Jump to content

If statement not working


ntspdy

Recommended Posts

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?

Link to comment
Share on other sites

You need to fetch the stuff

[code]
<?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']};
}
?>
[/code]
Link to comment
Share on other sites

You should combine the two queries into one.

[code]<?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)
?>[/code]

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.