seany123 Posted April 11, 2009 Share Posted April 11, 2009 okay i have a page which displays different members values once a _$POST has been recieved. <?php include("lib.php"); define("PAGENAME", "Hall Of Fame"); $player = check_user($secret_key, $db); $i = 1; include("templates/private_header.php"); ?> <style type="text/css"> <!-- body, td, th { color: #FFFFFF; } body { background-color: #000000; } a:link { color: #FF0000; } a:visited { color: #FF0000; } a:hover { color: #666666; } a:active { color: #FF0000; } .style5 {color: #FFFFFF} --> </style> <table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000"> <tr> <td align="center" class="style5"><strong>Hall Of Fame </strong></td> </tr> </table> <form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Select Value: <select name="value"> <option name="level" value="level">Level</option> <option name="money" value="money">Money</option> <option name="bank" value="bank">Bank</option> <option name="points" value="points">Points</option> <option name="strength" value="strength">Strength</option> <option name="defense" value="defense">Defense</option> <option name="speed" value="speed">Speed</option> <option name="total" value="total">Total</option> </select> Select City <select name="cityid"> <option name="all" value="all">All</option> <option name="London" value="1">London</option> <option name="Newyork" value="2">New york</option> <option name="Birmingham" value="3">Birmingham</option> <option name="Atlanta" value="4">Atlanta</option> <option name="Washington" value="5">washington</option> <option name="Tokyo" value="6">Tokyo</option> <option name="Moscow" value="7">Moscow</option> <option name="Berlin" value="8">Berlin</option> <option name="Madrid" value="9">Madrid</option> <option name="sydney" value="10">Sydney</option> <option name="Chicargo" value="11">Chicargo</option> <option name="Singapore" value="12">Singapore</option> <option name="Mexico city" value="13">Mexico city</option> <option name="Phoenix" value="14">Phoenix</option> <option name="Amsterdam" value="15">Amsterdam</option> <option name="Oslo" value="16">Oslo</option> <option name="Boston" value="17">Boston</option> <option name="HongKong" value="18">Hong Kong</option> <option name="LasVegas" value="19">Las Vegas</option> <option name="Austin" value="20">Austin</option> <option name="Miami" value="21">Miami</option> <option name="Dublin" value="22">Dublin</option> <option name="Oakland" value="23">Oakland</option> <option name="Milan" value="24">Milan</option> <option name="Istanbul" value="25">Istanbul</option> <option name="Toronto" value="26">Toronto</option> <option name="Rome" value="27">Rome</option> </select> <input type='submit' name='submit' value='Filter'></form> <table width="54%" border="0" align="left"> <tr> <th width="8%"> <th width="14%">Rank <th width="26%"><b>Username</b></td> <th width="16%"><strong>Level</strong> <th width="20%"><strong>Money</strong> <th width="16%">Status</tr> <?php // DISPLAYING ALL TABLES WHEN SHOWING (ALL) CITIES. if(isset($_POST['submit'])) { if ($_POST['cityid'] == "all" && $_POST['value'] == "level") { $query = $db->execute("select `id`, `username`, `level`, `money`, `last_active`, `banned`, `staff`, `rm`, `ncolor`, `city_id` from `players` order by `level` desc limit 50"); while($member = $query->fetchrow()) { echo "<td>"; echo "<td>" . number_format($i++) . "</td>\n"; echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">"; if ($member['banned'] >= 1) { echo "<b>[b] </b>"; echo "<STRIKE>" .$member['username']. "</STRIKE></td>"; } else if ($member['ncolor'] == 1) { echo "<font color=\"blue\">".$member['username']."</font>"; } else if($member['ncolor'] == 2) { echo "<font color=\"green\">".$member['username']."</font>"; } else if($member['ncolor'] == 3) { echo "<font color=\"yellow\">".$member['username']."</font>"; } else if($member['ncolor'] == 4) { echo "<font color=\"pink\">".$member['username']."</font>"; } else if($member['ncolor'] == 5) { echo "<font color=\"silver\">".$member['username']."</font>"; } else if($member['staff'] >= 1) { echo "<font color=\"gold\">".$member['username']."</font>"; } else if($member['rm'] >= 1) { echo "<font color=\"red\">".$member['username']."</font>"; } else { echo "<font color=\"\">".$member['username']."</font>"; } echo "<td>" . number_format($member['level']) . "</td>\n"; echo "<td>$" . number_format($member['money']) . "</td>\n"; if ($member['last_active'] >= Time()-1200) { echo "<td><font color=\"lime\">Online</font></td>"; } else { echo "<td><font color=\"red\">Offline</font></td>"; } echo "</tr>\n"; } } } if(isset($_POST['submit'])) { if ($_POST['cityid'] == "all" && $_POST['value'] == "money") { $query = $db->execute("select `id`, `username`, `level`, `money`, `last_active`, `banned`, `staff`, `rm`, `ncolor`, `city_id` from `players` order by `money` desc limit 50"); while($member = $query->fetchrow()) { echo "<td>"; echo "<td>" . number_format($i++) . "</td>\n"; echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">"; if ($member['banned'] >= 1) { echo "<b>[b] </b>"; echo "<STRIKE>" .$member['username']. "</STRIKE></td>"; } else if ($member['ncolor'] == 1) { echo "<font color=\"blue\">".$member['username']."</font>"; } else if($member['ncolor'] == 2) { echo "<font color=\"green\">".$member['username']."</font>"; } else if($member['ncolor'] == 3) { echo "<font color=\"yellow\">".$member['username']."</font>"; } else if($member['ncolor'] == 4) { echo "<font color=\"pink\">".$member['username']."</font>"; } else if($member['ncolor'] == 5) { echo "<font color=\"silver\">".$member['username']."</font>"; } else if($member['staff'] >= 1) { echo "<font color=\"gold\">".$member['username']."</font>"; } else if($member['rm'] >= 1) { echo "<font color=\"red\">".$member['username']."</font>"; } else { echo "<font color=\"\">".$member['username']."</font>"; } echo "<td>" . number_format($member['level']) . "</td>\n"; echo "<td>$" . number_format($member['money']) . "</td>\n"; if ($member['last_active'] >= Time()-1200) { echo "<td><font color=\"lime\">Online</font></td>"; } else { echo "<td><font color=\"red\">Offline</font></td>"; } echo "</tr>\n"; } } } if(isset($_POST['submit'])) { if ($_POST['cityid'] == "all" && $_POST['value'] == "bank") { $query = $db->execute("select `id`, `username`, `level`, `money`, `last_active`, `banned`, `staff`, `rm`, `ncolor`, `city_id` from `players` order by `bank` desc limit 50"); while($member = $query->fetchrow()) { echo "<td>"; echo "<td>" . number_format($i++) . "</td>\n"; echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">"; if ($member['banned'] >= 1) { echo "<b>[b] </b>"; echo "<STRIKE>" .$member['username']. "</STRIKE></td>"; } else if ($member['ncolor'] == 1) { echo "<font color=\"blue\">".$member['username']."</font>"; } else if($member['ncolor'] == 2) { echo "<font color=\"green\">".$member['username']."</font>"; } else if($member['ncolor'] == 3) { echo "<font color=\"yellow\">".$member['username']."</font>"; } else if($member['ncolor'] == 4) { echo "<font color=\"pink\">".$member['username']."</font>"; } else if($member['ncolor'] == 5) { echo "<font color=\"silver\">".$member['username']."</font>"; } else if($member['staff'] >= 1) { echo "<font color=\"gold\">".$member['username']."</font>"; } else if($member['rm'] >= 1) { echo "<font color=\"red\">".$member['username']."</font>"; } else { echo "<font color=\"\">".$member['username']."</font>"; } echo "<td>" . number_format($member['level']) . "</td>\n"; echo "<td>$" . number_format($member['money']) . "</td>\n"; if ($member['last_active'] >= Time()-1200) { echo "<td><font color=\"lime\">Online</font></td>"; } else { echo "<td><font color=\"red\">Offline</font></td>"; } echo "</tr>\n"; } } } if(isset($_POST['submit'])) { if ($_POST['cityid'] == "all" && $_POST['value'] == "points") { $query = $db->execute("select `id`, `username`, `level`, `money`, `last_active`, `banned`, `staff`, `rm`, `ncolor`, `city_id` from `players` order by `points` desc limit 50"); while($member = $query->fetchrow()) { echo "<td>"; echo "<td>" . number_format($i++) . "</td>\n"; echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">"; if ($member['banned'] >= 1) { echo "<b>[b] </b>"; echo "<STRIKE>" .$member['username']. "</STRIKE></td>"; } else if ($member['ncolor'] == 1) { echo "<font color=\"blue\">".$member['username']."</font>"; } else if($member['ncolor'] == 2) { echo "<font color=\"green\">".$member['username']."</font>"; } else if($member['ncolor'] == 3) { echo "<font color=\"yellow\">".$member['username']."</font>"; } else if($member['ncolor'] == 4) { echo "<font color=\"pink\">".$member['username']."</font>"; } else if($member['ncolor'] == 5) { echo "<font color=\"silver\">".$member['username']."</font>"; } else if($member['staff'] >= 1) { echo "<font color=\"gold\">".$member['username']."</font>"; } else if($member['rm'] >= 1) { echo "<font color=\"red\">".$member['username']."</font>"; } else { echo "<font color=\"\">".$member['username']."</font>"; } echo "<td>" . number_format($member['level']) . "</td>\n"; echo "<td>$" . number_format($member['money']) . "</td>\n"; if ($member['last_active'] >= Time()-1200) { echo "<td><font color=\"lime\">Online</font></td>"; } else { echo "<td><font color=\"red\">Offline</font></td>"; } echo "</tr>\n"; } } } my problem is when you first go to that page because nothing has been $_POST yet.. then the table is just empty... can anyone give me a hand? Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/ Share on other sites More sharing options...
waynew Posted April 11, 2009 Share Posted April 11, 2009 How about just redirecting it back if the relevant $_POST variables aren't found? Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807436 Share on other sites More sharing options...
.josh Posted April 11, 2009 Share Posted April 11, 2009 okay so I see a lot of conditions that involve seeing if $_POST['submit'] is set. So make a condition and run a query based off if it's not set. Maybe as a next step you can re-think your coding in general and figure out how to combine all that repetitive code... Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807439 Share on other sites More sharing options...
9three Posted April 11, 2009 Share Posted April 11, 2009 Create an else statement for the issset 'submit' and display whatever you want to display if no POST has been submitted. if (isset($_POST['submit']) { //Display your tables } else { //POST hasn't been used so display something else } Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807440 Share on other sites More sharing options...
seany123 Posted April 11, 2009 Author Share Posted April 11, 2009 doesnt that mean i have to use that after every $_POST? Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807449 Share on other sites More sharing options...
.josh Posted April 11, 2009 Share Posted April 11, 2009 no...you would just check if it's not set one time, and run a query and display something one time. Doesn't really matter where you put it, because it's either set or it's not. Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807452 Share on other sites More sharing options...
seany123 Posted April 11, 2009 Author Share Posted April 11, 2009 im sorry can you please explain that a little bit more? im slightly confused. Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807458 Share on other sites More sharing options...
.josh Posted April 11, 2009 Share Posted April 11, 2009 What is there to explain? You do the exact same thing you did with your other conditions, except for if(!isset($_POST['submit'])) { // query and display default stuff here } Do you not understand your own code? Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807474 Share on other sites More sharing options...
seany123 Posted April 11, 2009 Author Share Posted April 11, 2009 if(!isset($_POST['submit'])) { // query and display default stuff here } would display something AFTER they tried submitting... i want it to echo something before i have $_POST anything. Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807484 Share on other sites More sharing options...
.josh Posted April 11, 2009 Share Posted April 11, 2009 dude open your eyeballs. There's a ! before the isset. Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807486 Share on other sites More sharing options...
redarrow Posted April 11, 2009 Share Posted April 11, 2009 You also need to do css properly, it not worth having plain html and css that madness.. good luck. also look up heredoc. Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807494 Share on other sites More sharing options...
seany123 Posted April 11, 2009 Author Share Posted April 11, 2009 dude open your eyeballs. There's a ! before the isset. oh yeah didnt see that.. thankyou that has done exactly what i needed it to do! Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-807498 Share on other sites More sharing options...
blackRose18 Posted May 23, 2009 Share Posted May 23, 2009 The code was good to see and they function it more.I like the code they done. _________________ Crawl Space Dehumidifier Quote Link to comment https://forums.phpfreaks.com/topic/153659-solved-some-help-needed/#findComment-840495 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.