Seancon1 Posted September 30, 2012 Share Posted September 30, 2012 I am unable to echo content in my mysql_fetch_array.. $query_sum = mysql_query("SELECT ip, cases, motherboards, cpu, video_cards, ram, power_supply, sound_cards, storage, media_player, cpu_cooling, monitor, accessories FROM sessions WHERE ip = '$ip'") or die(mysql_error()); while($get = mysql_fetch_array( $query_sum )) { $item1 = $get['cases']; $item2 = $get['motherboards']; $item3 = $get['cpu']; $item4 = $get['video_cards']; $item5 = $get['ram']; $item6 = $get['power_supply']; $item7 = $get['sound_cards']; $item8 = $get['storage']; $item9 = $get['media_player']; $item10 = $get['cpu_cooling']; $item11 = $get['monitor']; $item12 = $get['accessories']; $items = array("1" => "$item1", "2" => "$item2", "3" => "$item3", "4" => "$item4", "5" => "$item5", "6" => "$item6", "7" => "$item7", "8" => "$item8", "9" => "$item9", "10" => "$item10", "11" => "$item11", "12" => "$item12"); echo "Displaying: " . $item3; } echo "Displaying: " . $item3; Does not return anything, not even the "Displaying" text is displayed. I remember being able to echo like this in the past, why not now? Link to comment https://forums.phpfreaks.com/topic/268921-cannot-echo-in-my-mysql_fetch_array/ Share on other sites More sharing options...
Jessica Posted September 30, 2012 Share Posted September 30, 2012 There were probably 0 rows returned. Echo the query then run it in mysql/phpMyAdmin to check. You can also check mysql_num_rows. (You should be using mysqli, btw). Link to comment https://forums.phpfreaks.com/topic/268921-cannot-echo-in-my-mysql_fetch_array/#findComment-1381812 Share on other sites More sharing options...
Seancon1 Posted September 30, 2012 Author Share Posted September 30, 2012 It was returning 0 rows simply because (silly me) the row with the ip wasn't my current. So it was searching for an ip that was not there. ;x Link to comment https://forums.phpfreaks.com/topic/268921-cannot-echo-in-my-mysql_fetch_array/#findComment-1381813 Share on other sites More sharing options...
trq Posted September 30, 2012 Share Posted September 30, 2012 Hence it's always best to check you have a successful query and that it returned some data before you go ahead and simply try and use it's results. Link to comment https://forums.phpfreaks.com/topic/268921-cannot-echo-in-my-mysql_fetch_array/#findComment-1381819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.