visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: php & mysql & 2 tables


By: roe1and Great Britain  Date: 29/01/2008 15:23:29  English  Points: 20 Status: Answered
Quality : Excellent
hello again. i have been struggling with something for q day or so now. i'm trying to compare the information in two tables and my code looked like this:

$sql1 = "SELECT * FROM $tbl_tab;";
$query1 = mysql_query($sql1, $marc) or die ("No 1: Misbehaving: .mysql_error());
$rows1 = mysql_num_rows($query1);

echo '<table>';
for ($i=0; $i<$rows1; $i++) {

$tab_year = mysql_result($query1, $i, "tab_year");
$tab_img = mysql_result($query1, $i, "tab_img");
$tab_art = mysql_result($query1, $i, "tab_art");

$sql2 = "SELECT * FROM $tbl_du WHERE du_img = $tab_img AND du_year = tab_year;";
$query2 = mysql_query($sql2, $marc);

$du_img = mysql_result($query1, $i, "du_img");
$du_year = mysql_result($query1, $i, "du_year");

if (empty($du_img) && empty($du_year)) {
echo '<tr><td>$' . $tab_art . '</td><td>' . $tab_year . '/' . $tab_img . '.tif</td></tr>';

} else {}

}</table>

this works but it is slow. because i have one query running inside another. i think what i need is a JOIN query, but i have never done this before. any help welcome
By: roe1and Date: 29/01/2008 15:51:10 English  Type : Comment
i should add if my $tbl_tab lookes like this:

year image art
1886 000155 flowers
1886 000154 candles

and my $tbl_du looks like this:

year image
1886 000155

then the results should be

candles 1886/000154
By: roe1and Date: 30/01/2008 16:14:30 English  Type : Answer
SELECT DISTINCT tab_year FROM $tbl_tab LEFT JOIN $tbl_du ON $tbl_du.du_id = $tbl_tab.tab_id WHERE $tbl_du.du_id IS NULL

Do register to be able to answer

EContact
browser fav
page generated in 89.445830 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page