silveradogirl45 Posted August 20, 2009 Share Posted August 20, 2009 I have a database table with a lot of rows and columns. I'm trying to pull one column out of the database. Put the files into an array. And pull each value out. My current code is outputting this: $cars[0]="FordChevyToyota"; $cars[1]=""; $cars[2]=""; I want my code to ouput this instead: $cars[0]="Ford"; $cars[1]="Chevy"; $cars[2]="Toyota"; I know it's probably simple, but for some reason I can't get it to output correctly from the database. $result = mysql_query("SELECT column1 from Table); while ($row = mysql_fetch_array($result)) { $files = $row[column1]; $cars = array($files); echo $array[0]; } When I echo $array[0] it prints "FordChevyToyota". When I echo $row[column1] it prints "FordChevyToyota". When I echo $files[0] it prints "FFF"; Thanks in advance for any help! Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted August 20, 2009 Share Posted August 20, 2009 Try this $result = mysql_query("SELECT column1 from Table); while ($row = mysql_fetch_array($result)) { $cars[]=$row['column1']; } print_r($cars); Quote Link to comment Share on other sites More sharing options...
silveradogirl45 Posted August 20, 2009 Author Share Posted August 20, 2009 That only prints out the last word "Toyota". Quote Link to comment Share on other sites More sharing options...
silveradogirl45 Posted August 20, 2009 Author Share Posted August 20, 2009 I still have the problem, but I noticed I made a typo in my initial post. the echo isn't suppose to be $array[0]; it's suppose to be $cars[0] that outputs "FordChevyToyota". Just wanted to clarify that confusion to anyone trying to help. Sorry! 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.