Page 1 of 1

a mysql join problem

Posted: Wed Aug 15, 2007 1:14 pm
by rich costello
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello

I am trying to write a script whereby I can pull an image out of one database table and display it in relation to its category_id in another table. I am using a my_sql join function that is joining the tables correctly, however it only shows the one same image from the top field of those combined rows on every single page. I need it display the image according to its category_id for that particular page. I am thinking I need to set variables to represent those specific rows but I'm not sure how to do that. 

Here is my code

Code: Select all

<?
{
$result = mysql_query("SELECT
placing_item_bid.category_id
, category_master.icon_1
FROM
school_auction.category_master
, school_auction.placing_item_bid
WHERE
placing_item_bid.category_id=category_master.category_id and
category_master.icon_1=category_master.icon_1");
$row = mysql_fetch_array( $result );
$img=$row['icon_1'];

list($width, $height, $type, $attr) = getimagesize("images/$img");
$h=$height;
$w=$width;

if($h>200)
{
$nh=200;
$nw=($w/$h)*$nh;
$h=$nh;
$w=$nw;
}
if($w>160)
{
$nw=160;
$nh=($h/$w)*$nw;
$h=$nh;
$w=$nw;
}
?>
<img name="runimg" src="images/<? echo $row['icon_1'];?>"
border=1 width=<?= $w; ?> height=<?=$h?> >
Here is an example of the page I am using it on. It should be pulling in an image of a ford icon but it's not

http://www.schoolauction.com/detail.php?item_id=739

Any help or advice would be great.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Aug 15, 2007 2:36 pm
by califdon
Rule #1 about asking database questions: Always show your table structures first. Nothing else about a database can be understood without first knowing the schema.

Posted: Wed Aug 15, 2007 3:24 pm
by miro_igov
There is no need of showing the table structure.

Try

$result = mysql_query("SELECT
placing_item_bid.category_id
, category_master.icon_1
FROM
school_auction.category_master
, school_auction.placing_item_bid
WHERE
placing_item_bid.category_id=category_master.category_id and
category_master.icon_1=category_master.icon_1 AND placing_item_bid.category_id = '$your_desirec_category_id' ");


You also can append LIMIT 0,1 to make it faster, because you use only the first row.

re

Posted: Wed Aug 15, 2007 3:36 pm
by rich costello
That worked. Thank You