cdoyle Posted October 19, 2008 Share Posted October 19, 2008 Hi, This something I've had trouble with when making pages, and was hoping someone can give some advice I am working on a new page for my game, where users can post and sell items. One problem I'm running into is the page loads and you can select a market you would like to enter, when you click on a category I want the page to reload and show the items from that category. But what is happening is the page reloads with the listings, but the market categories still appear under the table of items. You can see what I mean here. http://www.caraudiocentral.net/CAC_Mafia_Test_Site/marketnew.php What do I need to do to make it not show the categories under the listings. Here is my code include("lib.php"); define("PAGENAME", "CAC Public Market"); $player = check_user($secret_key, $db); $getcategories =$db->execute("SELECT `Weapon_Type`, `ID` FROM weapon_type"); include("templates/private_header.php"); if ($_GET['act'] == "cat" ) { $viewmarket = $db->execute("SELECT c.market_ID as mID, c.Item_Sold_ID, c.Seller_ID, c.Price, c.days_left, p.username, p.id as pid, b.id as wid, b.name as wname, b.type as wtype FROM market_new c INNER JOIN players p ON c.Seller_ID = p.id INNER JOIN blueprint_items b ON c.Item_Sold_ID = b.id Where b.type=?", array($_GET['catid'])); if ($viewmarket->recordcount() == 0) { echo "Sorry, No items for sale in this Market "; } else { echo "<table width=\"100%\" border=\"1\">"; echo "<tr align=\"center\">"; echo "<td><h3>Item</h3></td>"; echo "<td><h3>Seller</h3></td>"; echo "<td><h3>Cost</h3></td>"; echo "<td><h3>Days Left</h3></td>"; echo "<td><h3>Purchase</h3></td>"; while ($marketview = $viewmarket->fetchrow()) { echo "<tr>"; echo "<td>" . $marketview['wname'] . "</td>"; echo "<td>" . $marketview['username'] . "</td>"; echo "<td>" . $marketview['Price'] . "</td>"; echo "<td></td>"; echo "<td><a href=\"marketnew.php?act=buy&buyid=" . $marketview['mID'] . "\">Buy</a><br /></td>"; echo "</tr>"; } echo "</table>"; } } if ($_GET['act'] == "buy") { if ($player->id == $marketview['Seller_ID']) { echo "You can't buy your own items dummy<p>"; echo "<a href=\"home.php\">Home</a>\n"; } } else { echo "Please Select a Market to search"; echo "<table width=\"100%\" border=\"1\">"; echo "<tr>"; while ($categories = $getcategories->fetchrow()) { echo "<td>"; echo "<a href=\"marketnew.php?act=cat&catid=" . $categories['ID'] . "\">" . $categories['Weapon_Type'] . "</a><br />"; echo "</td>"; echo "</tr>"; } echo "</table>"; } include("templates/private_footer.php"); ?> Another question I have too, what is the correct way to validate that the $_Get's are not something it shouldn't be? I've been searching and see so many ways of doing different checks but not really sure which one is correct, or which ones are really needed Link to comment https://forums.phpfreaks.com/topic/129104-php-page-construction/ Share on other sites More sharing options...
cdoyle Posted October 20, 2008 Author Share Posted October 20, 2008 Does anyone know what I need to do, to make the page display correctly? Link to comment https://forums.phpfreaks.com/topic/129104-php-page-construction/#findComment-669967 Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 You need an elseif: <?php if ($_GET['act'] == "cat" ) { ... } if ($_GET['act'] == "buy") { ... } else { ... } ?> should be <?php if ($_GET['act'] == "cat" ) { ... } elseif ($_GET['act'] == "buy") { ... } else { ... } ?> Link to comment https://forums.phpfreaks.com/topic/129104-php-page-construction/#findComment-669973 Share on other sites More sharing options...
Acs Posted October 20, 2008 Share Posted October 20, 2008 In the 'cat' part there is a <tr> that you are not closing, it's the first one. In else while you are echoing one <tr> and inside you echo I don't know how many </tr>'s (depends on what the $getcategories->fetchrow() returns you) Check does and maybe you'll have your problem fixed Link to comment https://forums.phpfreaks.com/topic/129104-php-page-construction/#findComment-669979 Share on other sites More sharing options...
cdoyle Posted October 24, 2008 Author Share Posted October 24, 2008 You need an elseif: <?php if ($_GET['act'] == "cat" ) { ... } if ($_GET['act'] == "buy") { ... } else { ... } ?> should be <?php if ($_GET['act'] == "cat" ) { ... } elseif ($_GET['act'] == "buy") { ... } else { ... } ?> thank you, that worked! With my $_Gets how should I validate those to make sure they are numbers and nothing else? I keep finding so many different methods, but I just want to know what others use? Link to comment https://forums.phpfreaks.com/topic/129104-php-page-construction/#findComment-674098 Share on other sites More sharing options...
rhodesa Posted October 24, 2008 Share Posted October 24, 2008 use is_numeric() in an if statement Link to comment https://forums.phpfreaks.com/topic/129104-php-page-construction/#findComment-674103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.