Axon Posted January 24, 2005 Share Posted January 24, 2005 Hey Guys, I really need some help quickly if possible, I need to know how to take information from a database and put it into a PHP array. Thanks! -Ax Link to comment https://www.neowin.net/forum/topic/275486-phpmysql-mysql-to-array/ Share on other sites More sharing options...
0 bizpile Posted January 24, 2005 Share Posted January 24, 2005 $connection = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); $db = mysql_select_db($db_name, $connection) or die(mysql_error()); $sql= "SELECT * FROM $table"; $sql_results = mysql_query($sql, $connection) or die("Couldn't execute query"); while($row=mysql_fetch_array($sql_results, MYSQL_ASSOC)) $arr[]=$row; Link to comment https://www.neowin.net/forum/topic/275486-phpmysql-mysql-to-array/#findComment-585345381 Share on other sites More sharing options...
0 Axon Posted January 24, 2005 Author Share Posted January 24, 2005 Thanks for the fast reply, I should have been more clear as to what I was looking to accomplish, here is a picture of my database, and a highlited column, I want to select only the date and one column at a time! Thanks for the fast reply! -Ax Link to comment https://www.neowin.net/forum/topic/275486-phpmysql-mysql-to-array/#findComment-585345489 Share on other sites More sharing options...
0 epton Posted January 24, 2005 Share Posted January 24, 2005 But if you're only selecting one date and one column at a time then why do you need an array? $sql= "SELECT t_air FROM $table WHERE date = 'whatever'"; Link to comment https://www.neowin.net/forum/topic/275486-phpmysql-mysql-to-array/#findComment-585345660 Share on other sites More sharing options...
0 Axon Posted January 24, 2005 Author Share Posted January 24, 2005 I want to put the date and the corrosponing information into an array. :) array { "2005-03-01" "4.91" "2005-02-12" "2.01" "2005-10-15" "5.10" } ect Thanks for replying! -Ax Link to comment https://www.neowin.net/forum/topic/275486-phpmysql-mysql-to-array/#findComment-585345688 Share on other sites More sharing options...
0 GatorV Posted January 24, 2005 Share Posted January 24, 2005 Well you can acomplish it like this: <?php // Connect and stuff $query = "SELECT date, t_air FROM kcwks_raw"; $result = mysql_query( $query ); $data = array(); while( $row = mysql_fetch_array( $result ) ) $data[] = array( $row[0], $row[1] ); // Disconnect ?> then on data you will have a array were each item is an array with the data you need.. Link to comment https://www.neowin.net/forum/topic/275486-phpmysql-mysql-to-array/#findComment-585345830 Share on other sites More sharing options...
Question
Axon
Hey Guys,
I really need some help quickly if possible, I need to know how to take information from a database and put it into a PHP array.
Thanks!
-Ax
Link to comment
https://www.neowin.net/forum/topic/275486-phpmysql-mysql-to-array/Share on other sites
5 answers to this question
Recommended Posts