NYCPHP Meetup

NYPHP.org

proper code

Matthew Zimmerman mz34 at nyu.edu
Wed Sep 11 13:57:17 EDT 2002


> Apologies again. Here is some proper code. Again, I am not sure if it 
> is needed to answer my question, but this is a better example.

I have two tables named "images" and "format"

Images has three fields: id, name, and format

Format has two fields: id, name

The "format" field in the "images"  table is linked to the "id" field 
in the "format" database

> 2. I have a query that says
>
> $query= "SELECT images.id, format.id, format.name
> FROM images, format
> WHERE images.id=$id
AND images.format = format.id"

>
>
> 3. Then I assign the results to an array using
>
> $result= mysql_query($query);
>
> while ($row=mysql_fetch_array($result)
>
> 	{
> 		extract($row);
>
> 	}
>
> 4. Then I want to print the results which I would think would go like
> this:
>
> echo "$images.id, $format.id, $format.name";
>
> But it seems these are not the keys in the array, but instead there is
> just one $id key and the value of that is whatever "id" came last in
> the query. In other words, if the query read "Select format.id,
> images.id" then there would be a value in the array for $id equal to
> "images.id" and if query read "Select images.id, format.id" then there
> would be a value in the array for the key $id equal to "format_id".
>
> I expected there would be two keys in the array: images.id and 
> format.id
>
> Am I wrong to expect that?
>
> Thanks for any help. I am new to PHP and databases and this code I am
> using I got from a book, so maybe it is the wrong technique.
>
>
> Matt Zimmerman
> NYU
>
>
>
> --- Unsubscribe at http://nyphp.org/list ---
>
>




More information about the talk mailing list