Jump to content

[SOLVED] Table Joins & Displaying results


iceblox

Recommended Posts

Hi Guys,

 

I have a piece of code on my website that joins to tables together what i would like to do is only show the results if it returns 2 or more results. How would I accomplish this? Ive tried but not got very far.. Can any one help? This is the code...

 

 

<?php

$query = "SELECT deals.MakeName, deals.ModelName, deals.ModelID, deals.ImageSmall, code.modelid
FROM deals
INNER JOIN code
ON deals.ModelID = code.modelid WHERE code.modid = $modid GROUP BY deals.ModelName";


$result = mysql_query($query);


if (mysql_num_rows($result) > 0)
{

echo '<h3 align=center>Available Colours</h3>';

$num_rows = mysql_num_rows($result);
echo "<TABLE align=\"center\" BORDER=\"0\">\n";

$columns = $num_rows;

for($i = 0; $i < $num_rows; $i++) {
$row = mysql_fetch_array($result);
if($i % $columns == 0) {
echo "<TR>\n";
}
echo '<td align=center><center><a href="mobile-phone-deals/Compare_' . str_replace(" ","+",$row[0] ) . '-' . str_replace(" ","+",$row[1] ) . '_Mobile-Phones-'. $row[2].'.html"><img border="0" alt="Compare '. $row[0].' '. $row[1].' Mobile Phone Deals" src="'. $row[3].'"></a>&nbsp&nbsp&nbsp&nbsp</center>';
echo '</td>';
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
echo "</TR>\n";
}
}
echo "</TABLE>\n";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/85798-solved-table-joins-displaying-results/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.