gladiator83x Posted July 26, 2006 Share Posted July 26, 2006 Hi All,I created a new table called Defects, which has 4 columns. I am trying to save the entire column as an array...is that possible. This is what I have tried.------------------------------------------------------$array= "SELECT Review_Defects.Defects FROM Review_Defects";$array_result= mysql_query($array) or die('Query failed: ' .mysql_error());while ($line = mysql_fetch_array($array_result, MYSQL_ASSOC)) { foreach ($line as $col_value){// echo $col_value;}echo $col_value; //--echoes everything in column}//echo $col_value; --just echoes the last thing in column---------------------------------------------------------If I echo within the loop, I receive everything inside the column--which is what I want within my array. Is there some sort of function that I will have to use? Quote Link to comment https://forums.phpfreaks.com/topic/15741-arrays-in-php-and-mysql/ Share on other sites More sharing options...
effigy Posted July 26, 2006 Share Posted July 26, 2006 Do you mean the entire row as an array? If you want an associative array, you should be able to use $line as is. Quote Link to comment https://forums.phpfreaks.com/topic/15741-arrays-in-php-and-mysql/#findComment-64328 Share on other sites More sharing options...
gladiator83x Posted July 26, 2006 Author Share Posted July 26, 2006 How will I do that? I know that when I try to echo out $line, it just outputs 'Array' numerous times Quote Link to comment https://forums.phpfreaks.com/topic/15741-arrays-in-php-and-mysql/#findComment-64332 Share on other sites More sharing options...
effigy Posted July 26, 2006 Share Posted July 26, 2006 From my understanding, you want the row to be an array and it already is. The array is associative, using column names as keys. For example, if your query was [tt]select id, name from usr[/tt], your array is going to look something like...[tt]id => 1,name => bob[/tt]...which you access by $line['id'] and $line['name']. Quote Link to comment https://forums.phpfreaks.com/topic/15741-arrays-in-php-and-mysql/#findComment-64335 Share on other sites More sharing options...
Barand Posted July 26, 2006 Share Posted July 26, 2006 Try[code]<?php $defects = array();$array= "SELECT Review_Defects.Defects FROM Review_Defects";$array_result= mysql_query($array) or die('Query failed: ' .mysql_error());while ($line = mysql_fetch_array($array_result, MYSQL_ASSOC)) { $defects[] = $line['Defects']; // store value in array}// view the arrayeecho '<pre>', print_r($defects, true), '</pre>';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15741-arrays-in-php-and-mysql/#findComment-64338 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.