dre Posted February 15, 2007 Share Posted February 15, 2007 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!! Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted February 15, 2007 Share Posted February 15, 2007 I dont understand your request.. if a highere percentage of phones are category 1??? what do you mean? please explain your self in ohter way... Quote Link to comment Share on other sites More sharing options...
dre Posted February 15, 2007 Author Share Posted February 15, 2007 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. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 15, 2007 Share Posted February 15, 2007 If you want to know which is most popular, slap: ORDER BY '%' DESC LIMIT 1 onto the end of your query. Quote Link to comment Share on other sites More sharing options...
dre Posted February 15, 2007 Author Share Posted February 15, 2007 lol knew it would be somthing simmple like that! cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.