Jump to content

[SOLVED] array problem


el-sid

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.