MistorClinky Posted August 23, 2017 Share Posted August 23, 2017 Hi Everyone I am working on a website for a school project that displays the rating for a game in the form of a star image. If the game has a rating of 3, 3 stars need to be displayed etc. The ratings are stored in a database on phpmyadmin. database = assessmenttable = gamescolumn = rating Each game has a gameID, there are 31 games on the table and looks like thishttp://imgur.com/a/6F74I This is how the code is looking for this particular part of the webpage. The new line of code will go underneath the <img src="images line. <div class="game"> <a class="cat" href="index.php?page=game&gameID=<?php echo $game_rs['gameID']; ?>"> <p><?php echo $game_rs['game']; ?></p> <p><?php echo $game_rs['developer']; ?></p> <img src="images/thumbnails/<?php echo $game_rs['thumbnail']; ?>"></img> </a> </div> I really appreciate any help anyone can offer Thankyou!!! Link to comment Share on other sites More sharing options...
Sepodati Posted August 23, 2017 Share Posted August 23, 2017 Use a "for" loop. Each time through the loop, output the code to display a star <img>. http://php.net/manual/en/control-structures.for.php Link to comment Share on other sites More sharing options...
ginerjm Posted August 23, 2017 Share Posted August 23, 2017 Read up on the "heredocs" operator while you're doing your research. It will make that html/php jumble of code a lot easier to write and to read later on. echo HEREDOCS <div class="game"> <a class="cat" href="index.php?page=game&gameID={$game_rs['gameID']}"> <p>{$game_rs['game']}</p> <p>{$game_rs['developer']}</p> <img src="images/thumbnails/{$game_rs['thumbnail'}"></img> </a> </div> HEREDOCS; Link to comment Share on other sites More sharing options...
mac_gyver Posted August 23, 2017 Share Posted August 23, 2017 the OP might also want to research an <img ...> tag. there is no closing </img> Link to comment Share on other sites More sharing options...
Psycho Posted August 23, 2017 Share Posted August 23, 2017 Instead of creating a loop, a more elegant approach might be to use the str_repeat() function. Create a variable to hold the content for a star image element and then just use str_repeat() with that variable and the rating number to create the correct output. So, somewhere before the loop to create the output for the records define the image $starImg = "<img src='images/star.jpg'>"; Then within the loop for the records, use a single line to create the correct number of images using the rating number from the query results echo str_repeat($starImg, $game_rs['rating_number']); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.