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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.