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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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