This is the second part of a script. It gets the EAN from the form in the first part.

Where there are sales, it will show total number but if not I want to show a message to say "none" or "No Sales". Don't quite get the else/if errors. Could someone suggest what I've done wrong.

<?php

include 'db.php';
$term = $_POST['EAN'];
$term = TRIM($term);

$sql = mysql_query("SELECT Name, Brand, EAN, sum(orderedquantity) As SumS 
FROM $salesdb 
WHERE EAN LIKE '%$term%' Limit 0,5");

while ($row = mysql_fetch_array($sql))
{

if($row['SumS'] <'1')
{
Print '<table style="width:100%;margin-left:auto;margin-right:auto" border=1><font face=arial size=2 > <tr><td>Sales 2012:<b>"None Sold"</b></td></tr></table>';

}
else
{
    Print '<table style="width:100%;margin-left:auto;margin-right:auto" border=1><font face=arial size=2 >
<tr><td>Sales 2012:<b>'.$row['SumS'].'</b></td></tr></table>';
   }


?>

Recommended Answers

All 2 Replies

Member Avatar for diafol

What do you mean errors? You just have 2 echoes. Is your SQL correct - on what criteria are you summing? Do you need a GROUP BY clause?

I put group by in query and put conidtion outside of while to show "no-record"

<?php

include 'db.php';
$term = $_POST['EAN'];
$term = TRIM($term);

$sql = mysql_query("SELECT Name, Brand, EAN, sum(orderedquantity) As SumS 
FROM $salesdb 
WHERE EAN LIKE '%$term%' group by  Name, Brand, EAN Limit 0,5");
$i=-1;
while ($row = mysql_fetch_array($sql))
{
    $i++;


    Print '<table style="width:100%;margin-left:auto;margin-right:auto" border=1><font face=arial size=2 >
<tr><td>Sales 2012:<b>'.$row['SumS'].'</b></td></tr></table>';
}


if($i==-1)
{
    Print '<table style="width:100%;margin-left:auto;margin-right:auto" border=1><font face=arial size=2 > <tr><td>Sales 2012:<b>"None Sold"</b></td></tr></table>';

}


?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.