Zugzwangle Posted January 30, 2013 Share Posted January 30, 2013 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']; } Link to comment https://forums.phpfreaks.com/topic/273822-query-fetches-multiple-rows-in-phpmyadmin-only-fetches-one-row-in-php-code/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 30, 2013 Share Posted January 30, 2013 It's likely that your ->sql_fetchrow() method is at fault. What's the code for it? Link to comment https://forums.phpfreaks.com/topic/273822-query-fetches-multiple-rows-in-phpmyadmin-only-fetches-one-row-in-php-code/#findComment-1409120 Share on other sites More sharing options...
Zugzwangle Posted January 30, 2013 Author Share Posted January 30, 2013 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!! Link to comment https://forums.phpfreaks.com/topic/273822-query-fetches-multiple-rows-in-phpmyadmin-only-fetches-one-row-in-php-code/#findComment-1409122 Share on other sites More sharing options...
Zugzwangle Posted January 30, 2013 Author Share Posted January 30, 2013 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. Link to comment https://forums.phpfreaks.com/topic/273822-query-fetches-multiple-rows-in-phpmyadmin-only-fetches-one-row-in-php-code/#findComment-1409123 Share on other sites More sharing options...
Zugzwangle Posted January 30, 2013 Author Share Posted January 30, 2013 I have overwritten the whole forum with a fresh install.. Still no joy. Database problem do you think? Link to comment https://forums.phpfreaks.com/topic/273822-query-fetches-multiple-rows-in-phpmyadmin-only-fetches-one-row-in-php-code/#findComment-1409124 Share on other sites More sharing options...
PFMaBiSmAd Posted January 30, 2013 Share Posted January 30, 2013 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. Link to comment https://forums.phpfreaks.com/topic/273822-query-fetches-multiple-rows-in-phpmyadmin-only-fetches-one-row-in-php-code/#findComment-1409125 Share on other sites More sharing options...
Zugzwangle Posted January 30, 2013 Author Share Posted January 30, 2013 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 Link to comment https://forums.phpfreaks.com/topic/273822-query-fetches-multiple-rows-in-phpmyadmin-only-fetches-one-row-in-php-code/#findComment-1409156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.