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
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
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
Share on other sites

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 ;D. 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.