zackcez Posted July 3, 2008 Share Posted July 3, 2008 I'm trying to put this in my loop: " . $row[$stat] . " Where stat is this by default: $stat = Attackxp + Woodcuttingxp + Defencexp + Strengthxp + Hitpointsxp + Rangexp + Prayerxp + Magicxp + Cookingxp + Fletchingxp + Fishingxp + Firemakingxp + Craftingxp + Smithingxp + Miningxp + Herblorexp + Agilityxp + Thievingxp + Slayerxp + Farmingxp + Runecraftingxp; Each item in $stat is in the mysql database....How could I make this correctly work? Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/ Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 What are the constants Attackxp, Woodcuttingxp, etc..? Are those supposed to be numerical variables? Can you be more specific as to how you are doing this? Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581083 Share on other sites More sharing options...
zackcez Posted July 3, 2008 Author Share Posted July 3, 2008 I currently have them set as big integers. Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581086 Share on other sites More sharing options...
wildteen88 Posted July 3, 2008 Share Posted July 3, 2008 You need to explain more clearly, what do you mean by I'm trying to put this in my loop: " . $row[$stat] . " What loop? What's with all those constants in the $stats variable. Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581091 Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 Oh, do you mean that your query returns all those fields (Attackxp, etc...)? If that is the case, your code would just be: " . $row['Attackxp'] . "<br>" . $row['Woodcuttingxp'] . "<br>" . $row['Defencexp']; //etc... If that isn't what you mean, you will have to be more specific. Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581095 Share on other sites More sharing options...
zackcez Posted July 3, 2008 Author Share Posted July 3, 2008 I want the Attackxp and all the others to be added up to get a sum. Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581098 Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 It would probably best to use the SUM() function in your query, or in the loop, your pseudo-code would work, you just need the right syntax: $stat = $row['Attackxp'] + $row['Woodcuttingxp'] + $row['Defencexp']; //etc... echo $stat; Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581102 Share on other sites More sharing options...
zackcez Posted July 3, 2008 Author Share Posted July 3, 2008 The value then just come out as...nothing Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581123 Share on other sites More sharing options...
teynon Posted July 3, 2008 Share Posted July 3, 2008 here is a simple solution to your query. Instead of looping and adding and what not in PHP, let MYSQL do the adding. Here is an exampe: SELECT Attackxp+Woodcuttingxp+Defencexp WHERE `ID` = 1 Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581132 Share on other sites More sharing options...
zackcez Posted July 3, 2008 Author Share Posted July 3, 2008 But now How can I make it order it by the value gotten when adding them all up :s Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581233 Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 There is only going to be one value when you add them all up so how would you order them? Link to comment https://forums.phpfreaks.com/topic/113119-solved-mysql-while-loop/#findComment-581285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.