code used:
PHP Code:
$sql = "SELECT handset, MIN(price) WHERE make='$getmake' GROUP BY handset";
error msg:
HTML Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xxxx/public_html/test.php on line 18
database example:
ID | Handset | Make | Network | Tariff | Total Cost| Line Rental | Mins | Texts | URL
There are on average 20 records with the same handset name.
I want to show every handset determaned by its make, but only show the ones with the min "Total Cost"
e.g. of code
PHP Code:
<?php
$getmake = $_GET['make'];
$address = "localhost";
$username = "xxxx";
$password = "xxxx";
$db = "xxxx";
$table = "xxxx";
$conn = mysql_connect($address, $username, $password);
$rs = mysql_select_db($db, $conn);
$sql = "SELECT handset, MIN(price) WHERE make='$getmake' GROUP BY handset";
$rs = mysql_query($sql, $conn);
$j = 0;
echo("<table width='100%' border='0' cellpadding='0' cellspacing='0' id='$make'><tr valign='top'>");
while($row = mysql_fetch_array($rs)) {
$handset = $row[handset];
$make = $row[make];
$tariff = $row[tariff];
$tariffid = $row[tariffid];
$id = $row[handsetid];
$price = $row[price];
$url = $row[url];
$gift = $row[gift];
$texts = $row[texts];
$xnet = $row[xnet];
$offpeak = $row[offpeak];
$merchant = $row[merchant];
$contractlength = $row[contractlength];
$montlycost = $row[monthlycost];
$cashback = $row[cashback];
$freerental = $row[freerental];
$halfrental = $row[halfrental];
$total = $row[total];
if ($xnet == "0") $xnetmin = ("");
if ($xnet != "0") $xnetmin = ("$xnet Anytime Minutes");
if ($offpeak == "0") $offpeakmin = ("");
if ($offpeak != "0") $offpeakmin = ("$offpeak Off Peak Minutes");
if ($texts == "0") $textsmin = ("Text Bundles Available");
if ($texts != "0") $textsmin = ("$texts <b>FREE</b> Texts");
echo("<th class='menusmall' align='center' width='16%'><p align='center'><font face='Tahoma' style='font-size: 9pt'><b><br />");
echo("<table border='0' width='200' id='$handset' cellspacing='5' cellpadding='0'><tr><td colspan='2' width='0'><p align='left'><font style='FONT-SIZE: 9pt' face='Tahoma'><b><span style='TEXT-DECORATION: none'><font color='#2d75d7'><a href='http://www.xxxx.com/handsets.php?hs=$id.'><font color='#2D75D7'><span style='text-decoration: none'>$handset</span></font></a></font></span></b></font></td><td width='9%'><font face='Tahoma' size='1'><a class='tditem' href='http://www.xxxx.com/handsets.php?hs=$id'><img src='http://www.xxxx.com/images/network$network.gif' border='0' align='right'></a></font></td></tr><tr><td width='10%' valign='top'><font style='FONT-SIZE: 9pt' face='Tahoma'><b><span style='TEXT-DECORATION: none'><font color='#2d75d7'><a href='http://www.xxxx.com/handsets.php?hs=$id'><img alt='$handset' src='http://www.xxxx.com/images/handset_$id.jpg' border='0'></a></font></span></b></font></td><td width='83%' colspan='2'><font color='#2D75D7' face='Tahoma'><span style='font-size: 9pt'>$gift</span></font><p><font color='#2D75D7' face='Tahoma'><span style='font-size: 9pt'>$tariff<br><b>$xnetmin$offpeakmin</b><br>$textsmin</span></font></td></tr></table>");
echo("<br /><br /></th>");
$j++;
if(($j % 4) == 0) echo("</tr>\n<tr>");
}
echo("</tr></table>");
mysql_close();
?>
Bookmarks