Showing picture on search result as thumbnail next to ad

I hope the subject isn’t too confusing. I’ll try explaining better below.

I’m working on a site where people can upload ads/articles. They go to advertise.php, fill in all the forms, choose a picture to upload and submit… The ad gets stored in the database and I’ve later made a search site where people can search & select from the list of ads which ad they would like to browse. This is for search.php.
When you find what you’re looking for from the result, you just go ahead click the link to the ad and it opens up in showad.php
In the page where the ad is shown, all forms from which was previously filled out get echoed, with the belonging picture. If you would click the picture, it would open up in show.php, which is connected to the AId(articles ID).

Now. At the table on search.php I’ve chosen to show the result with a table, containing: Object, Category, Price, Date, City. I’ve later come up with the brilliant idea of adding the picture from the ads corresponding showad.php-id as a thumbnail and add it to the table.

I will share the codes for Search.php, Showad.php and Show.php, because I feel the answer is in either showad or show…

Search.php
[php]

<?php include("connect.php"); ?> Search:

Category:
All! <?php
                          $sql = "SELECT * FROM category";
                          $result = mysql_query($sql);
                          while($row = mysql_fetch_array($result)){ 
                              echo "<option value=\"" . $row["catID"] . "\">" . $row["catName"] . "</option>\n";
                          }
                          $sql="";
                          ?>
          </select></td>
          <th align="right">City:</th><br />
          <td><select name="city">
              <option value="">Whole country</option>
                          <?php
      
                          $sql = "SELECT * FROM city";
                          $result = mysql_query($sql); 
                          while($row = mysql_fetch_array($result)){ 
                              echo "<option value=\"" . $row["cityID"] . "\">" . $row["cityName"] . "</option>\n";
                          }
                          $sql="";
                          ?>
        </select></td>
        <td align="right"></td>
        <td>   <input type="submit" value="Submit" name="searchbutton" /></td>
    </form></tr></table>
    
    <table class="borderall">
    <tr>
    <th align="center" width="200" class="borderright">Object</th>
    <th align="center" width="100" class="borderright">Category</th>
    <th align="center" width="40" class="borderright">Price</th>
    <th align="center" width="100" class="borderright">Date</th>
    <th align="center" width="100">City</th>
    </tr>
    
    
    <?php
          
		$search =  !isset($_GET["search"]) ? '' : $_GET['search'];
       $cat = !isset($_GET["cat"]) ? '' : $_GET['cat']; 
       $city = !isset($_GET["city"]) ? '' : $_GET['city']; 
        
        $sql = "SELECT * FROM tblad, city, category WHERE tblad.catID=category.catID AND		    tblad.cityID = city.cityID";
                      
          if ($search!="")
           {
           $sql .= " AND Object LIKE '%{$search}%'  ";
           }
     
        if ($cat!="")
          {
           $sql .= " AND tblad.catID={$cat} ";
           }
     
        if ($city !="")
          {
           $sql .= " AND city.cityID={$city} ";
           }
     
      $sql .= " ORDER BY DateTime DESC"; 

echo “
”;

    $result = mysql_query($sql) or die(mysql_error()); 
    while($row = mysql_fetch_array($result)) {

echo “

”;
echo “ ” . $row[“Object”] . “” . “”;
echo “” . $row[“catID”] . “”;
echo “” . $row[“Price”] . “:-” . “”;
echo “” . $row[“DateTime”] . “”;
echo “” . $row[“cityName”] . “”;
echo “”;
}

//echo $sql;

?>[/php]

Showad.php
[php]<?php
include(“connect.php”);
error_reporting(E_ALL ^ E_NOTICE);
$aid = $_GET[“id”];
if (is_numeric($aid)){
//header (“location:search.php”);
}
$sql= “SELECT * FROM tblad, category, city, tblpic
where tblad.AId=tblpic.AId
AND tblad.catID=category.catID
AND tblad.cityID=city.cityID
and tblad.AId=$aid”;

/*

Old code for joining tables and columns. Leaving it here in case something was forgotten when the code above was written. In that case, we have the original code below.

$sql= "SELECT tblad.*, category.catName, tblpic.picFile FROM tblad INNER JOIN category ON tblad.catID=category.catID LEFT JOIN tblpic ON tblad.AId=tblpic.AId WHERE tblad.AId=$aid
";

*/

$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_array($result);

?>[/php]

Show.php
[php] <?php
$conn = mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“database”);

$imagedir = “pics/”;
$id = $_GET[‘id’];
if(!is_numeric($id)) {
die(“Cheater!!! stop!”);
}
$sql = mysql_query(“SELECT tblpic.* FROM tblpic WHERE PID=$id”);

if(!$sql) {
die(“Databasal error”);
}
else {
$result = mysql_fetch_array($sql);

	if(!$result) {
		die("Cannot find that particular file");
		exit();
	} else {

		$length = filesize($imagedir. $result['PicFile']);
		header('Content-Length: ' . $length);
		header("Content-Type: " . $result['PicType']);
		readfile($imagedir.$result['PicFile']);
		
	}
}

//echo $sql;
exit();
[/php]

Hey!

I’m in a little bit of a better mood today lol, it’s Friday!

Okay, so you gave us a really lovely description of what you’re doing but no actual problem?

Generally in a techy kind of environment, we’d need:

[ul][li]Description of the problem[/li]
[li]Steps taken to replicate the problem[/li]
[li]Expected outcome[/li]
[li]Actual outcome[/li][/ul]

That enables us to clearly understand the problem and view steps you’ve taken to reproduce the problem, what you want it to do and what it’s actually doing. This will will help us help you quicker.

All right, thanks alot for your insight. I’ll try being as thorough as possible according to these 4 points.

In showad I have the following table and code for echoing the respective columns
[php]

<?php $sql="SELECT * FROM tblpic WHERE tblpic.AId=$aid"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)){ $max=400; $id=$row["PID"]; $height=$row["height"]; $width=$row["width"]; if ($height > $width && $height > $max){ $ratio = $height/$max; $height = $max; $width = $width/$ratio; } else if($width > $max) { $ratio = $width/$max; $width = $max; $height = $height/$ratio; } echo ""; }
	 $referer = $_SERVER['http_referer'];

	
	?>
  </tr>
  [/php]

And since showad.php seems to be doing fine with showing the image of the article id, I thought I could just copy it into search.php.
So what I did was add [php]

[/php]
to the table in search.php and echo it along with the other rows. However this is where I get confused as the code looks like this
[php] echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;[/php]

I’m trying to add
[php]<?php
$sql=“SELECT * FROM tblpic WHERE tblpic.AId=$aid”;
$result=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result)){
$max=75;
$id=$row[“PID”];
$height=$row[“height”];
$width=$row[“width”];
if ($height > $width && $height > $max){
$ratio = $height/$max;
$height = $max;
$width = $width/$ratio;
}
else if($width > $max) {
$ratio = $width/$max;
$width = $max;
$height = $height/$ratio;
}
echo "

";
}
	 $referer = $_SERVER['http_referer'];

	
	?>[/php]

into the row i added in the table
[php]echo “

”;[/php]

but all I get is the following error:
Notice: Undefined index: id in/search.php

What I’ve tried doing is simply add
[php]$aid = $_GET[‘id’] ;
if (is_numeric($aid)){
header (“location:search.php”);
}[/php]

What I really want it to do is display a thumbnail from the picture from showad.php in the size of 75px left of the object row with the other search results(category,city)

Object <?php echo $row["Object"];?>
Category: <?php echo $row["catName"];?>
Uploaded by: <?php echo $row["Name"];?>
Date: <?php echo $row["DateTime"];?>
Phone number: <?php echo $row["Phone"];?>
City: <?php echo $row["cityName"];?>
Zip: <?php echo $row["Zip"];?>
E-Mail: <?php echo $row["Email"];?>
Info about the object: <?php echo $row["Info"];?>
Price (usd): <?php echo $row["Price"] . ":-";?>
Picture (click to view in original size): sometext Picture ” . $row[“Object”] . “” . “” . $row[“catID”] . “” . $row[“Price”] . “:-” . “” . $row[“DateTime”] . “” . $row[“cityName”] . “
sometext
” . HERE IS WHERE I ADD IT . “
Sponsor our Newsletter | Privacy Policy | Terms of Service