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!! Link to comment https://forums.phpfreaks.com/topic/38662-solved-is-it-possible-to/ 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... Link to comment https://forums.phpfreaks.com/topic/38662-solved-is-it-possible-to/#findComment-185652 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. Link to comment https://forums.phpfreaks.com/topic/38662-solved-is-it-possible-to/#findComment-185665 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. Link to comment https://forums.phpfreaks.com/topic/38662-solved-is-it-possible-to/#findComment-185684 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! Link to comment https://forums.phpfreaks.com/topic/38662-solved-is-it-possible-to/#findComment-185784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.