Gnub Posted March 1, 2007 Share Posted March 1, 2007 Ok, here are the basics. I have a form, where the user inputs data, and based on the data inputed, the query checks the database, and returns some info based on the criteria provided. The Problem - Reality: The date range provided by the user, if is within 12 days does not show the package, that i know for sure are within that range. Example: From 20th of March to 31st March, the query should return all data between those dates, however it doesn't, i know there is 1 in that range. Now if i extend that range to 18th - 31st, it picks up 1, but that 1 is listed as a package on the 18th, and is not showing the 1 that i know is listed on the 25th. I've checked the field type is in date format on the DB. There is also an error check within this query. If there isn't a result, it will display a "Please try again" or if there are packages it will display them, however it displays neither. Im guessing that the query does pick up the package, but for some reason doesn't show it. Thanks in Advance Gnub 2 Code snippets. Fig.1 Query <?PHP if ($mnuFrom !=="zero") { if ($mnuTo !=="zero") { if ($mnuStars !== "0") { if ($mnuBoard !== "0") { if ($mnuNights !=="0") { if ($mnuNights =="1") { $tsql = "Select `Teletext`.*, DATE_FORMAT(`DepartureDate`, '%a %D %b') AS revised_date, (`Price`-(`FLIGHTS`+`ACCOM`)) AS YMARGIN FROM `Teletext` WHERE DepartureDate BETWEEN '$DateFrom' AND '$DateTo' AND Departure = '$mnuFrom' AND ArrivalPoint = '$mnuTo' AND Board = '$mnuBoard' AND Rating = '$mnuStars' Order BY Price ASC;"; } if ($mnuNights =="2") { $tsql = "Select `Teletext`.*, DATE_FORMAT(`DepartureDate`, '%a %D %b') AS revised_date, (`Price`-(`FLIGHTS`+`ACCOM`)) AS YMARGIN FROM `Teletext` WHERE DepartureDate BETWEEN '$DateFrom' AND '$DateTo' AND Departure = '$mnuFrom' AND ArrivalPoint = '$mnuTo' AND Board = '$mnuBoard' AND Rating = '$mnuStars' AND Duration < 7 Order BY Price ASC;"; } if ($mnuNights =="3") { $tsql = "Select `Teletext`.*, DATE_FORMAT(`DepartureDate`, '%a %D %b') AS revised_date, (`Price`-(`FLIGHTS`+`ACCOM`)) AS YMARGIN FROM `Teletext` WHERE DepartureDate BETWEEN '$DateFrom' AND '$DateTo' AND Departure = '$mnuFrom' AND ArrivalPoint = '$mnuTo' AND Board = '$mnuBoard' AND Rating = '$mnuStars' AND Duration = 7 Order BY Price ASC;"; } if ($mnuNights =="4") { $tsql = "Select `Teletext`.*, DATE_FORMAT(`DepartureDate`, '%a %D %b') AS revised_date, (`Price`-(`FLIGHTS`+`ACCOM`)) AS YMARGIN FROM `Teletext` WHERE DepartureDate BETWEEN '$DateFrom' AND '$DateTo' AND Departure = '$mnuFrom' AND ArrivalPoint = '$mnuTo' AND Board = '$mnuBoard' AND Rating = '$mnuStars' AND Duration BETWEEN 8 and 13 Order BY Price ASC;"; } if ($mnuNights =="5") { $tsql = "Select `Teletext`.*, DATE_FORMAT(`DepartureDate`, '%a %D %b') AS revised_date, (`Price`-(`FLIGHTS`+`ACCOM`)) AS YMARGIN FROM `Teletext` WHERE DepartureDate BETWEEN '$DateFrom' AND '$DateTo' AND Departure = '$mnuFrom' AND ArrivalPoint = '$mnuTo' AND Board = '$mnuBoard' AND Rating = '$mnuStars' AND Duration > 14 Order BY Price ASC;"; }}}}}} ?> Fig.2 Small IF Error Handling. <?PHP IF($row = mysql_fetch_array($result)) { While ($row = mysql_fetch_array($result)) { echo "<TR><TD valign=top align=Left size=3 ><B> Date:</TD><TD><font color=red><B>" . $row['revised_date']."<B> </font> Resort: <font color=red>".$row["Destination"].".</font></TD><TD><B>Nights:<font color=red>".$row["Duration"]."</font></TD><TD><B> Price: </B><font size=3 color=red><B>£".$row["Price"]."!</B></TD></tr>"; echo "<TR><TD>From: </TD><TD><font color=red>".$row["Departure"]." </font> Board basis : <font color=red>".$row["Rating"]."*".$row["Board"]."</font></TD><td>Quote No:<font color=red> ".$row["Row_No"]."</font></td></TR>"; echo "<TR><TD>Hotel: </TD><TD><font color=red>".$row["AccName"]."</font></TD></TR>"; echo "<TR><TD colspan=7><hr size=1 color=red></td></tr>"; } } Else { echo "<TR><TD align=center colspan=4><font size=3><B>Your search did not find anything between</TD></TR><TR><TD colspan=4 align=center><font size=3><B>$mDateFrom and $mDateTo </TD></TR><TR><TD colspan=4 align=center><font size=3><B>Try altering your search, or call our Sales dept.<BR></font></B></TD></TR>"; echo "<TR><td colspan=1></td><TD colspan=4 align=right><BR><img src=\"images/image1.JPG\" /><img src=\"images.JPG\" /><img src=\"images/image1.JPG\" /></td></TR>"; } ?> Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 try using echo $tsql; this will give you the query tocheck if the query that is being executed is correct or not... mysql_num_rows($result); this will give you an idea whether its fetching any data or not.. Quote Link to comment Share on other sites More sharing options...
Gnub Posted March 1, 2007 Author Share Posted March 1, 2007 through trial and error i've managed to find my problem. check code, snippet before reading on. I removed the IF statement, and kept the While. It returned the 1 package i talked about in my example. Is there a way i can say... IF (($row = mysql_fetch_array($result)) > 1) ? IF($row = mysql_fetch_array($result)) { While ($row = mysql_fetch_array($result)) { echo "<TR><TD valign=top align=Left size=3 ><B> Date:</TD><TD><font color=red><B>" . $row['revised_date']."<B> </font> Resort: <font color=red>".$row["Destination"].".</font></TD><TD><B>Nights:<font color=red>".$row["Duration"]."</font></TD><TD><B> Price: </B><font size=3 color=red><B>£".$row["Price"]."!</B></TD></tr>"; echo "<TR><TD>From: </TD><TD><font color=red>".$row["Departure"]." </font> Board basis : <font color=red>".$row["Rating"]."*".$row["Board"]."</font></TD><td>Quote No:<font color=red> ".$row["Row_No"]."</font></td></TR>"; echo "<TR><TD>Hotel: </TD><TD><font color=red>".$row["AccName"]."</font></TD></TR>"; echo "<TR><TD colspan=7><hr size=1 color=red></td></tr>"; } } Else { echo "<TR><TD align=center colspan=4><font size=3><B>Your search did not find anything between</TD></TR><TR><TD colspan=4 align=center><font size=3><B>$mDateFrom and $mDateTo </TD></TR><TR><TD colspan=4 align=center><font size=3><B>Try altering your search, or call our Sales dept.<BR></font></B></TD></TR>"; echo "<TR><td colspan=1></td><TD colspan=4 align=right><BR><img src=\"images/image1.JPG\" /><img src=\"images.JPG\" /><img src=\"images/image1.JPG\" /></td></TR>"; } ?> Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted March 1, 2007 Share Posted March 1, 2007 if (mysql_num_rows ($query) > 0) { # do something } Quote Link to comment Share on other sites More sharing options...
Gnub Posted March 1, 2007 Author Share Posted March 1, 2007 thanks mbtayler Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 if (mysql_num_rows ($query) > 0) { # do something } sorry to correct you but it should be the result in place of query... Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted March 1, 2007 Share Posted March 1, 2007 Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 what was that for mbtaylor Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted March 1, 2007 Share Posted March 1, 2007 Just my sense of humour. Quote Link to comment 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.