Jump to content

Gotharious

Members
  • Posts

    159
  • Joined

  • Last visited

Everything posted by Gotharious

  1. then I believe this is what's causing the error $sql = "select * from hotels where city_id =(select id from cities where name = '$where') or country_id =(select id from countries where name = '$where')";
  2. Ok here is the whole queries, mate Hotel.php <?php include("includes/hotelsManager.php"); $hotelObj = new hotelManager(); $where = isset($_POST['where']) ? $_POST['where'] : ""; if(isset($_POST['where'])) { $hotelObj -> getHotel($where); $per_page = 9; //Calculating no of pages $sql = "select * from hotels where city_id = (select id from cities where name = '$where' ) or country_id = (select id from countries where name = '$where' )"; $result = MYSQL_QUERY($sql) or die("<br />No Hotels found in this city, please check the city name and try again"); $count = mysql_num_rows($result); $pages = ceil($count/$per_page) ?> <div id="loading" ></div> <div id="maincontent" ></div> <ul id="pagination"> <?php //Pagination Numbers for($i=1; $i<=$pages; $i++) { echo '<li class="paging" id="'.$i.'">'.$i.'</li>'; } ?> hotelsManager.php class hotelManager { public function getHotel($where) { $where = isset($_POST['where']) ? $_POST['where'] : ""; $dbObj = new DB(); $where = $_POST['where']; $sql = "select * from hotels where city_id =(select id from cities where name = '$where') or country_id =(select id from countries where name = '$where')"; $result = mysql_query($sql); $arr = array(); echo "<table>"; while($row = mysql_fetch_array($result) or die(mysql_error())) { echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\">"; echo "<table> <tr> <td valign=\"top\"> <a href=\"hotels.php?id=".$row['id']."\" class=\"titleslink\">".$row['name']."</a> </td> </tr> <tr> <td class=\"text\" valign=\"top\"> ".$row['location']." </td> </tr> </table>"; echo "</td>"; echo "</tr>"; } echo "</table>"; paginate_hotels.php <?php include('config.php'); include('textManager.php'); $per_page = 9; if($_GET) { $page=$_GET['page']; } $where = isset($_POST['where']) ? $_POST['where'] : ""; $datein = isset($_POST['indate']) ? $_POST['indate'] : ""; $dateoout = isset($_POST['dateout']) ? $_POST['dateout'] : ""; $notspecified = isset($_POST['notspecified']) ? $_POST['notspecified'] : ""; $groupwithchildren = isset($_POST['groupwithchildren']) ? $_POST['groupwithchildren'] : ""; $start = ($page-1)*$per_page; $sql = "select * from hotels where city_name = '$where' or country_name like (select id from cities where name = '$where' or name like '$where') order by id limit $start,$per_page"; $result = mysql_query($sql); ?> <table width="100%"> <?php while($row = mysql_fetch_array($result)) or die(mysql_error()) { echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\" width=\"400px\">"; echo "<table> <tr> <td valign=\"top\" class=subtitle4> <strong>".$row['name']."</strong> </td> </tr> <tr> <td class=\"text2\" valign=\"top\"> ".$row['location']." </td> </tr> <tr> <td class=text>"; echo (($row['details'] != "") ? textManager::substrTopic($row['details'],300) : "No details"); echo "<a href=\"hotels.php?id=".$row['id']."\" class=\"titleslink2\"> See More..</a>"; echo "</td> </tr> </table>"; echo "</td>"; echo "<td valign=\"bottom\" align=right>"; echo "<a href=\"hotels.php?id=".$row['id']."\" class=\"seemore\">Book Now</a>"; echo "</td>"; echo "</tr>"; echo "<tr><td colspan=\"3\" height=30px align=center><div class=hrdecoration></div></td></tr>"; } ?>
  3. ok, I made or die(sql_error)) and that's what it showed Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in *********hotelsManager.php on line 22 Unknown column 'france' in 'where clause'
  4. but still if I replaced it with = it would give the same result or should I replace it with something else?
  5. SpiderWell, I did as you said echo $sql and here is the result i've got select * from 'hotels' where city_id like (select id from cities where name like 'france' or country_id like ( select id from countries where name like 'france' ) select * from hotels where city_id = (select id from cities where name = 'france' ) or country_id = (select id from countries where name = 'france' )select * from hotels where city_id = (select id from cities where name = 'france' ) or country_id = (select id from countries where name = 'france' )select * from hotels where city_id = (select id from cities where name = 'france' ) or country_id = (select id from countries where name = 'france' )select * from hotels where city_id = (select id from cities where name = 'france' ) or country_id = (select id from countries where name = 'france' )select * from hotels where city_id = (select id from cities where name = 'france' ) or country_id = (select id from countries where name = 'france' )
  6. Mgoodman, I removed the includes and pagination code and instead I typed <?php echo $where; ?> and it showed the same input I put in the search form I typed france and the result came out as france
  7. Thanks Spiderwell and mgoodman, I will try to explain it again for you Spiderwell, for example if the table hotels has 1000 hotel, and only 50 hotels located in france and I set the paginating that only 10 results appear per page the user input is france, so I get 50 results ordered alphabetically that some is in france and some isn't, and I also get them no matter what city or country I type, but in the same time, I only get 5 pages as for 50 results, and if I type thailand, which has 200 in the list, then I get 200 hotel from different cities and countries, but only 20 pages with 200 result so it's more of the calculation or count of hotels is right, it just brings out the wrong hotels Mgoodman, thanks alot for your advice, will do that real_escape I'm sorry to ask this, but what do you mean by echo $where? Hope you guys would pardon me, English isn't my first language, so it's sometimes hard to understand or explain what i want and yes SpiderWell, I'm a total noob in this, but unfortunately I'm in a situation that I have to get this fixed tonight :/
  8. Hello everyone, I'm having this problem which is really annoying, tried to solve it but couldn't, I write that code in PHPMyAdmin and it works great, but it doesn't work in the website it self ok long story short, there are three tables, hotels, cities, countries hotels include in addition to hotel info, 2 columns (city_id) and (country_id) Cities include id and name and also countries include id and name what I was trying to do, that when a person inputs a city or country name in the search form, it should get the hotels that exists in this city or country, but unfortunately it shows all the hotels in all cities and countries, although the pagination code for number of pages works just fine, it count the number of hotels in that city or country and show the number of pages correctly so here is the code for both for hotel search class hotelManager { public function getHotel($where) { $where = isset($_POST['where']) ? $_POST['where'] : ""; $dbObj = new DB(); $sql = "select * from hotels where city_id = (select id from cities where name = '$where' ) or country_id = (select id from countries where name = '$where' )"; $result = MYSQL_QUERY($sql); $arr = array(); echo "<table>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\">"; echo "<table> <tr> <td valign=\"top\"> <a href=\"hotels.php?id=".$row['id']."\" class=\"titleslink\">".$row['name']."</a> </td> </tr> <tr> <td class=\"text\" valign=\"top\"> ".$row['location']." </td> </tr> </table>"; echo "</td>"; echo "</tr>"; } echo "</table>"; for hotel pagination <?php include("includes/hotelsManager.php"); $hotelObj = new hotelManager(); $where = isset($_POST['where']) ? $_POST['where'] : ""; if(isset($_POST['where'])) { $hotelObj -> getHotel($where); $per_page = 9; //Calculating no of pages $sql = "select * from hotels where city_id = (select id from cities where name = '$where' ) or country_id = (select id from countries where name = '$where' )"; $result = MYSQL_QUERY($sql) or die("<br />No Hotels found in this city, please check the city name and try again"); $count = mysql_num_rows($result); $pages = ceil($count/$per_page) ?> <div id="loading" ></div> <div id="maincontent" ></div> <ul id="pagination"> thank you in advance
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.