As good as everyone thinks I am at PHP, I'm not that good as SQL.
Could someone please help me turn the group of SQL queries grouped with PHP into a single query?
Here is the code:
function check_read_forum($fid) {
global $db, $forum_user;
if ($forum_user['is_guest']) {
return false;
}
$result = $db->query('SELECT id FROM ' . $db->prefix . 'topics
WHERE forum_id=' . $fid) or error_msg('Could not check for unread messages - part 1');
while ($topic = $db->fetch_assoc($result)) {
$r2 = $db->query('SELECT 1 FROM ' . $db->prefix . 'read
WHERE topic_id=' . $topic['id'] . ' AND user_id=' . $forum_user['id']) or error_msg('Could not check unread messages - part 2');
if (!$db->num_rows($r2)) {
return true;
}
}
}Offline
jvvg wrote:
Bump
![]()
I need help!
What's wrong with the current one?
it seems like it would work fine
But couldn't you just do
SELECT * FROM ' . $db->prefix . 'topics WHERE forum_id = '.$fid
Then just pick and choose which parts you want to use?
Offline
jvvg wrote:
rookwood101 wrote:
So your trying to use OOP and PDO?
The OOP is database abstraction. What's PDO?
@SJRCS_011: That won't work.
ok, it was just expermiental
Offline
You want multiple querys in a single call, right?
If you are using the mysql functions, then it wont work. Mysqli functions, however, do have a method that allows you to do multiple querys at the same time. I never use mysqli because mysql functions do the job just fine for me. I only do single querys
Offline
Let me put it this way:
I am writing a program to check for unread messages in a forum.
What I do is I have a table that shows read topics (user ID and topic ID).
I need code to check if the forum has any unread messages.
Offline