...

View Full Version : PHP Photo Changer



chris23
08-02-2012, 04:53 PM
What I need help with is being able to click and change a main image with other thumbnails.

The problem is (i think) is because the page is loading different pictures for different products and from the database it's not working with js or jqeury.

here is the code

----------Main Image--------------

<div id="image"><?php echo '<img src="pics/'.$row['pic1'].'">';?> </div>
------------Thumbs-------------------------------


echo '<img src="pics/'.$row['pic2'].'">';?> <?php echo '<img src="pics/'.$row['pic3'].'">';?> <?php echo '<img src="pics/'.$row['pic4'].'">';?><?php echo '<img src="pics/'.$row['pic5'].'">';?><?php echo '<img src="pics/'.$row['pic6'].'">';?><?php echo '<img src="pics/'.$row['pic7'].'">';?><?php echo '<img src="pics/'.$row['pic8'].'">';?><?php echo '<img src="pics/'.$row['pic9'].'">';?>

A online live demo can be viewed if necessary.

Any help would be much appreciated and thank you in advance

DrDOS
08-02-2012, 06:40 PM
What does a print_r of $row produce? I have a suspicion it should be

$row['pic3'][0]

chris23
08-02-2012, 06:49 PM
( [0] => 36 [id] => 36 [1] => t [title] => t [2] => t [model] => t [3] => 8 [cat_id] => 8 [4] => tlfjldsjlkdsjsd [description] => tlfjldsjlkdsjsd [5] => t [year_regletter] => t [6] => t [vin_number] => t [7] => [type] => [8] => t [axle_config] => t [9] => t [gross_weight] => t [10] => tt [suspension] => tt [11] => t [transmission] => t [12] => t [power_output] => t [13] => t [mileage] => t [14] => t [mot_status] => t [15] => 1002092 [price] => 1002092 [16] => 36-1.jpg [pic1] => 36-1.jpg [17] => 36-2.jpg [pic2] => 36-2.jpg [18] => 36-3.jpg [pic3] => 36-3.jpg [19] => 36-4.jpg [pic4] => 36-4.jpg [20] => 36-5.jpg [pic5] => 36-5.jpg [21] => 36-6.jpg [pic6] => 36-6.jpg [22] => [pic7] => [23] => [pic8] => [24] => [pic9] => )

Here is the page code


]<style>
#col-1{
width:450px;
height:450px;
margin-right:55px;
float:left;
}
#col-2{
width:450px;
float:left;
height:450px;
}
#col-3{
height:120px;
width:100%;
margin-top:165px;
margin-bottom:25px;
}

#col-3 img{
height:100px;
width:100px;
margin-right:15px;

}



.box img {
height:100px;
width:150px;
}
.box{
width:150px;
float:left;
background-color:#0F0;
margin-right:20px;
height:100px;
}
#image{
background-image:url(temp/img_holder.jpg);
height:310px;
}

#image img{
width:426px;
height:287px;
margin-top:8px;
margin-left:16px;

}
</style>
<?php include('header.php');?>
<?php
$id = $_REQUEST['id'];
$result = mysql_query("SELECT * FROM products WHERE id = '$id';") or die(mysql_error());
$row = mysql_fetch_array( $result );
$title=$row['title'];
?>
<div id="wrapper" style="margin-top:-85px;">
<div id="page" style="height:660px;">
<div id="col-1">
<h2><?php echo "{$row['title']}";?></h2>
<div id="image"><?php echo '<img src="pics/'.$row['pic1'].'">';?> </div>
<br/><br/><br/>
<h3>Further Vehicle Details</h3>
<p style="text-align:justify; margin-top:-10px;">
<?php echo "{$row['description']}";?>
</p>
</div>
<div id="col-2">
<img src="temp/enquire.jpg" alt=""/>
<table width="401">
<tr>
<td style="border-bottom:#999 1px solid;">Model: <p style="padding:0; float:right; margin:0"><?php echo "{$row['model']}";?></p></td>
</tr>
<tr>
<td style="border-bottom:#999 1px solid;">Year &amp; Reg Letter: <p style="padding:0; float:right; margin:0"><?php echo "{$row['year_regletter']}";?></p></td>
</tr
><tr>
<td style="border-bottom:#999 1px solid;">Axel Config: <p style="padding:0; float:right; margin:0"><?php echo "{$row['axle_config']}";?></p></td>
</tr>
<tr>
<td style="border-bottom:#999 1px solid;">Gross Weight: <p style="padding:0; float:right; margin:0"><?php echo "{$row['gross_weight']}";?> kg</p></td>
</tr>
<tr>
<td style="border-bottom:#999 1px solid;">Suspension: <p style="padding:0; float:right; margin:0"><?php echo "{$row['suspension']}";?></p></td>
</tr>
<tr>
<td style="border-bottom:#999 1px solid;">Transmission: <p style="padding:0; float:right; margin:0"><?php echo "{$row['transmission']}";?></p></td>
</tr>
<tr>
<td style="border-bottom:#999 1px solid;">Power Output: <p style="padding:0; float:right; margin:0"><?php echo "{$row['power_output']}";?> bhp</p></td>
</tr>
<tr>
<td style="border-bottom:#999 1px solid;">Mileage: <p style="padding:0; float:right; margin:0"><?php echo "{$row['mileage']}";?> km</p></td>
</tr>
<tr>
<td style="border-bottom:#999 1px solid;">MOT Status: <p style="padding:0; float:right; margin:0"><?php echo "{$row['mot_status']}";?></p></td>
</tr>
<tr>
<td style="border-bottom:#999 1px solid;">Cost: <p style="padding:0; font-weight:bold; float:right; margin:0"> <?php echo "{$row['price']}";?></p></td>
</tr>
</table
></div>
<div class="clearfix"></div>
<br/><br/><br/>
<div id="col-3" style="margin-top:-5px;">
<?php echo '<img src="pics/'.$row['pic2'].'">';?> <?php echo '<img src="pics/'.$row['pic3'].'">';?> <?php echo '<img src="pics/'.$row['pic4'].'">';?><?php echo '<img src="pics/'.$row['pic5'].'">';?><?php echo '<img src="pics/'.$row['pic6'].'">';?><?php echo '<img src="pics/'.$row['pic7'].'">';?><?php echo '<img src="pics/'.$row['pic8'].'">';?><?php echo '<img src="pics/'.$row['pic9'].'">';?>

<br/>
</div>
</div>
<br/>
</div>

<?php include('footer.html');?>

chris23
08-02-2012, 06:56 PM
Thank you in advance and for replying to me

DrDOS
08-02-2012, 07:08 PM
print_r($row) is what we need to see here. Could you put that in the page and edit your post to include what it yields?

Len Whistler
08-03-2012, 03:19 AM
You should not have php opening tags right after php closing tags. I have cleaned up your code to make it easier to read, but your problem probably still exists.


<?php

echo '<img src="pics/'.$row['pic2'].'">';
echo '<img src="pics/'.$row['pic3'].'">';
echo '<img src="pics/'.$row['pic4'].'">';
echo '<img src="pics/'.$row['pic5'].'">';
echo '<img src="pics/'.$row['pic6'].'">';
echo '<img src="pics/'.$row['pic7'].'">';
echo '<img src="pics/'.$row['pic8'].'">';
echo '<img src="pics/'.$row['pic9'].'">';

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum