0

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>';
   }


?>
3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by urtrivedi
0

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?

0

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>';

}


?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.