heraldic2 Posted November 8, 2011 Share Posted November 8, 2011 Greetings, I need a bit of php coding help. I have a query that gives me results. What I need to do is take those results and, I think, use php to compare the results and add a 1 to the correct section. Example: 3 tables table name- retail_sales id sales_id amount week table name- online_sales id sales_id amount week table name- sales_person sales_id name I have the query that breaks down results by week: week 1 | retail_sales.amount | online_sales.amount What I need is some php code that will then compare the two together and: if retail_sales.amount > online_sales.amount +1 to retail OR if retail_sales.amount < online_sales.amount +1 to online so you would end up with a result like a sports record (6-2) Any ideas Thank you for any help Link to comment https://forums.phpfreaks.com/topic/250674-adding-query-results/ Share on other sites More sharing options...
joel24 Posted November 8, 2011 Share Posted November 8, 2011 $sql=@mysql_query("SELECT * FROM etc etc"); $retail=0; $sales=0; while ($row=mysql_fetch_assoc($sql)) { if ($row['retail_sales.amount'] > $row['online_sales.amount']) { $retail++; } else { $sales++; } } echo "$retail - $sales"; Link to comment https://forums.phpfreaks.com/topic/250674-adding-query-results/#findComment-1286140 Share on other sites More sharing options...
heraldic2 Posted November 9, 2011 Author Share Posted November 9, 2011 Thank you very much. It is exactly what I needed. Link to comment https://forums.phpfreaks.com/topic/250674-adding-query-results/#findComment-1286450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.