kurtos123 Posted August 14, 2015 Share Posted August 14, 2015 I am displaying the top 10 games on my website but i want this list numbered from 1 to 10. How do i inplement this in my code ? Is it posible also the ad numbered images, and how do i do that? Here is my code so far: <?phpinclude "config.php";$rQuery = mysql_query("SELECT * FROM " . $pre . "$sqlgame WHERE cijfer / stemmen >= 10 ORDER BY views DESC LIMIT 10");while($aGame = mysql_fetch_assoc($rQuery)){ if($aGame['cijfer'] != 0 AND $aGame['stemmen'] != 0) { $cijfer = floor($aGame['cijfer'] / $aGame['stemmen']); } else { $cijfer = 0; } $sSpelNaam = str_replace(" ", "-",$aGame['name']); echo "<font color='#333333'>• <a href=\"http://www.crocgame.com/games.php/" . $sSpelNaam . ".html\" target='blank' onmouseover=\"ddrivetip('<img src=\'" . $aGame['screenshoturl'] . "\' width=\'170\' height=\'140\' alt=\'" . $aGame['name'] . "\'><br /><b>" . $aGame['name'] . "</b>');\" onmouseout='hideddrivetip();'>" . $aGame['name'] . " " . $aGame['extra'] . "</a></font><br />" . PHP_EOL; }?> Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/ Share on other sites More sharing options...
Ch0cu3r Posted August 14, 2015 Share Posted August 14, 2015 On way would be to use counter // initiate counter $i = 0; while($aGame = mysql_fetch_assoc($rQuery) { if($aGame['cijfer'] != 0 AND $aGame['stemmen'] != 0) { $cijfer = floor($aGame['cijfer'] / $aGame['stemmen']); } else { $cijfer = 0; } $sSpelNaam = str_replace(" ", "-",$aGame['name']); // increment counter by one $i++; // output counter echo "$i. <font color='#333333'>• <a href=\"http://www.crocgame.com/games.php/" . $sSpelNaam . ".html\" target='blank' onmouseover=\"ddrivetip('<img src=\'" . $aGame['screenshoturl'] . "\' width=\'170\' height=\'140\' alt=\'" . $aGame['name'] . "\'><br /><b>" . $aGame['name'] . "</b>');\" onmouseout='hideddrivetip();'>" . $aGame['name'] . " " . $aGame['extra'] . "</a></font><br />" . PHP_EOL; } The code will increment $i by one each time a row is outputted in the while loop Or you could output the results in a HTML ordered list Is it posible also the ad numbered images, and how do i do that? Yes, depending on how have named your images, I assume you have named like 1.png, 2.png etc, you can change echo "$i. in my example code above to to be echo "<img src=\"$i.png\" /> Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518766 Share on other sites More sharing options...
kurtos123 Posted August 14, 2015 Author Share Posted August 14, 2015 Updated my browser and got error message Parse error: syntax error, unexpected '{' in /home/crocgame/domains/crocgame.com/public_html/beste_games1.php on line 7 I am bad in php so please help me further... Many thanks for help! <?phpinclude "config.php";// initiate counter$i = 0;while($aGame = mysql_fetch_assoc($rQuery){ if($aGame['cijfer'] != 0 AND $aGame['stemmen'] != 0) { $cijfer = floor($aGame['cijfer'] / $aGame['stemmen']); } else { $cijfer = 0; } $sSpelNaam = str_replace(" ", "-",$aGame['name']); // increment counter by one $i++; // output counter echo "$i. <font color='#333333'>• <a href=\"http://www.crocgame.com/games.php/" . $sSpelNaam . ".html\" target='blank' onmouseover=\"ddrivetip('<img src=\'" . $aGame['screenshoturl'] . "\' width=\'170\' height=\'140\' alt=\'" . $aGame['name'] . "\'><br /><b>" . $aGame['name'] . "</b>');\" onmouseout='hideddrivetip();'>" . $aGame['name'] . " " . $aGame['extra'] . "</a></font><br />" . PHP_EOL; }?> Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518767 Share on other sites More sharing options...
Barand Posted August 14, 2015 Share Posted August 14, 2015 Missing a closing ) at the end of line 6 Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518769 Share on other sites More sharing options...
kurtos123 Posted August 14, 2015 Author Share Posted August 14, 2015 where is line 6 exactly and with closing you mean this "}" ? Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518770 Share on other sites More sharing options...
Barand Posted August 14, 2015 Share Posted August 14, 2015 You will find line 6 immediately before line 7, and by "closing )" i mean ) while($aGame = mysql_fetch_assoc($rQuery) ) ^ | this is missing Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518772 Share on other sites More sharing options...
kurtos123 Posted August 14, 2015 Author Share Posted August 14, 2015 Get a mysql error on line 6 with: while($aGame = mysql_fetch_assoc($rQuery) ) now: Mysql_fetch _assoc():supplied argument is not a valid MySQL result resource in /home/crocgame/domains/crocgame.com/public_html/beste_games1.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518774 Share on other sites More sharing options...
kurtos123 Posted August 14, 2015 Author Share Posted August 14, 2015 i agree in code of moderator Ch0cu3r " )" on line 6 was missing but something more but be wrong .... Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518775 Share on other sites More sharing options...
kurtos123 Posted August 14, 2015 Author Share Posted August 14, 2015 Code so far: <?phpinclude "config.php";// initiate counter$i = 0;$rQuery = mysql_query("SELECT * FROM " . $pre . "$sqlgame WHERE cijfer / stemmen >= 10 ORDER BY views DESC LIMIT 10");while($aGame = mysql_fetch_assoc($rQuery)) if($aGame['cijfer'] != 0 AND $aGame['stemmen'] != 0) { $cijfer = floor($aGame['cijfer'] / $aGame['stemmen']); } else { $cijfer = 0; } $sSpelNaam = str_replace(" ", "-",$aGame['name']); // increment counter by one $i++; // output counter echo "$i.<font color='#333333'>• <a href=\"http://www.crocgame.com/games.php/" . $sSpelNaam . ".html\" target='blank' onmouseover=\"ddrivetip('<img src=\'" . $aGame['screenshoturl'] . "\' width=\'170\' height=\'140\' alt=\'" . $aGame['name'] . "\'><br /><b>" . $aGame['name'] . "</b>');\" onmouseout='hideddrivetip();'>" . $aGame['name'] . " " . $aGame['extra'] . "</a></font><br />" . PHP_EOL; }?> STill not working with above code get mysql error: Parse error: syntax error, unexpected '}' in/home/crocgame/domains/crocgame.com/public_html/beste_games1.phpon line 23 Please help ! Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518777 Share on other sites More sharing options...
Ch0cu3r Posted August 14, 2015 Share Posted August 14, 2015 There should be a { after the while loop statement on line 6 while($aGame = mysql_fetch_assoc($rQuery)) { // <--- this is missing Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518779 Share on other sites More sharing options...
kurtos123 Posted August 14, 2015 Author Share Posted August 14, 2015 Everybody thanks for great help, it works now !!!! Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518781 Share on other sites More sharing options...
kurtos123 Posted August 14, 2015 Author Share Posted August 14, 2015 small detail don't now it can be solved the list is printed like this (watch position number 10 under 9): 1 2 .. 9 10 Possible to print like this: 1 .. 9 10 Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518783 Share on other sites More sharing options...
Ch0cu3r Posted August 14, 2015 Share Posted August 14, 2015 Could use either str_pad, sprintf or use a condition if $i less than 10 to prefix $i with a space See if you can implement either of the 3 options above into your code. NOTE: You may need to use rather than the actual space character. As web browsers tend to ignore (white)space characters. Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518784 Share on other sites More sharing options...
kurtos123 Posted August 14, 2015 Author Share Posted August 14, 2015 topic can be closed thanks for great help again ! Quote Link to comment https://forums.phpfreaks.com/topic/297778-numbered-list-in-php/#findComment-1518790 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.