Forum Moderators: coopster

Message Too Old, No Replies

Having Trouble With If and Else.Go figure.

         

comptronica

4:04 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



Hey guys I'm fairly new at this and what i'm trying to do is fairly simple I think.
K... I have a Apartment Building site and I'm trying show the rental payment by month but if tenant has left I want it to say vacant for that month and every month after for the year. Also I have to query twice because Tenants have rent increases(ann) and rent amount changes.
Sounds simple huh?
Been trying for three days straight and this is what I've got.

<?
$sql="select * from tenants where id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_assoc($result);
$d=date ("m");
$term=($rows['term']);
if ('2008/01/01' == ($term))
{
echo "Vacant";
}
else if ($d=="01"){
$sql="SELECT SUM(jan) + SUM(jan1) + SUM(jan2)- SUM(rent) as new_jan FROM tenants where id='$id' and ann between '2008/02/01' AND '2008/12/31'";
$sql="SELECT SUM(jan) + SUM(jan1) + SUM(jan2)- SUM(rent2) as new_jan FROM tenants where id='$id' and ann between '2008/02/01' AND '2008/02/31'";
$result=mysql_query($sql);
$rows=mysql_fetch_assoc($result);
echo ($rows ["new_jan"]);
}
else if ....and I carry on with the months.
Why doesn't it work?
it will give me answer for tenant that has no term date but tenant that does comes up blank.
Thanks Guys.

deMorte

1:04 pm on Mar 31, 2008 (gmt 0)

10+ Year Member



What type are "ann" and "term" database values? A SQL Date or a Varchar?
If they are Date, your comparison values should be YYYY-MM-DD (ie. 2008-02-01).
If they are Varchars (strings) MySQL manual says that you should convert strings into a Date value to get the desired results on BETWEEN clause.
Maybe you should consider changing all the date-values into SQL friendly YYYY-MM-DD format and see if it helps.
Check these addresses for more info:
[dev.mysql.com...]
[dev.mysql.com...]

comptronica

11:35 am on Apr 1, 2008 (gmt 0)

10+ Year Member



Perfect! Of course changed dates to yyyy-mm-dd in mysql works great.

henry0

11:50 am on Apr 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



comptronica, welcome to WebmasterWorld if not welcomed yet!

BTW do not use the short tags <?
php6 won't allow them so get in the habit of writing the full <?php