Jump to content

"IF" operator playing up in SIMPLE CODE


jonnewbie12

Recommended Posts

Totally baffled here!

 

I have a Recordset that returns numerous values from a table.  The 1st row value in one of the columns called 'moisture' is 1.

 

When I insert an IF command to to perform a task (echo some text) if the value is 1 it just doesn't work. Here is the code.

 

 

<?php if ($rowRecordset1['moisture'] =="1") {echo "moisture resistant";} ?>

 

 

I know the value is 1 because if I echo the the recordset as follows the value comes up as 1:

 

<?php echo $row_Recordset1['moisture'];?>

 

I canty for the life of me figure out what I am doing wrong with such a simple code.  The Field type in MY PHP admin is set to INT, collation utf8_general_CI, NULL is off and default is none.  There are no attributes.

 

ANYONE????? :-[ :-[

 

 

Link to comment
https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/
Share on other sites

Sure.  Thanks.  Problem I have is that I am trying to get two if statements doing two different things.  For example, the 1st row in the 'moisture' column returns the value of 1 so I want it to say "moisture resistant".  BUT I also query another column "Fire" in the same row.  This returns a value of 0 so I want it to do nothing.  If it had a value of 1 then it would say "flame retardant".  I have copied the code so you can see what I am trying to do:

 

<?php require_once('Connections/blindserver.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

 

mysql_select_db($database_blindserver, $blindserver);

$query_Recordset1 = "SELECT * FROM materials WHERE G = 'pattern'";

$Recordset1 = mysql_query($query_Recordset1, $blindserver) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

 

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

 

 

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

 

<link type="text/css" rel="stylesheet" href="../magiczoomplus.css"/>

<script type="text/javascript" src="../magiczoomplus.js"></script>

 

 

 

<title>Untitled Document</title>

 

 

 

</head>

 

<body>

<p> </p>

 

 

 

<a href="<?php echo $row_Recordset1['fabricpicture']; ?>" class="MagicZoomPlus" rel="caption-source:span;caption-position:right" title="<?php echo $row_Recordset1['fabricgroup']; ?> <?php echo $row_Recordset1['E']; ?>">

 

<img src="<?php echo $row_Recordset1['fabricpicture']; ?>" name="Grey" width="100" height="100" border="0" class="MagicZoomPlus" id="Grey"/>

 

 

<span><strong><?php echo $row_Recordset1['fabricgroup']; ?> <?php echo $row_Recordset1['E']; ?></strong> </p> <?php echo $row_Recordset1['fabricmaterial']?> </P> Max Width = <?php echo $row_Recordset1['width']?> </p> Max Drop = <?php echo $row_Recordset1['drop']?> </p> <?php if ($rowRecordset1['moisture'] ==1) {echo "moisture resistant";} ?> </p> <?php if ($rowRecordset1['flame'] ==1) {echo "flame retardant";} ?></p> and [a href=example.html]here is a link[/a]</span>.

</a>

 

 

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.