PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
daebat
Forum Commoner
Posts: 47 Joined: Mon May 11, 2009 10:16 am
Post
by daebat » Tue Oct 13, 2009 10:52 am
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?
Mark Baker
Forum Regular
Posts: 710 Joined: Thu Oct 30, 2008 6:24 pm
Post
by Mark Baker » Tue Oct 13, 2009 11:36 am
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
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Tue Oct 13, 2009 11:39 am
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.
daebat
Forum Commoner
Posts: 47 Joined: Mon May 11, 2009 10:16 am
Post
by daebat » Tue Oct 13, 2009 11:49 am
THANKS!@
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Tue Oct 13, 2009 11:53 am
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...
daebat
Forum Commoner
Posts: 47 Joined: Mon May 11, 2009 10:16 am
Post
by daebat » Tue Oct 13, 2009 12:01 pm
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());
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Tue Oct 13, 2009 12:04 pm
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.
daebat
Forum Commoner
Posts: 47 Joined: Mon May 11, 2009 10:16 am
Post
by daebat » Tue Oct 13, 2009 12:16 pm
I think I have it figured out.