vampke Posted January 8, 2008 Share Posted January 8, 2008 Hi peoples, I 'm writing a script where i want to get all the numbers out of a database and put them in an html this is the database table: unid id un1 un2 un3 un4 un5 un6 un7 1 1 2 3 8 19 48 52 63 2 1 2 3 8 20 21 43 58 3 2 1 7 11 23 26 33 44 4 2 3 12 17 42 49 71 96 5 3 21 28 38 39 47 54 59 6 3 1 4 9 19 35 42 95 my php code: $msg =""; $get_numbers = mysql_query("SELECT * FROM numbers"); while($row = mysql_fetch_row($get_numbers)) { $userid = $row[0]; $id = $row[1]; $number1 = $row[2]; $number2 = $row[3]; $number3 = $row[4]; $number4 = $row[5]; $number5 = $row[6]; $number6 = $row[7]; $number7 = $row[8]; $msg .= "$number1, $number2, $number3, $number4, $number5, $number6, $number7 \n"; } This returns 189 lines of results. Here are the first few: 2, 3, 8, 19, 48, 52, 63 userID: 1 2, 3, 8, 19, 48, 52, 63 2, 3, 8, 20, 21, 43, 58 userID: 2 2, 3, 8, 19, 48, 52, 63 userID: 1 2, 3, 8, 19, 48, 52, 63 2, 3, 8, 20, 21, 43, 58 1, 7, 11, 23, 26, 33, 44 etc... Can someone explain to me what i'm so obviously doing wrong? I only want to return the 6 rows in the mysql table Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/ Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 Use mysql_fetch_array() Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433560 Share on other sites More sharing options...
vampke Posted January 8, 2008 Author Share Posted January 8, 2008 Use mysql_fetch_array() same result Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433561 Share on other sites More sharing options...
adam291086 Posted January 8, 2008 Share Posted January 8, 2008 feth_array should work. Post your code Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433564 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 <?php $msg =""; $get_numbers = mysql_query("SELECT * FROM numbers") or die(mysql_error()); while($row = mysql_fetch_array($get_numbers)) { $userid = $row[0]; $id = $row[1]; $number1 = $row[2]; $number2 = $row[3]; $number3 = $row[4]; $number4 = $row[5]; $number5 = $row[6]; $number6 = $row[7]; $number7 = $row[8]; $msg .= "$number1, $number2, $number3, $number4, $number5, $number6, $number7 \n"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433567 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 Where is your echo statement. Why does $msg .= ? Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433570 Share on other sites More sharing options...
adam291086 Posted January 8, 2008 Share Posted January 8, 2008 beaten to it Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433571 Share on other sites More sharing options...
vampke Posted January 8, 2008 Author Share Posted January 8, 2008 Thanks ken2k7, that worked, I'm not sure what is different then in my code though... weird.... the $msg is returned in the html code, I thought it was clear so i did not mention it Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433572 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 Ah I see, you're loading up the variable first then displaying it. I usually echo it on each loop iteration. Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433575 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 mysql_fetch_row() fetches one row of data while mysql_fetch_array() can fetch more than 1. Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433577 Share on other sites More sharing options...
trq Posted January 8, 2008 Share Posted January 8, 2008 mysql_fetch_row() fetches one row of data while mysql_fetch_array() can fetch more than 1. Since when? mysql_fetch_array fetches one row each time it is called then moves the internal pointer forward. Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433582 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 mysql_fetch_row() fetches one row of data while mysql_fetch_array() can fetch more than 1. Since when? mysql_fetch_array fetches one row each time it is called then moves the internal pointer forward. Oh okay. Thanks. Why do people say 'internal pointer'? ??? Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433584 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 That's how it keeps track of where it's at or else it won't know what the next row is. Quote Link to comment https://forums.phpfreaks.com/topic/85019-solved-getting-results-from-mysql/#findComment-433586 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.