Arbitus Posted February 18, 2009 Share Posted February 18, 2009 So I'm creating a cheat code website. I have a table for each system x360 ps3 wii I want to be able to insert rows into each one that has individual cheats in per game. So say Halo has 10 codes, there would be 10 seperate rows for halo. Well this is all fine and dandy untill I try to make a page that displays the games. like so: <?php while($rows = mysql_fetch_array($query)) { ?> <center> <br> <a href="/game.php?system=<?php echo $system; ?>&game=<?php echo $rows['game_name']; ?>&id=<?php echo $rows['ID']; ?>"><?php echo $rows['game_name']; ?></a> </center> <?php } ?> When I do this, it displays each one seperatly so since i have 10 halo codes, it shows halo 10 times. So I guess what I'm trying to ask is if I can limit halo to be shown only one time on that page. Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted February 18, 2009 Share Posted February 18, 2009 If you only want ONE output, just put a LIMIT on your query. LIMIT 1; Quote Link to comment Share on other sites More sharing options...
Arbitus Posted February 18, 2009 Author Share Posted February 18, 2009 Well the problem is that if I limit to 1, it will not show all of the games. On this page it will have something like this: Call of duty 4 Call of duty WOW Halo But right now it looks like this: Call of duty 4 Call of duty 4 Call of duty 4 Call of duty 4 Call of duty WOW Call of duty WOW Halo Halo Halo Halo Halo Since there are rows for each cheat. Quote Link to comment Share on other sites More sharing options...
Maq Posted February 18, 2009 Share Posted February 18, 2009 There's probably a much easier way to do this but my head hurts from work: $halo_count = 0; while($rows = mysql_fetch_array($query)) { if($rows['game_name'] == 'halo') { $count++; } if($count > 1 && $rows['game_name'] == 'halo') { break; } else { ?> } } ?> Quote Link to comment Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 Well show us the query and maybe we can help you. You have multiple items in your DB with the same game name thus you get the duplicate name listings. Quote Link to comment Share on other sites More sharing options...
Arbitus Posted February 18, 2009 Author Share Posted February 18, 2009 There's probably a much easier way to do this but my head hurts from work: <?php $halo_count = 0; while($rows = mysql_fetch_array($query)) { if($rows['game_name'] == 'halo') { $count++; } if($count > 1 && $rows['game_name'] == 'halo') { break; } else { ?> <center> <br> <a href="/game.php?system=<?php echo $system; ?>&game=<?php echo $rows['game_name']; ?>&id=<?php echo $rows['ID']; ?>"><?php echo $rows['game_name']; ?></a> </center> <?php } } ?> The only problem with this is that there will be more than just halo. If you look here: http://arbituz.com/cheat.php?system=x360 You will see what I'm saying. I would prefer to have each code to have it's own row to make user submissions to be easier. But everytime I add a new code, it shows the game name multiple times on the game list page. Quote Link to comment Share on other sites More sharing options...
5kyy8lu3 Posted February 18, 2009 Share Posted February 18, 2009 couldn't you use UNIQUE or DISTINCT? Quote Link to comment Share on other sites More sharing options...
Arbitus Posted February 18, 2009 Author Share Posted February 18, 2009 Ok, so I guess I found a solution. I added a new field called 'new' the the rows. if a code for a game that has never been entered is submited. it gets a 1 in new. other than that it has a 0. Then I made it so on the game list it only selects games with a 1 in new. Thanks for all your help. This is probably a hillbilly solution but if you can think of better either send me an email admin@arbituz.com or leave me a message here. Thanks agian! Quote Link to comment Share on other sites More sharing options...
Arbitus Posted February 18, 2009 Author Share Posted February 18, 2009 couldn't you use UNIQUE or DISTINCT? how would i use those? Quote Link to comment Share on other sites More sharing options...
Maq Posted February 19, 2009 Share Posted February 19, 2009 Ok, so I guess I found a solution. I added a new field called 'new' the the rows. if a code for a game that has never been entered is submited. it gets a 1 in new. other than that it has a 0. Then I made it so on the game list it only selects games with a 1 in new. Thanks for all your help. This is probably a hillbilly solution but if you can think of better either send me an email admin@arbituz.com or leave me a message here. Thanks agian! I think you're fine with that solution, the 0 and 1 "boolean" method is a common practice. Although I'm still confused as to what exactly you're trying to accomplish, so I cannot confirm this is a permanent solution. Sorry :-\ Quote Link to comment 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.