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 Quote Link to comment 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. Quote Link to comment 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]; Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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); ?> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 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.