Page 1 of 1
Simple Query Question
Posted: Tue Oct 13, 2009 10:52 am
by daebat
Code: Select all
$data = mysql_query("SELECT `id` FROM `productimages` INNER JOIN `pimagecategories` ON `productimages`.`category` = `categories`.`id` WHERE `categories`.`id` = 1;") or die(mysql_error());
returns
Column 'id' in field list is ambiguous
I know that this means that I'm using ID twice but what do I do to make it work?
Re: Simple Query Question
Posted: Tue Oct 13, 2009 11:36 am
by Mark Baker
Code: Select all
$data = mysql_query("SELECT `productimages`.`id` FROM `productimages` INNER JOIN `pimagecategories` ON `productimages`.`category` = `categories`.`id` WHERE `categories`.`id` = 1;") or die(mysql_error());
And you only need the `backticks` when the table or column name is a mysql reserved word
Re: Simple Query Question
Posted: Tue Oct 13, 2009 11:39 am
by jackpf
Prefix it with the table name
Doh, didn't see your post mark

Yeah. I think it's good practice to use backticks on all table/field names anyway...but it's just preference i guess.
Re: Simple Query Question
Posted: Tue Oct 13, 2009 11:49 am
by daebat
THANKS!@

Re: Simple Query Question
Posted: Tue Oct 13, 2009 11:53 am
by jackpf
Don't you mean
[sql]SELECT `productimages`.`id`FROM `productimages`, `categories`INNER JOIN `pimagecategories` ON `productimages`.`category` = `categories`.`id`WHERE `categories`.`id` = 1;[/sql]?
Although I obviously can't be sure,since you haven't posted your database structure...

Re: Simple Query Question
Posted: Tue Oct 13, 2009 12:01 pm
by daebat
Ok, now I am not echoing any of the data:
Code: Select all
<?php
$data = mysql_query("SELECT `productimages`.`id` FROM `productimages` INNER JOIN `pimagecategories` ON `productimages`.`category` = `pimagecategories`.`id` WHERE `pimagecategories`.`id` = 1;") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
Echo "<br /><br /><br /><br /><br /><br />";
//Outputs the image and other data
Echo "AKAISHI<hr><br />";
Echo "<table width='200' class='pimages' >";
Echo "<tr><td>".$info['thumb'] . "</b></td></tr>";
Echo "<tr><td><b> ".$info['title'] . "</b></td></tr> ";
Echo "<tr><td><a href=".$info['upjpg'] . "> HI RES JPG</a><br></td></tr>";
Echo "<tr><td><a href=".$info['uptiff'] . ">HI RES TIFF</a><br></td></tr>";
Echo '<tr><td><a href='.$info['uppng'] . '> HI RES PNG</a><br></td></tr>';
Echo "</table>";
}
?>
The code I am using was set up for
Code: Select all
$data = mysql_query("SELECT * FROM productimages") or die(mysql_error());
Re: Simple Query Question
Posted: Tue Oct 13, 2009 12:04 pm
by jackpf
That's not what I posted
Also, you're going to need to either use a wildcard, or specify those extra fields you want to display.
Re: Simple Query Question
Posted: Tue Oct 13, 2009 12:16 pm
by daebat
I think I have it figured out.