I've two tables , bns_cars and bns_cars_imagesPHP Code:$sq = "SELECT * FROM bns_cars WHERE id = (".$_GET['id'].")";
$dat = mysql_query( $sq );
$nfo = mysql_fetch_assoc( $dat );
$stype = ($nfo['type']);
$sql = "SELECT m.id, m.type, a.path, a.file_name, a.record_id FROM bns_cars m, bns_cars_images a WHERE m.id = a.record_id GROUP BY m.type HAVING m.type = (".$stype.")" ;
$data = mysql_query( $sql )
or die(mysql_error());
while($info = mysql_fetch_array( $data )) {
echo "<a href=http://xxx.com/index.php?module=cars&id={$info['id']}><img src=http://xxx.com/uploads/cars/{$info['path']}/{$info['file_name']} width=170px height=113px /></a>" ;
}
Tables : bns_cars
ID : 360 | type : 24
ID : 321 | type : 24
ID : 363 | type : 24
ID : 320 | type : 33
Tables : bns_cars_images
record_id : 360 | path: 2012/10/10 | file_name : example1.jpg
record_id : 360 | path: 2012/10/10 | file_name : example2.jpg
record_id : 360 | path: 2012/10/10 | file_name : example3.jpg
record_id : 360 | path: 2012/10/10 | file_name : example4.jpg
record_id : 321 | path: 2012/10/10 | file_name : example5.jpg
record_id : 363 | path: 2012/10/10 | file_name : example6.jpg
record_id : 320 | path: 2012/10/10 | file_name : example7.jpg
My SQL query is working but this is not what i actually want it to do.
My website link will appear like this : http://xxx.com/index.php?module=cars&id=360 ( ID is different of every car )
So i want the SQL to check the type of the current car by using the ID from the URL and then search all types with the type we just got using the current URL and show only one image as echo from each type by comparing the id and record_id.
If i wasn't able to express myself well then i would like to show my desired output
Let's say the type we got is "24" so the output will be
I also understand i am using mysql instead of mysqli and PDO but for this moment i would like to know how this is done by using my mysql and later i will convert itHTML Code:<a href=http://xxx.com/index.php?module=cars&id=360><img src=http://xxx.com/uploads/cars/2012/10/10/example1.jpg width=170px height=113px /></a> <a href=http://xxx.com/index.php?module=cars&id=321><img src=http://xxx.com/uploads/cars/2012/10/10/example5.jpg width=170px height=113px /></a> <a href=http://xxx.com/index.php?module=cars&id=363><img src=http://xxx.com/uploads/cars/2012/10/10/example6.jpg width=170px height=113px /></a>




Reply With Quote