
chrispos
Members-
Posts
47 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
chrispos's Achievements

Member (2/5)
0
Reputation
-
This is now resolved by using a different approach the code is as follows should it be of interest include 'config.php'; include 'date.class.php'; $start = new Date(false ,$d, $m, $y); $end = new Date(false ,$d1, $m1, $y1); $query = "SELECT * FROM `hotel`ORDER BY RAND()"; $result = mysql_query ($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) if (mysql_num_rows($result)>0){ $hid = $row['hid']; $result1 = mysql_query ("SELECT * FROM rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"); $num_rows = mysql_num_rows($result1); echo $row['name']."<br>"; echo $row['hid']."<br>"; echo "$num_rows Rows<br><br>"; } mysql_free_result ($result); // Free up the resources. mysql_close(); Thank you for looking and helping
-
The hotel names are coming up fine. Thank you I have tried it but no it does not work. I think I am going to have to try a different way
-
The reason I am trying to include a page is because it started out as an SQL issue but I had an issue with that. The code I used is below include 'config.php'; include 'date.class.php'; $start = new Date(false ,$d, $m, $y); $end = new Date(false ,$d1, $m1, $y1); $query = "SELECT * FROM `hotel`ORDER BY RAND()"; $result = mysql_query ($query); // Run the query. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <h2>' . $row['name'] . '</h2> '; } ; $result = mysql_query ("SELECT * FROM rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"); $num_rows = mysql_num_rows($result); echo "$num_rows Rows\n"; mysql_free_result ($result); // Free up the resources. mysql_close(); d m y and d1 m1 y1 are start dates and end dates and what happens when the form is posted is it comes up with the hotel name as it should but it does not come up with the number of rows for each hotel. I had better explain this more so you get the picture. Three tables hotel rooms and bookings. Hotel has hid as do the rooms and bookings tables. (Hotel I D) Rooms have room id and booking have booking id. The rows show but only for one hotel so that tells me that the hotel id is not being picked up on the count query so if anyone has any ideas there that could be the answer to the question but as much as I have tried i am stumped.
-
If I explain exactly then this might help and by the way thanks for your help it is great OK when I am including the config.php page (database connection I am using include 'config.php'; The hotels pages are stored in the same directory so I am using the code above include 'config.php'; $query = "SELECT * FROM `hotel`ORDER BY RAND()"; $result = mysql_query ($query); // Run the query. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <h2>' . $row['name'] . '</h2> <p>'. include $row['page'].'</p> '; } ; mysql_free_result ($result); // Free up the resources. mysql_close(); I have set up a page to test if the pages are shown just by putting in include page etc and that works so it is not a directory issue. I tried the code as you wrote it and in theory it should work. I have set them up to show images and links in the past but it does not want to include the pages very strange. In the database I am storing the include pages as 'dhot.php'
-
Tried these but still it will not show the pages very strange to be honest
-
Hi All Thanks for looking. I am trying to include individual pages to appear on a page with each page name in a database. When I put the include page it shows it exact but what I would like to do is have the pages included in the main page. Here is the code i have used include 'config.php'; $query = "SELECT * FROM `hotel`ORDER BY RAND()"; $result = mysql_query ($query); // Run the query. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <h2>' . $row['name'] . '</h2> <p> '. $row['page'] . '</p> '; } ; mysql_free_result ($result); // Free up the resources. mysql_close(); row page being each subjects individual page. Thanks for looking
-
Thanks for taking a look OK I don't think I explained this very well but here goes for round two. If you go into say booking.com or laterooms.com you have the option of selecting the dates for your holiday then it brings up hotels with the rooms that they have full or empty. The script above just shows rooms available and works fine. What i am trying to do is get each hotel to show with available rooms. As I have said the script above works fine no problems with showing available rooms. It is the bit of showing the Hotel name and under that the available rooms. This is the script for the hotel search and i have included the PHP as I think it will make more sense <?php include_once 'config.php'; $display = 20; // Determine how many pages there are. if (isset($_GET['np'])) { // Already been determined. $num_pages = $_GET['np']; } else { // Need to determine. // Count the number of records $query = "SELECT COUNT(*) FROM `hotels`"; $result = mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; // Calculate the number of pages. if ($num_records > $display) { // More than 1 page. $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } // End of np IF. // Determine where in the database to start returning results. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Make the query. $query = "SELECT * FROM `hotels`ORDER BY RAND() LIMIT $start, $display"; $result = mysql_query ($query); // Run the query. // Table header. echo '<table align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><p class="text1"><b>Image</b></p></td> <td align="left"><p class="text1"><b>Name</b></p></td> <td align="left"><p class="text1"><b>Description</b></p></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $bg = ($bg=='#CCCCCC' ? '#9B9B9B' : '#CCCCCC'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left"><img src="' . $row['image'] . '"></td> <td align="left"><p class="text1"><b>' . $row['name'] . '</b></p></td> <td align="left"><p class="text1">' . $row['facilities'] . '</p></td> </tr> '; } echo '</table>'; mysql_free_result ($result); // Free up the resources. mysql_close(); // Close the database connection. // Make the links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="index.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="index.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="index.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>'; } echo '</p>'; } // End of links section. ?> This is a pagination script and the hotels come out in a random order. But what I would like to do is as the Hotel name comes out show the available rooms by using the first script. hid is the hotel id and rid is the room id. There is a php script called date class and works by posting arrival day date month departure day date month. As you have asked to see the full script for the room search here it is include 'config.php'; include 'date.class.php'; $start = new Date(false ,$d, $m, $y); $end = new Date(false ,$d1, $m1, $y1); $query = "SELECT * FROM rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"; $result = mysql_query($query) or die (mysql_error()); if (mysql_num_rows($result)>0){ while ($row = mysql_fetch_assoc($result)) { $prices = array(); $q = "SELECT * FROM price WHERE (hid = '$hid') AND rid = ".$row['rid']." AND ((year = $y) OR (year = $y1))"; $r1 = mysql_query($q) or die (mysql_error()); while ($rowa = mysql_fetch_assoc($r1)) { $prices[$rowa['year'].$rowa['month']] = $rowa['price']; } $days = $start->daysToPay($end); $total = 0; foreach($days as $d=>$t){ //$w = str_split($d, 4); //echo $w[0].' '.$w[1].' '.$t.'<br>'; $total = $total + ($t * $prices[$d]); } $ridr=$row['rid']; $hid=$row['hid']; $number=$row['number']; $description=$row['description']; $sleeps=$row['sleeps']; $booking ='<form id="form1" name="form1" method="post" action="/checktobook1b.php"> <input name="stdate" type="hidden" id="stdate" value="' . $stdate . '" /> <input name="dpdate" type="hidden" id="dpdate" value="' . $dpdate . '" /> <input name="ridr" type="hidden" id="id" value="' . $ridr . '" /> <input name="hid" type="hidden" id="hid" value="' . $hid . '" /> <input name="number" type="hidden" id="number" value="' . $number . '" /> <input name="total" type="hidden" id="total" value="' . $total . '" /> <input name="startdate" type="hidden" id="startdate" value="' . $start->getTime() . '" /> <input name="enddate" type="hidden" id="enddate" value="' . $end->getTime() . '" />'; $booking1 = '<label> <input type="submit" name="Submit" value="Book This Room" /> </label> </form>'; echo "$booking"; echo'Room Number'."\n\n"."$number<br>"; echo "$description<br>"; echo'The Price Is GBP'."\n\n".'£'."\n"."$total<br>"; echo "$booking1<br><br>"; } } } ?> d m y are day month year sorry if that sounds silly but you never know. Any help would be goo but if not thanks for looking
-
Hi All hope you are all having a good day. I am building a hotel booking site and it shows only rooms that are available. All this works fine and the tables are set up in such a way. The hotel name and description are in one table with hid identifying each hotel. I then have a table for rooms in each hotel with hid used to link the rooms with each hotel. I have another table called bookings and when someone books a room it goes in there. So when someone runs a query only available rooms show up. What I would like to do is show all the hotels, each hotel name and then the available rooms in that hotel. I am using MySQL 5 and PHP 5 This is the query that works to show the available rooms $query = "SELECT * FROM rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"; rid is in the rooms table and is used to identify what room is what.
-
I am using php 5 and I am having issues with cookies. I have looked at the help pages here but still stuck. A site had been hacked via a database and I am making it more secure with the use of session control ip address and cookies. The issue is this I need to run a database query to test if the two cookies set match that with the data in the database. I am using the following code in the head section. <?php session_start(); $session = session_id(); $ip = $_SERVER['REMOTE_ADDR']; $user = stripslashes(trim($_POST['user'])); $pass = stripslashes(trim($_POST['pass'])); $username="$user"; $encrypt_user=md5($username); $password="$pass"; $encrypt_password=md5($password); include 'config.php'; $query = "SELECT * FROM `users`WHERE `username` = '$encrypt_user' AND `userpass` = '$encrypt_password'"; $result = mysql_query($query) or die (mysql_error()); if (mysql_num_rows($result)>0){ while($row = mysql_fetch_row($result)){ // set the cookies setcookie("cookie[pas]", "$encrypt_password"); setcookie("cookie[user]", "$encrypt_user"); $query = ("UPDATE`users`SET`sid`='$session', `ip` = '$ip'WHERE `username` = '$encrypt_user' AND `userpass` = '$encrypt_password'"); $result = mysql_query($query) or die (mysql_error()); } } else { echo 'No rows found'; } ?> This works fine now when I add this bit of code I can see the cookie name and value. <?php echo "$ip<br>"; if (isset($_COOKIE['cookie'])) { foreach ($_COOKIE['cookie'] as $name => $value) { $name = htmlspecialchars($name); $value = htmlspecialchars($value); echo "$name : $value <br />\n"; } } ?> I can see the ip address and the two cookies named user and pass but when I try to get the individual cookie details nothing comes out and this is the issue as I need to test each of the two individual cookies against the info in the database so I can include pages to make it all secure. I have tried <?php if (isset($_COOKIE['user'])) { echo "$encrypt_user"; } ?> encrypt_user being the username from the form. I have also tried <?php if (isset($_COOKIE['user'])) { echo "$_COOKIE['user']"; } ?> These are not showing. I do not need to see it just run a query to test that each cookie matches the encrypt data in the MySQL. Any ideas would be great if you can help and if not have a great weekend
-
I have solved this using the code below if it helps someone. $d = $_POST['d']; $d1 = $_POST['d1']; include 'config.php'; for ($i = $d; $i <= $d1; $i++) { $query = "INSERT INTO `test`(`day`) VALUES ('$i')"; $result = mysql_query($query) or die (mysql_error()); echo "$i"; }
-
Using MySQL 5 I am trying to use a loop to insert data The tables are day, day1, month, year and price. I have used a loop using day and day1 using php for the days and I know the months and year using a drop down menu. The idea is the user selects day then day1 and then the price and all that data is added. days being 1 2 3 4 5 6 7 etc using php for the loop. I can do a normal insert but is it posable to do this in sql using a loop? Any help would be great many thanks
-
I have solved this using a loop the code is below if anyone needs it. <?php $d = $_POST['d']; $d1 = $_POST['d1']; $num = $d; while ($num <= $d1) { echo $num."<br />"; $num++; } ?> Many thanks for looking
-
I have a page with 3 drop down lists one for day of the month, one for month and one for year. what I am trying to do is use something that will enable me to make each day from the selected dates to appear as individual days. So if someone selected 1st of September and then 23rd of September it would show 1 2 3 4 5 up to 23. I need to be able to put this in a database. The make date is easy and I think I need to use explode but when I have seen this it comes out with 1, 2, 3, 4, and I do not want to use the comer. This is what I am using for the dates. <?php $d = $_POST['d']; $m = $_POST['m']; $y = $_POST['y']; $d1 = $_POST['d1']; $m1 = $_POST['m1']; $y1 = $_POST['y1']; $date = date ("M-d-Y", mktime(0, 0, 0, $m, $d, $y)); $date1 = date ("M-d-Y", mktime(0, 0, 0, $m1, $d1, $y1)); ?> It will also have prices with these dates so if the user puts in 20.00 for day 1 it would need to go in for the dates selected. ie 1st 20.00 2nd 20.00 and so on. Any ideas or help would be appreciated Many Thanks