Hi, Guys. I`m in a small pickle.. :/ $i = 1; <div id="featuredb-<?=$i?>" class="featuredbox"> I need it so that the "i" changes value, start from 1 to 5. So that the first output shows 1, the 2nd to show: 2, and so on.. It does not have to be named "i" or any thing like that i just tryed to add it in my self but failed. I allso need the output to be limited at: 5 items. I need to make so that i can get an arrow that i can output few places in the php / html code to get the right class / ID for styling it etc. Any one? Here is the PHP CODE: function display_todaysmostpopular($base_url,$rewrite,$sedir){ ?> <? $x = 0; $sql_query = "SELECT * from games WHERE gamestatus = 1 ORDER BY playedtoday DESC LIMIT 24"; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { //output as long as there are still available fields while($row = mysql_fetch_array($result)) { $x++; $i = 1; $mostpopulargametitle = $row[gametitle]; $mostpopulargametitle = stripslashes($mostpopulargametitle); $mostpopulargameid = $row[gameid]; $mostpopulartimesplayed = $row[timesplayed]; $gamedescription = $row[$gamedesc]; $sepopular = str_replace (" ","-",$mostpopulargametitle); $sepopular= str_replace ("'","_",$sepopular); $mostpopularicon = $row[gameicon]; $iconlocation = $row[iconlocation]; $mostplayed = $row[playedtoday]; // If SE Friendly is turned OFF, this will be displayed if ($rewrite != 1) $gameurl = $base_url."index.php?action=playgame&gameid=".$mostpopulargameid; else $gameurl = $base_url.$sedir."/".$sepopular; if ($iconlocation ==1) $gameicon = $mostpopularicon; else $gameicon = $base_url."games/images/".$mostpopularicon; ?> <?if ($x ==1 || $x == 9) echo "";?> <div id="featuredb-<?=$i?>" class="featuredbox"> <a href="<?=$gameurl;?>" title="Click to play <?=$mostpopulargametitle;?>" class="featured-1"><img src="<?=$gameicon;?>" width="180" height="130" alt="" /></a> <h3><?=$mostpopulargametitle;?></h3> <p> <?=$gamedescription;?> <br><?=$mostplayed;?> plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <?if ($x ==8 || $x == 26) echo "";?> <? } } ?> <? } ?> PHP:
I'm not sure where that would go as I didn't read the whole code but : for ($i=1; $i<=5; $i++) { //put code here } Code (markup):
Hi, Well if i put the for ($i=1; $i<=5; $i++) in the start of the code where the $i is now, how can i echo that number to the output field? PS: Thank you for your help!
Take the $i =1 out of your while loop. It resets itself to 1 every time you do the loop. Use $i++ inside the loop to increment. Its like saying $i +1
Hi, How would you implant that $i++ into the code above? And thanks again, i will have more issues with PHP small fixes. If someone wants to take the job, please post your payment request and it will be done! Thanks
This is pretty simple same as the $x. i would feel like i was taking money for free accepting this job as for the limit : you mean the results if so change LIMIT in the query to 0,5
Neo, I believe you could simplify your problem by modifying your query to only return the TOP 5 games of the day instead of using PHP logic. This would depend on how your database is organized, and how you log the number of times a game has been played. You can PM me if you want to discuss.
here is the code i used: <?php for ($i=1; $i<=5; $i++) { if ($x ==1 || $x == 9) echo "";?> <div id="featuredb-<?=$i?>" class="featuredbox"> <a href="<?=$gameurl;?>" title="Click to play <?=$mostpopulargametitle;?>" class="featured-1"><img src="<?=$gameicon;?>" width="180" height="130" alt="" /></a> <h3><?=$mostpopulargametitle;?></h3> <p> <?=$gamedescription;?> <br><?=$mostplayed;?> plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <?php if ($x ==8 || $x == 26) echo ""; } ?> PHP: <div id="featuredb-1" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Test-game-1" title="Click to play Test game 1" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Test game 1</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-2" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Test-game-1" title="Click to play Test game 1" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Test game 1</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-3" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Test-game-1" title="Click to play Test game 1" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Test game 1</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-4" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Test-game-1" title="Click to play Test game 1" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Test game 1</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-5" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Test-game-1" title="Click to play Test game 1" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Test game 1</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-1" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Santa" title="Click to play Santa" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Santa</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-2" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Santa" title="Click to play Santa" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Santa</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-3" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Santa" title="Click to play Santa" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Santa</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-4" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Santa" title="Click to play Santa" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Santa</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-5" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Santa" title="Click to play Santa" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Santa</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-1" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Frogee" title="Click to play Frogee" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Frogee</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-2" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Frogee" title="Click to play Frogee" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Frogee</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-3" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Frogee" title="Click to play Frogee" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Frogee</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-4" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Frogee" title="Click to play Frogee" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Frogee</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <div id="featuredb-5" class="featuredbox"> <a href="http://www2.skinzee.com/phpAS/games/Frogee" title="Click to play Frogee" class="featured-1"><img src="http://www2.skinzee.com/phpAS/games/images/Frogeee.jpg" width="180" height="130" alt="" /></a> <h3>Frogee</h3> <p> <br>0 plays </p> <a href="#" class="playnow">Play Now! »</a> </div> It`s displaying everything 3x times.. :/ And i dont know why... Exactly... I`m willing to pay please PM me or post here your requested amount and your IM so we can talk LIVE! Thanks
Hi, I found out that the reason it`s showing up that many times is because of this loop: for ($i=1; $i<=5; $i++) It shows 5x times more then it should.. Is it possible to rewrite it? Thanks!
All you need to do is simply return the query containing your top 5 games and loop them once using $x as the iterator to populate your div elements id's. You will want to ORDER BY "timesplayed" ASC so the loop starts with the most popular.
Hi, Sounds simple and easy, but i dont know PHP other then the basic. Could you please take the code rewrite it and give me to workin code i will pay you just PM me please? Thanks!
Give this a try Neo, I changed the query to order by timesplayed DESC and put a condition in the loop to only show the first 5 iterations. <?php function display_todaysmostpopular($base_url,$rewrite,$sedir) $sql_query = "SELECT * from games WHERE gamestatus = 1 ORDER BY timesplayed "; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { //output as long as there are still available fields $x=1; while($row = mysql_fetch_array($result)) { if($x <= 5) { $mostpopulargametitle = $row[gametitle]; $mostpopulargametitle = stripslashes($mostpopulargametitle); $mostpopulargameid = $row[gameid]; $mostpopulartimesplayed = $row[timesplayed]; $gamedescription = $row[$gamedesc]; $sepopular = str_replace (" ","-",$mostpopulargametitle); $sepopular= str_replace ("'","_",$sepopular); $mostpopularicon = $row[gameicon]; $iconlocation = $row[iconlocation]; $mostplayed = $row[playedtoday]; // If SE Friendly is turned OFF, this will be displayed if ($rewrite != 1) $gameurl = $base_url."index.php?action=playgame&gameid=".$mostpopulargameid; else $gameurl = $base_url.$sedir."/".$sepopular; if ($iconlocation ==1) $gameicon = $mostpopularicon; else $gameicon = $base_url."games/images/".$mostpopularicon; if ($x ==1 || $x == 9) echo ""; ?> <div id="featuredb-<?=$x?>" class="featuredbox"> <a href="<?=$gameurl;?>" title="Click to play <?=$mostpopulargametitle;?>" class="featured-1"><img src="<?=$gameicon;?>" width="180" height="130" alt="" /></a> <h3><?=$mostpopulargametitle;?></h3> <p> <?=$gamedescription;?> <br><?=$mostplayed;?> plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <?php if ($x ==8 || $x == 26) echo ""; }else break; $x++; } } } ?> Code (markup):
I have no way to test it but... function display_todaysmostpopular($base_url,$rewrite,$sedir){ ?> <? $x = 0; $sql_query = "SELECT * from games WHERE gamestatus = 1 ORDER BY playedtoday DESC LIMIT 24"; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { //output as long as there are still available fields ////////icfire edited here for ($i = 1; $i<=5; $i++) { $row = mysql_fetch_array($result); $x++; $mostpopulargametitle = $row[gametitle]; $mostpopulargametitle = stripslashes($mostpopulargametitle); $mostpopulargameid = $row[gameid]; $mostpopulartimesplayed = $row[timesplayed]; $gamedescription = $row[$gamedesc]; $sepopular = str_replace (" ","-",$mostpopulargametitle); $sepopular= str_replace ("'","_",$sepopular); $mostpopularicon = $row[gameicon]; $iconlocation = $row[iconlocation]; $mostplayed = $row[playedtoday]; // If SE Friendly is turned OFF, this will be displayed if ($rewrite != 1) $gameurl = $base_url."index.php?action=playgame&gameid=".$mostpopulargameid; else $gameurl = $base_url.$sedir."/".$sepopular; if ($iconlocation ==1) $gameicon = $mostpopularicon; else $gameicon = $base_url."games/images/".$mostpopularicon; ?> <?if ($x ==1 || $x == 9) echo "";?> <div id="featuredb-<?=$i?>" class="featuredbox"> <a href="<?=$gameurl;?>" title="Click to play <?=$mostpopulargametitle;?>" class="featured-1"><img src="<?=$gameicon;?>" width="180" height="130" alt="" /></a> <h3><?=$mostpopulargametitle;?></h3> <p> <?=$gamedescription;?> <br><?=$mostplayed;?> plays </p> <a href="#" class="playnow">Play Now! »</a> </div> <?if ($x ==8 || $x == 26) echo "";?> <? } } ?> <? } ?> Code (markup): Before it was saying keep going until every row is looped through now it says just do 5 Tell me if that works
Yours did`t work, just getting a blank page now for some reason i must have done something wrong problebly... If you want access to that folder to edit it your self please PM ME, and your price !
icefire this works perfectly! Thank you so much.. I really apprisiate it.. Could you help me out some more? Sending pm now...