Jump to content

Query fetches multiple rows in phpmyadmin. Only fetches one row in php code!


Recommended Posts

This query executes fine in phpmyadmin, but only gets one row when php executes the query. I am unsure of what to do to fix this. Please would you give me suggestions as to what the error maybe, and how to go about fixing it.

$sql = "SELECT the_forum_league_games.id, the_forum_league_pairings.weekno, users1.username AS user1name, users1.user_id AS user1id, users2.username AS user2name, users2.user_id AS user2id, the_forum_league_games.result
FROM the_forum_league_games
LEFT JOIN the_forum_users
AS users1
ON users1.user_id=the_forum_league_games.player1
LEFT JOIN the_forum_users
AS users2
ON users2.user_id=the_forum_league_games.player2
LEFT JOIN the_forum_league_pairings
ON the_forum_league_pairings.id=the_forum_league_games.pairing_id
WHERE the_forum_league_pairings.seasonid='$season_number'
ORDER BY the_forum_league_pairings.weekno, the_forum_league_games.player1";

$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
echo print_r($row, false); // outputs one row, whereas in phpmyadmin 12 rows!!
$weekno_arr[] = $row['weekno'];
$player1_arr[] = $row['user1id'];
$player1_arr[] = $row['user2id'];
$username1_arr[] = $row['user1name'];
$username2_arr[] = $row['user2name'];
$gameid_arr[] = $row['id'];
}

I made another simple query, to the and it again failed to collect the data. I think there must be something wrong with the phpbb query execution itself, else something wrong with the database. There are no php errors thrown up!!

It's likely that your ->sql_fetchrow() method is at fault. What's the code for it?

It is the inbuilt phpbb function. I will overwrite the phpbb with new files I guess, to see if that eliminates that avenue.

A) You didn't mention in your first post that this had anything to do with a pre-build application like phpbb.

 

B) You need to trouble-shoot why you are getting the result you are, before you can fix it, otherwise you will just waste a bunch of time.

 

C) Is that all your actual code inside of the while(){} loop? A next likely cause of the symptom you have indicated is you are overwriting the $result variable inside of the loop. It's also possible that something in the data you are outputting via the print_r is hiding the actual output inside of a html tag. What does the 'view source' in your browser show?

 

D) I didn't see a num_rows() method mentioned in the phpbb database class. It would have been nice if they had provided a method of finding out how many rows a select query matched.

Edited by PFMaBiSmAd

A) You didn't mention in your first post that this had anything to do with a pre-build application like phpbb.

 

B) You need to trouble-shoot why you are getting the result you are, before you can fix it, otherwise you will just waste a bunch of time.

 

C) Is that all your actual code inside of the while(){} loop? A next likely cause of the symptom you have indicated is you are overwriting the $result variable inside of the loop. It's also possible that something in the data you are outputting via the print_r is hiding the actual output inside of a html tag. What does the 'view source' in your browser show?

 

D) I didn't see a num_rows() method mentioned in the phpbb database class. It would have been nice if they had provided a method of finding out how many rows a select query matched.

You were right on:

overwriting the $result variable inside of the loop

Thank you for taking the time to post. You have helped me out a lot.

Zugz

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.