I have a page that does load images from mysql db - but they don't go to the anchor. The first page is listings that just has text, and the second shows image(s) for those. After refresh the category page will go to the anchored link, but I've been told that I need to have the image width and height in order for the page to know what it has to jump to. Getimagesize was suggested as a possible fix. I've been reading on this for the past three hours and just don't know how to get it into what I need.
Here's a snippet from the listings page that has the text link
echo "<a href='category.php?cid=".$row['category_id']."#advertiser_".$row['advertiser_id']."'>";
And here's the category page
<?php
//make sure there is a valid category id passed
$found = false;
$category = array();
$catSql = "select * from category where category_id = '".$_GET['cid']."'";
$result = mysql_query($catSql);
if(mysql_num_rows($result) > 0){
$found = true;
$category = mysql_fetch_array($result);
}
if($found){
$sql = "select * from advertisers a left join category c using(category_id) WHERE ";
$sql .= " c.category_id = '".$_GET['cid'] . "' and a.visible = 1 order by a.advertiser_name asc ";
$result = @mysql_query($sql);
//PRINT OUT THE CATEGORY TITLE
echo "<h1>".stripslashes($category['category_name'])."</h1>";
//LOOP THROUGH THE RESULT SET AND PRINT OUT THE IMAGES
while($row = mysql_fetch_array($result)){
//PUT EACH ADVERTISER IN A SEPARATE DIV THAT CAN BE USED FOR STYLING
echo "<div>";
//PRINT OUT THE ANCHOR FOR THE RECORD
echo "<a name='product_".$row['product_id']."' />\n";
//PRINT OUT THE FIRST IMAGE IF IT EXISTS
if(trim($row['img1']) != "" && file_exists($row['img1']))
echo '<img src="' . $row['img1'] . '" alt="' . stripslashes($row['advertiser_name']) . '" id="advertiser_' . $row['advertiser_id'] . '" />';
echo "<br>";
echo "<a href='listings.php'>Back to Listings</a>";
echo "<br>";
//A SECOND IMAGE EXISTS. SPIT OUT A BREAK AND DISPLAY THE IMAGE
if(trim($row['img2']) != "" && file_exists($row['img2'])){
echo "<br>";
echo '<img src="' . $row['img2'] . '" alt="' . stripslashes($row['advertiser_name']) . '" id="advertiser_' . $row['advertiser_id'] . '" />';
echo "<br>";
}
echo "</div>";
}
}
else{
//put an error message here
?>
you screwed up - please try again
<?
}
?>
Can someone please help show me where to insert getimagesize into the above code and a brief explanation on using?
thanks