Jump to content

Help w Something really simple PLZ!


Nas[wD]

Recommended Posts

The code:

$query = "SELECT * FROM forum_forums";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
extract($row);
$total = $row["topics"] + $row["posts"];
}

 

I know how to add the topics and posts per row, but i don't know how to add all the rows together

 

I wanna add the fields 'topics', and 'posts' from all the rows together for a $ultratotal

 

please help me somebody

 

 

Link to comment
Share on other sites

$query = "SELECT * FROM forum_forums";
$result = mysql_query($query) or die(mysql_error());
$count = 0;
while($row = mysql_fetch_array($result)) {
extract($row);
$total = $row["topics"] + $row["posts"];
$count = $count + $total;
}
echo $count; //should be your ultratotal

Link to comment
Share on other sites

Yeah, you could do a query to add up all the subtotals, but since you are already getting all the individual records a better approach would be to calculate the subtotals as you process each record.

 

I thought the same thing, but I don't know how to lay it out in code

Link to comment
Share on other sites

this will be faster. should work.

$ultratotal = mysql_result(mysql_query("SELECT sum(topics) + sum(posts) as ultratotal FROM forum_forums"),0);

 

Damn you guys are teaching me so much stuff, and they both work! Thank you so much!!!!!

 

$totalmembers = mysql_result(mysql_query("SELECT COUNT(id) as totalmembers FROM members"),0);

- also worked for my total members stat :D thanks again!

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.