Jdog Posted January 11, 2013 Share Posted January 11, 2013 (edited) As thread title says, currently using this code to pull in listings from the "listings" table in the database <?PHP if ($_POST[limit] != $nil) $_SESSION['limit'] = $_POST['limit']; if ($_SESSION[limit] == $nil) $_SESSION['limit'] = 20; //--------------------------------------- ?> <?PHP include "bit_centerbar.php"; ?> <?php //------------------------- if (empty($rowxxx['SORT'])) $rowxxx['SORT'] = 'TITLE ASC'; else { if ($rowxxx['SORT'] == Alphabetically) $rowxxx['SORT'] = 'TITLE ASC'; if ($rowxxx['SORT'] == 'Date Added') $rowxxx['SORT'] = 'YA DESC, MA DESC, DA DESC, TITLE DESC'; if ($rowxxx['SORT'] == 'Date Updated') $rowxxx['SORT'] = 'YU DESC, MU DESC, DU DESC, TITLE ASC'; } if (empty($_GET[sortby])) $sort = $rowxxx['SORT']; $_GET[sortby] = "$sort"; $table = "LISTINGS"; $string = "WHERE STATUS = 'Active' AND CATEGORY LIKE '%-$_GET[category]-%'"; if (empty($_GET[category])) $string = "WHERE STATUS = 'Active'"; if ($_GET[category] == '') $string = "WHERE ID != ''"; $swap = "&page=$_GET &category=$_GET[category]"; //------------------------------------------------------------------------------------------- $query1 = @mysql_query ("SELECT * FROM $table INNER JOIN PACKAGES ON LISTINGS.PACKAGE = PACKAGES.ID $string $adv_search ORDER BY PACKAGES.RANK ASC, $_GET[sortby]"); //$query1 = @mysql_query ("SELECT * FROM $table $string $adv_search ORDER BY $_GET[sortby]"); $numrows= @mysql_num_rows ($query1); if (!isset ($_GET['show'])) { $display = 1; } else { $display = $_GET['show']; } $start = (($display * $_SESSION['limit']) - $_SESSION['limit']); $query2 = @mysql_query ("SELECT *, LISTINGS.ID AS LID FROM $table INNER JOIN PACKAGES ON LISTINGS.PACKAGE = PACKAGES.ID $string $adv_search ORDER BY PACKAGES.RANK ASC, $_GET[sortby] LIMIT $start,$_SESSION[limit]"); //$query2 = @mysql_query ("SELECT * FROM $table $string $adv_search ORDER BY $_GET[sortby] LIMIT $start,$_SESSION[limit]"); while ($row = @mysql_fetch_array ($query2)) { include "browse_display.php"; } //------------------------------------------------------------------------------------------- ?> <?php if ($numrows == '0') { ?> <div class="tdbox" style="width: 100%;"></div> <?php if (empty($_GET[category])) include 'bit_centerbar.php'; ?> <? echo $browse_no; ?> <?PHP } else { ?> <form action="?show=1&page=browse&category=<?php echo $_GET[category]; ?>&mode=<?php echo $_GET[mode]; ?>" method="post" name="form" id="form"> <div class="pagi" style="margin-top: 15px;"> <input type="submit" name="Submit" value="<? echo $browse_show; ?>" /> <select name="limit"> <option selected> <?php echo $_SESSION['limit']; ?> </option> <option>1</option> <option>5</option> <option>10</option> <option>20</option> <option>30</option> <option>50</option> <option>100</option> </select> <? echo $browse_lists; ?> <?php include "pagination_bot.php"; ?> </div> </form> <?PHP } ?> But now I am trying to find a way to display the results from particular states, i.e. Victoria, Queensland(this is from Australia). I am trying the following code, but currently getting the "no listings here, check back soon" message with no errors. I'm very new to PHP so not sure if I need to tweak the code to pull the results from the "LISTINGS" table, or the "LOCATIONS" <?PHP if ($_POST[limit] != $nil) $_SESSION['limit'] = $_POST['limit']; if ($_SESSION[limit] == $nil) $_SESSION['limit'] = 20; //--------------------------------------- ?> <?PHP include "bit_centerbar.php"; ?> <?php //------------------------- if (empty($rowxxx['SORT'])) $rowxxx['SORT'] = 'TITLE ASC'; else { if ($rowxxx['SORT'] == Alphabetically) $rowxxx['SORT'] = 'TITLE ASC'; if ($rowxxx['SORT'] == 'Date Added') $rowxxx['SORT'] = 'YA DESC, MA DESC, DA DESC, TITLE DESC'; if ($rowxxx['SORT'] == 'Date Updated') $rowxxx['SORT'] = 'YU DESC, MU DESC, DU DESC, TITLE ASC'; } if (empty($_GET[sortby])) $sort = $rowxxx['SORT']; $_GET[sortby] = "$sort"; $table = "LISTINGS"; $string = "WHERE STATUS = 'Active' AND CATEGORY LIKE '%-$_GET[sTATE]-%'"; if (empty($_GET[category])) $string = "WHERE STATUS = 'Active'"; if ($_GET[category] == '') $string = "WHERE ID != 'Queensland'"; $swap = "&page=$_GET &state=$_GET[state]"; //------------------------------------------------------------------------------------------- $query1 = @mysql_query ("SELECT * FROM $table INNER JOIN PACKAGES ON LISTINGS.PACKAGE = PACKAGES.ID $string $adv_search ORDER BY PACKAGES.RANK ASC, $_GET[sortby]"); //$query1 = @mysql_query ("SELECT * FROM $table $string $adv_search ORDER BY $_GET[sortby]"); $numrows= @mysql_num_rows ($query1); if (!isset ($_GET['show'])) { $display = 1; } else { $display = $_GET['show']; } $start = (($display * $_SESSION['limit']) - $_SESSION['limit']); $query2 = @mysql_query ("SELECT *, LISTINGS.ID AS LID FROM $table INNER JOIN PACKAGES ON LISTINGS.PACKAGE = PACKAGES.ID $string $adv_search ORDER BY PACKAGES.RANK ASC, $_GET[sortby] LIMIT $start,$_SESSION[limit]"); //$query2 = @mysql_query ("SELECT * FROM $table $string $adv_search ORDER BY $_GET[sortby] LIMIT $start,$_SESSION[limit]"); while ($row = @mysql_fetch_array ($query2)) { include "bwose_display.php"; } //------------------------------------------------------------------------------------------- ?> <?php if ($numrows == '0') { ?> <div class="tdbox" style="width: 100%;"></div> <?php if (empty($_GET[category])) include 'bit_centerbar.php'; ?> <? echo $browse_no; ?> <?PHP } else { ?> <form action="" method="post" name="form" id="form"> <div class="pagi" style="margin-top: 15px;"> <input type="submit" name="Submit" value="<? echo $browse_show; ?>" /> <select name="limit"> <option selected> <?php echo $_SESSION['limit']; ?> </option> <option>1</option> <option>5</option> <option>10</option> <option>20</option> <option>30</option> <option>50</option> <option>100</option> </select> <? echo $browse_lists; ?> <?php include "pagination_bot.php"; ?> </div> </form> <?PHP } ?> Edited January 11, 2013 by Jdog Quote Link to comment https://forums.phpfreaks.com/topic/273015-need-help-retrieving-results-from-certain-table/ Share on other sites More sharing options...
litebearer Posted January 11, 2013 Share Posted January 11, 2013 1. get rid of the @ error suppression 2. echo your variables and queries to determine they contain what you expect them to contain Quote Link to comment https://forums.phpfreaks.com/topic/273015-need-help-retrieving-results-from-certain-table/#findComment-1404977 Share on other sites More sharing options...
Jdog Posted January 12, 2013 Author Share Posted January 12, 2013 I removed the error suppression and it's still outputting all the results, not just the results from that designated state. Quote Link to comment https://forums.phpfreaks.com/topic/273015-need-help-retrieving-results-from-certain-table/#findComment-1405076 Share on other sites More sharing options...
Jessica Posted January 12, 2013 Share Posted January 12, 2013 See the link in my signature on debugging SQL. You need to check for errors. Quote Link to comment https://forums.phpfreaks.com/topic/273015-need-help-retrieving-results-from-certain-table/#findComment-1405078 Share on other sites More sharing options...
Jdog Posted January 12, 2013 Author Share Posted January 12, 2013 Thanks Jessica, I will have a look at that right now. Quote Link to comment https://forums.phpfreaks.com/topic/273015-need-help-retrieving-results-from-certain-table/#findComment-1405079 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.