Reputation: 89
My datebase has 2 tables [white/black] and in that tables will be pictures. I want to show that image in a pair. One picture from white table and one picture from black table. It is like Hot or Not scripts. My question is how to display that images, that after page refresh there will be other pair.
<?php
$link = mysql_connect("localhost", "root", "");
mysql_select_db("dvddb");
$sql = "SELECT image FROM white WHERE id=1 //and image from black where id=1";
$result = mysql_query("$sql");
mysql_close($link);
?>
i found this code to display picture from id. How to set thath query...
Upvotes: 0
Views: 77
Reputation: 694
You should use SQL Joins for this
A Visual Explanation of SQL Joins
Upvotes: 1
Reputation: 2128
here is your solution :)
$qry = mysql_qyery("select * from white");
while($row = mysql_fetch_array($qry))
{
$qry2 = mysql_query("select * from black where id = '".$row['id']."'");
while($row2 = mysql_fetch_array($qry2))
{
echo $row['image'];
echo $row2['image'];
}
}
please let me know if you want any further guidance...
Upvotes: 2