iceblox Posted January 13, 2008 Share Posted January 13, 2008 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>    </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 More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 $num_rows = mysql_num_rows($result); if($num >= 2) { // Display } else { // Do something else } Link to comment https://forums.phpfreaks.com/topic/85798-solved-table-joins-displaying-results/#findComment-437893 Share on other sites More sharing options...
iceblox Posted January 13, 2008 Author Share Posted January 13, 2008 Thanks, I think i tried to complicate a simple fix. Cheers! Link to comment https://forums.phpfreaks.com/topic/85798-solved-table-joins-displaying-results/#findComment-437896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.