sd9sd Posted July 2, 2008 Share Posted July 2, 2008 I have a table like this: --------------------------------------- order | rating | name --------------------------------------- 0 | 54 | tom 2 | 34 | dick 8 | 45 | harry --------------------------------------- I need to get the contents of the 'order' column into an array like so: echo $orderNumbers[0]; //prints 0 echo $orderNumbers[1]; //prints 2 echo $orderNumbers[2]; //prints 8 This is the php code I'm using unsuccessfully: $query = mysql_query("SELECT * FROM `data`"); while($row = mysql_fetch_array($query)){$result=$row['order'];} $result=explode(",",$result); echo "length of array=".count($result)."<br>"; for($i=0;$i<count($result);$i++) {echo "$result[$i] <br>";} Could anyone show me the right way to get the data please? Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2008 Share Posted July 2, 2008 Are you want to count rows for order column. if yes you can use mysql_num_rows. Quote Link to comment Share on other sites More sharing options...
themistral Posted July 2, 2008 Share Posted July 2, 2008 Try this while($row = mysql_fetch_array($query)){ echo $row['order']; } It will return the order column Quote Link to comment Share on other sites More sharing options...
whiteboikyle Posted July 2, 2008 Share Posted July 2, 2008 hmm why not just do a for($i = 0; mysql_num_rows($result); $i = $i + 1;){ $order = mysql_result($result, $i, "order"); } its not an array but it can get you the number of each row.. like row 1 row 2.. etc Quote Link to comment Share on other sites More sharing options...
sd9sd Posted July 2, 2008 Author Share Posted July 2, 2008 Thanks themistral and marif4u! It worked....my mistake with the array. Thanks again Thanks whiteboikyle...that's one solution that'll be useful for me too. P.S: a friendly hint from me - you can try using $i++ in the for loop, instead of the $i=$i+1; 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.