Jump to content


Photo

If statement not working


  • Please log in to reply
4 replies to this topic

#1 ntspdy

ntspdy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 April 2006 - 10:15 PM

First off, I appreciate any help I can get.

Here is my issue, I'm making a call to a DB then depending on the data from one column I'm displaying the data from a second column. The problem I'm getting is that even though I know the data in the column I cannot get my if statement to recognize the "true" part of the statement. Here is the code.

<?php
include('dbconnect.php');

$query="SELECT runtime
FROM missionruntime";
$query1="SELECT start
FROM missionruntime";

$runtime=mysql_query($query);
$start=mysql_query($query1);

if ( $start == 2006-04-19 13:51:59 ) {
echo "SERVER DOWN";
} else {
echo mysql_result($runtime,"runtime");
}
?>

Now I know that $start = 2006-04-19 13:51:59 but it will not display SERVER DOWN. It just displays a blank page. Since the data type is varchar(20) do I have to specify my = statement differently?



#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 19 April 2006 - 10:34 PM

try...

if ( $start == '2006-04-19 13:51:59') {
echo "SERVER DOWN";
} else {
echo mysql_result($runtime,"runtime");
}
follow me on twitter @PHPsycho

#3 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 19 April 2006 - 10:35 PM

You need to fetch the stuff

<?php
include('dbconnect.php');

$query="SELECT runtime
FROM missionruntime";
$query1="SELECT start
FROM missionruntime";

$runtime=mysql_fetch_array(mysql_query($query));
$start=mysql_fetch_array(mysql_query($query1));



if ( $start['start'] == 2006-04-19 13:51:59 ) {
echo "SERVER DOWN";
} else {
echo {$runtime['runtime']};
}
?>


#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 April 2006 - 12:03 AM

You should combine the two queries into one.

<?php
include('dbconnect.php');

$query="SELECT runtime, start FROM missionruntime";
$rs = mysql_query($query1);
$row=mysql_fetch_assoc($rs);



if ( $row['start'] == 2006-04-19 13:51:59 ) echo "SERVER DOWN";
else echo $row['runtime']; // you don't need the curly braces here. (edited original post)
?>

Ken

#5 ntspdy

ntspdy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 20 April 2006 - 01:58 AM

Thanks guys, and thanks for answering my second question before I asked it kenrbnsn. I was sure there was a way to do that but that was second on my list.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users