Jump to content

[SOLVED] Is it possible to...?


dre

Recommended Posts

Run a if statement on a query??

what i mean is i have the following piece of code:

          <?php 
$db = mysql_connect("localhost", "Username", "Password"); 
mysql_select_db("phone",$db); 
$result = mysql_query
("SELECT
pd.category,
SUM(phone_sales.quantity) * t.r AS '%'
FROM phone_sales, phone_details pd 
JOIN (SELECT 100/SUM(quantity) AS r FROM phone_details) AS t
WHERE pd.phone_id=phone_sales.phone_id
GROUP BY pd.category",$db)or die(mysql_error());

echo "<TABLE BORDER=3 BORDERCOLOR=black><TBODY BGCOLOR=white>"; 
echo"<TR><TD><B>Category</B></TD><TD><B>Category Sales Performance</B></TD></TR>";
while($myrow = mysql_fetch_array($result)) 
{ 
echo "<TR><TD>"; 
echo $myrow["category"];
echo "<TD>";
echo $myrow["%"];
echo "</TD>";
} 
echo "</TABLE>"; 
?>

this generates a table that places a list of mobile phones in one of three categories along with the sales performance (%), if a higher percentage of phones sold are category 1 then i would like to echo "recommendation" on screen.

Any help/ideas will be much appreciated!!

Link to comment
https://forums.phpfreaks.com/topic/38662-solved-is-it-possible-to/
Share on other sites

Sorry,

say for example i get this result from my code:

 

category    sales(%)

    1                  30

    2                  21

    3                  12

 

i would then like a message printed on screen saying category 1 is most popular.

 

Archived

This topic is now archived and is closed to further replies.

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