3 Replies - 645 Views - Last Post: 26 October 2010 - 11:44 AM Rate Topic: -----

#1 artgraven  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-October 10

result incrementation in while loop

Posted 26 October 2010 - 04:23 AM

Greetings All

thank you for taking the time to read my question.

it is simple but i keep getting stuck

i am attempting to generate a index for a dynamically produced pdf using dompdf.

i did a "SELECT catagory, SUM(entries) FROM table"

now i am passing it out as a while loop

while($row = mysql_fetch_array($SUMresult)){
$page = $row['SUM(hits)'];
	echo " ". $row['catagory']. " contains ". $page . " listings";
	echo "<br />";
}


which shows me how many entries exist for each catagory.

now when trying to generate the index. i need to

take the result of the above $page and increment each output with the prior output. dividing each by 15 for example
$page = $row['SUM(hits)'] / 15;

so the first result may be 0.6 then if the second result is 1.6 it should instead give me 2.2.

this way i can generate the index by knowing when each result set will end and how many will be on each page (each page containing 15 results)

i apologise if this seems a bit dumb an inexperienced but i highly value any insight into this

This post has been edited by JackOfAllTrades: 26 October 2010 - 04:28 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: result incrementation in while loop

#2 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,212
  • Joined: 23-August 08

Re: result incrementation in while loop

Posted 26 October 2010 - 04:30 AM

$page += $row['SUM(hits)'] / 15;
maybe?
Was This Post Helpful? 1
  • +
  • -

#3 artgraven  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-October 10

Re: result incrementation in while loop

Posted 26 October 2010 - 11:37 AM

Thank you so very much

i first tried adding it after the result set with no results and a few other things and finally realized that i was pre-declaring the variable to the result set instead of just setting it to 0 at the top. as is typical with an increment.

final working code

$page = 0;
  //Print out result
while($row = mysql_fetch_array($SUMresult)){
        $page += $row['SUM(entries)']/15;
	echo " ". $row['catagory']. " contains ". $page . " listings" ;
	echo "<br />";
}


now on to the final challenge.

figuring out how to move the catagory(category) one up so that the i can display the starting point.

thank you so very much for the moment of clarity.

This post has been edited by CTphpnwb: 26 October 2010 - 11:45 AM
Reason for edit:: 2nd failure to use code tags.

Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,738
  • Joined: 08-August 08

Re: result incrementation in while loop

Posted 26 October 2010 - 11:44 AM

Please use code tags!

I'm not sure what you're trying to do, but it looks like a while loop is unnecessary (for getting the totals) if you get your query right. For anything that does require a while loop, you should probably be using LIMIT.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1