Gruzin Posted January 24, 2007 Share Posted January 24, 2007 Hi guys,Just want to know what's the difference between [b]mysql_fetch_array[/b] and [b]mysql_fetch_assoc[/b]?Thanks,George Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted January 24, 2007 Share Posted January 24, 2007 Have you read the manual, as this makes it pretty clear![b]mysql_fetch_array()[/b][quote]Fetch a result row as an associative array, a numeric array, or both[/quote][b]mysql_fetch_assoc()[/b][quote]Fetch a result row as an associative array[/quote]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
Gruzin Posted January 24, 2007 Author Share Posted January 24, 2007 Thanks Huggie,I will read the manual again...Actaually I have a simple mysql query, like this:[code]$sql = mysql_query("SELECT * FROM aid_poll_results WHERE id='17'");while($row = mysql_fetch_assoc($sql)){$opt1 = $row['1'];$opt2 = $row['2'];$opt3 = $row['3'];$opt4 = $row['4'];$opt5 = $row['5'];$opt6 = $row['6'];$opt7 = $row['7'];$opt8 = $row['8'];$opt9 = $row['9'];}[/code]above query fetches rows correctly, but this:[code]$sql = mysql_query("SELECT * FROM aid_poll_results WHERE id='17'");while($row = mysql_fetch_array($sql)){$opt1 = $row['1'];$opt2 = $row['2'];$opt3 = $row['3'];$opt4 = $row['4'];$opt5 = $row['5'];$opt6 = $row['6'];$opt7 = $row['7'];$opt8 = $row['8'];$opt9 = $row['9'];}[/code]this example fetches rows, omitting 1 row, I mean it does fetch the rows except firts one, and instead of it fetches id row... hope u understand me :)Thanks,George Quote Link to comment Share on other sites More sharing options...
matto Posted January 24, 2007 Share Posted January 24, 2007 remember arrays always begin with zero[code]$opt1 = $row['0'];$opt2 = $row['1'];....and so on[/code] Quote Link to comment Share on other sites More sharing options...
Gruzin Posted January 24, 2007 Author Share Posted January 24, 2007 Thanks man ;) it works with mysql_fetch_array as well! Quote Link to comment Share on other sites More sharing options...
matto Posted January 24, 2007 Share Posted January 24, 2007 Glad to have helped. Remember to set this thread to resloved... ;) Quote Link to comment 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.