PDA

View Full Version : query?


hola
04-23-2007, 04:50 PM
i am trying to view result based on this condition;

User selects start and end date...so

select * from table between start date and end date.

now 2nd check after the above query should be;

if the (quantity = 0) in any of these start and end date...then display message...else if the quantity does not = 0 in any of the row (start & end date) then display the results.

the problem at the moment is the if statement is under the while statement..that is causing to print out both..the msg and the results.....


while($row11 = mysql_fetch_array($result)){


$av = $row11['av'];

if ($av==0){

echo"sorry no rooms available";}

else {

echo "<form>";......etc }

}


how to sort this problem out?

richei
04-23-2007, 06:38 PM
Well for 1, ur not closing ur while statement, is there something more there? I woud echo your before and after variables to make sure ur getting the desired output.


while($row11 = mysql_fetch_array($result)){

$av = $row11['av'];

if ($av==0)
{
echo"sorry no rooms available";
}
else {
echo "<form>";......etc
}
}

hola
04-23-2007, 08:11 PM
well rechie^ i deleted out the rest of the code..well this is what i am trying to do

------------------- Qty type
Day1--------------- 0 test1
Day1--------------- 3 test2

Day2--------------- 2 test1
Day2--------------- 1 test2

Day3--------------- 1 test1
Day3--------------- 1 test2

if Qty is zero...it should not display any of the test1.....for any days...it should only display test2...so the output would be:

Day1 3 test2
Day2 2 test2
Day3 1 test2

and from here ....then i wanted to display the lowest qty row...so FINAL output

Day3 1 test2.........

Stryker250
04-24-2007, 02:05 AM
add this to your query or make your query look something like this


$query = "SELECT * FROM tbl WHERE date >= '$date_from' AND date <= '$date_to' AND av <> '0' ORDER BY date ASC";
$result = mysql_query($query) or die(mysql_error());


EDIT...just to explain the '<>' part of the query....that part means where av does not equal 0 ;)

EDIT......here is another method you could try

while($row11 = mysql_fetch_array($result)){

$av = $row11['av'];
$room_type = $row11['roomType'];
if ($av == '0' && $room_type == 'Single' || $room_type == 'Double')
{
echo"sorry no rooms available";
}else{

echo "Your data row start";......etc
}

}

hola
04-24-2007, 12:36 PM
User selects start and end date....from 25 to 27....

+---------+------+-----------+
| day_Num | qty | room_Type |
+---------+------+-----------+
| 25 | 2 | single |
| 25 | 0 | double |
| 25 | 0 | ensuite |
| 26 | 6 | single |
| 26 | 13 | double |
| 26 | 5 | ensuite |
| 27 | 1 | single |
| 27 | 1 | double |
| 27 | 1 | ensuite |
+---------+------+-----------+

room_Type = double and ensuite has ZERO qty....so all the related data with double and ensuite...should not be printed...so the OUTPUT should be:

+---------+------+-----------+
| day_Num | qty | room_Type |
+---------+------+-----------+
| 25 | 2 | single |
| 26 | 6 | single |
| 27 | 1 | single |
+---------+------+-----------+

And from here then... the lowest qty should be printed out, so the FINAL OUTPUT should be:

+---------+------+-----------+
| day_Num | qty | room_Type |
+---------+------+-----------+
| 27 | 1 | single |
+---------+------+-----------+

Anyone know what the query should be?