el-sid Posted September 1, 2008 Share Posted September 1, 2008 hi everyone. iv been trying to get this mysql output to work on php (minus the table attributes of course) mysql> SELECT * FROM winery; +-----------+---------------------------------+-----------+ | winery_id | winery_name | region_id | +-----------+---------------------------------+-----------+ | 1 | Hanshaw Estates Winery | 2 | | 2 | De Morton and Sons Wines | 5 | | 3 | Jones's Premium Wines | 3 | | 4 | Borg Daze Premium Wines | 5 | | 5 | Binns Group | 6 | | 6 | Davie Brook Vineyard | 3 | i tried this but i keep getting errors <?php include "db.inc"; if (!($connection = @ mysql_connect($hostName, $username, $password))) die("Could not connect to database"); if (!mysql_select_db($databaseName, $connection)) showerror(); $Query = "SELECT * FROM winery"; if (!($result = @ mysql_query ($Query,$connection))) showerror(); while ($row = mysql_fetch_row($result)){ echo $row; } ?> the output i get is a string of arrays but i want it to be justlike the mysql output Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/ Share on other sites More sharing options...
JasonLewis Posted September 1, 2008 Share Posted September 1, 2008 To get a better understanding, instead of this: echo $row; Put this: print_r($row); That should give you a bit more idea on what you want to accomplish. Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630817 Share on other sites More sharing options...
burn1337 Posted September 1, 2008 Share Posted September 1, 2008 How I would work around it $text = 'select * from Winery'; $query = mysql_query($text); $row = mysql_fetch_array($query); echo $row[0]; echo $row[1]; echo $row[2]; Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630818 Share on other sites More sharing options...
valtido Posted September 1, 2008 Share Posted September 1, 2008 How I would work around it $text = 'select * from Winery'; $query = mysql_query($text); while($row = mysql_fetch_array($query)){ echo $row['winery_name']; } i think thats what you are trying to do Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630834 Share on other sites More sharing options...
el-sid Posted September 1, 2008 Author Share Posted September 1, 2008 How I would work around it $text = 'select * from Winery'; $query = mysql_query($text); while($row = mysql_fetch_array($query)){ echo $row['winery_name']; } i think thats what you are trying to do thats right, its what am trying..but am getting this error PHP Notice: Undefined index: winery_name in /var/www/html/winestore/test.php on line 20 its occuring many times...meaning the loop is actually working. but how do i get rid of the error Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630855 Share on other sites More sharing options...
JasonLewis Posted September 1, 2008 Share Posted September 1, 2008 Make sure that it is a column in the MySQL database. If you are stuck, use what I posted above in the while loop to see what elements there are in the array. Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630864 Share on other sites More sharing options...
burn1337 Posted September 1, 2008 Share Posted September 1, 2008 it is a column you need to use mysql_fetch_assoc() to use the column names. mysql_fetch_arrar() produces an array with only number reference, assoc will do both named, and string. Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630867 Share on other sites More sharing options...
valtido Posted September 1, 2008 Share Posted September 1, 2008 thats only a minor error dont worry much about it check if u have <?php error_reporting(E_ALL & ~E_NOTICE); ?> Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630868 Share on other sites More sharing options...
JasonLewis Posted September 1, 2008 Share Posted September 1, 2008 it is a column you need to use mysql_fetch_assoc() to use the column names. mysql_fetch_arrar() produces an array with only number reference, assoc will do both named, and string. You must be tired burn. mysql_fetch_array() returns both an Associative Array and an Numerical Array. mysql_fetch_row() returns only the Numerical Array and mysql_fetch_assoc() returns only an Associative Array. Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630872 Share on other sites More sharing options...
burn1337 Posted September 1, 2008 Share Posted September 1, 2008 my bad I am tired... I told you.. ok no more delay I'm off to la la and never never land Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630876 Share on other sites More sharing options...
el-sid Posted September 1, 2008 Author Share Posted September 1, 2008 my bad I am tired... I told you.. ok no more delay I'm off to la la and never never land geez! i dont know if you are all tired . but thanks for the help. i was able to get the desired output using mysql_fetch_array() or mysql_fetch_assoc() thanks for the help Link to comment https://forums.phpfreaks.com/topic/122193-solved-array-problem/#findComment-630887 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.