complex05 Posted March 13, 2006 Share Posted March 13, 2006 I'm building an application for people to book guest suites in a hotel. This is the script i'm using[code] if ($action == "input_details") { $query = mysql_query("SELECT suites,suitenos,maxnights,nightprice,deposit FROM gssettings WHERE id=1"); $data = mysql_fetch_array($query); $maxnights = $data["maxnights"]; $suites = $data["suites"]; $suitenos = $data["suitenos"]; $nightprice = $data["nightprice"]; $deposit = $data["deposit"]; $suite_numbers = split(",",$suitenos); $query = mysql_query("SELECT suiteno FROM gsdays WHERE date='$arrival'"); $check = mysql_num_rows($query); if($check>=$suites) { $validate = 1; $error = "There are no suites available on $arrival"; } while($data = mysql_fetch_array($query)) { if ($a==1) break; for($i=0;$i<$suites;$i++) { $suiteno = $data["suiteno"]; if ($a==1) break; if ($check==0) { $use_suite = $suite_numbers[0]; } else { if ($suiteno != $suite_numbers[$i]) { $use_suite = $suite_numbers[$i]; $a = 1; } else { $validate = 1; $error .= "There are no suites available on $arrival"; } } } } $departure = "$yearcheck-$monthcheck-$daycheck"; $query = mysql_query("SELECT DATEDIFF('$departure','$arrival') AS datediff"); $data = mysql_fetch_array($query); $datedifference = $data["datediff"]; if ($datedifference > $maxnights) { $validate = 1; $error .= "<li>You are only able to reserve the guest suite for $maxnights days"; } for($i=0;$i<$datedifference;$i++) { list($year,$month,$day) = split("-",$arrival); $this_date = date("Y-m-d",mktime(0,0,0,$month,$day+$i,$year)); $query = mysql_query("SELECT * FROM gsdays WHERE date='$this_date'"); $check = mysql_num_rows($query); if ($check >= $suites) { $validate = 1; $error .= "<li>There are no guest suites available on $this_date"; } } if ($validate == 1) { echo $error; echo("<p><a href=\"guestsuite.php\" class=\"menu\">Click here to try again</a>"); } else { $invoice = (($datedifference*$nightprice) + $deposit); $invoice_show = number_format((($datedifference*$nightprice) + $deposit),2); mysql_query("INSERT INTO gsdata (username,approved,suiteno,arrival,departure,invoice) VALUES ('$username',0,'$use_suite','$arrival','$departure','$invoice')"); for($i=0;$i<$datedifference;$i++) { list($year,$month,$day) = split("-",$arrival); $this_date = date("Y-m-d",mktime(0,0,0,$month,$day+$i,$year)); $query = mysql_query("SELECT id FROM gsdata ORDER BY id DESC LIMIT 1"); $data = mysql_fetch_array($query); $dataid = $data["id"]; mysql_query("INSERT INTO gsdays (suiteno,date,user,dataid) VALUES ('$use_suite','$this_date','$username','$dataid')"); } echo<<<endhtml <b><center>Thank you for making your reservation</b><p> Your invoice total is $$invoice_show</center>endhtml; } }}[/code]The problem is $use_suite returns blank if there are no reservations, if there is one reservation it will use $suite_numbers[0]. Anyone see the problem? Quote Link to comment https://forums.phpfreaks.com/topic/4845-complicated-logic/ Share on other sites More sharing options...
complex05 Posted March 13, 2006 Author Share Posted March 13, 2006 bump. Quote Link to comment https://forums.phpfreaks.com/topic/4845-complicated-logic/#findComment-17063 Share on other sites More sharing options...
complex05 Posted March 13, 2006 Author Share Posted March 13, 2006 nobody wants to takea stap at this one? Quote Link to comment https://forums.phpfreaks.com/topic/4845-complicated-logic/#findComment-17083 Share on other sites More sharing options...
keeB Posted March 13, 2006 Share Posted March 13, 2006 Your code is a bit messy and hard to read, it's taking a little bit to decipher it... give a moment! Quote Link to comment https://forums.phpfreaks.com/topic/4845-complicated-logic/#findComment-17084 Share on other sites More sharing options...
Barand Posted March 13, 2006 Share Posted March 13, 2006 Perhaps if you described the data (tables and columns) and told us what you were trying to achieve it would save us a couple of hours trying to reverse-engineer a script that isn't even working and therefore only tells us what you don't want to do. Quote Link to comment https://forums.phpfreaks.com/topic/4845-complicated-logic/#findComment-17141 Share on other sites More sharing options...
complex05 Posted March 13, 2006 Author Share Posted March 13, 2006 It's alright, I figured it out. Problem was I was getting data from the while() loop... however it wouldnt' run if the query returned no results. And 90% of the time, it SHOULD return 0... silly error. Quote Link to comment https://forums.phpfreaks.com/topic/4845-complicated-logic/#findComment-17144 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.