jd2007 Posted July 10, 2007 Share Posted July 10, 2007 let's say a table named 'cars' has two columms, one is 'id', second is 'make' in mysql. i want to take all content in 'make' and store in a numerical array called 'mycars'. the content of 'make' is ferrari, aston martin, buick and jaguar. if i echo mycars[0], it will display ferrari...how do i do that ? Quote Link to comment Share on other sites More sharing options...
suma237 Posted July 10, 2007 Share Posted July 10, 2007 post your code.or use while loop Quote Link to comment Share on other sites More sharing options...
chronister Posted July 10, 2007 Share Posted July 10, 2007 I have a stupid question for you. Are you familiar with running queries and retrieving data from a DB? This is a pretty simple task <?php $query="SELECT * FROM cars"; $result=mysql_query($query); while($row=mysql_fetch_object($result)) { $mycars[]=$row->make; } echo $mycars[0]; ?> So long as Ferrari is the first item pulled from the database, this code will do exactly that. You could use a while loop to display the results, or a for loop or a foreach loop. I suggest you get pretty familiar with using loops and getting data in and out of an array. Hope this helps. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 10, 2007 Share Posted July 10, 2007 Yes MySQL pulls data out of the data in order they are stored in the table, eg if ferrari was entered first and jaguar was entered second the mysql will pull Ferrari first followed by jaguar. You can change the order by using the ORDER BY clause within the query if you wish. 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.