johnny Posted August 14, 2006 Share Posted August 14, 2006 Ok I have the following queries that display numeric values on my page:[code] <?php $link = mysql_connect("xxx", "xxx", "xxx") or die("Could not connect : " . mysql_error());mysql_select_db("xxx") or die("Could not select database");$query="SELECT CelebTotal.$weekFROM CelebTotal,scheduleWHERE CelebTotal.Celeb = schedule.f1AND schedule.week = $weekAND schedule.team = '1'";$res = mysql_query($query);while($row = mysql_fetch_assoc($res)){echo $row [$week].'<br>';}?> <?php $link = mysql_connect("xxx", "xxx", "xxx") or die("Could not connect : " . mysql_error());mysql_select_db("xxx") or die("Could not select database");$query="SELECT CelebTotal.$weekFROM CelebTotal,scheduleWHERE CelebTotal.Celeb = schedule.f2AND schedule.week = $weekAND schedule.team = '1'";$res = mysql_query($query);while($row = mysql_fetch_assoc($res)){echo $row [$week].'<br>';}?>[/code]I want to ADD these two values and display that number on the same page. I have tried something like this, but it's not working:[code]<?php $link = mysql_connect("xxx", "xxx", "xxx") or die("Could not connect : " . mysql_error());mysql_select_db("xxx") or die("Could not select database");$query="SELECT CelebTotal.$weekFROM CelebTotal,scheduleWHERE CelebTotal.Celeb = schedule.f1AND schedule.week = $weekAND schedule.team = '1'";$query2="SELECT CelebTotal.$weekFROM CelebTotal,scheduleWHERE CelebTotal.Celeb = schedule.f2AND schedule.week = $weekAND schedule.team = '1'";$res=mysql_query($query);$res2=mysql_query($query2);$total = $res+$res2;echo $total;?>[/code]It returns a number, but that number is always 7 and that's not correct. Link to comment https://forums.phpfreaks.com/topic/17472-how-can-i-add-these-query-results/ Share on other sites More sharing options...
hostfreak Posted August 14, 2006 Share Posted August 14, 2006 Try:[code]<?php $link = mysql_connect("xxx", "xxx", "xxx") or die("Could not connect : " . mysql_error());mysql_select_db("xxx") or die("Could not select database");$query="SELECT CelebTotal.$weekFROM CelebTotal,scheduleWHERE CelebTotal.Celeb = schedule.f1AND schedule.week = $weekAND schedule.team = '1'";$res=mysql_query($query);$total = $res++;echo $total;?>[/code[[/code] Link to comment https://forums.phpfreaks.com/topic/17472-how-can-i-add-these-query-results/#findComment-74350 Share on other sites More sharing options...
johnny Posted August 14, 2006 Author Share Posted August 14, 2006 What does the "++" mean/do? That code only includes one of the two queries I want to add together. Link to comment https://forums.phpfreaks.com/topic/17472-how-can-i-add-these-query-results/#findComment-74752 Share on other sites More sharing options...
king arthur Posted August 14, 2006 Share Posted August 14, 2006 ++ means post-increment. The line "$total = $res++" means "assign the value of $res to $total, and then increase $res by 1". Link to comment https://forums.phpfreaks.com/topic/17472-how-can-i-add-these-query-results/#findComment-74776 Share on other sites More sharing options...
johnny Posted August 14, 2006 Author Share Posted August 14, 2006 That is displaying "Resource id #3" - WTF is that? Link to comment https://forums.phpfreaks.com/topic/17472-how-can-i-add-these-query-results/#findComment-74779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.