jonnewbie12 Posted October 29, 2011 Share Posted October 29, 2011 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????? :-[ Quote Link to comment https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/ Share on other sites More sharing options...
AyKay47 Posted October 29, 2011 Share Posted October 29, 2011 change to <?php if ($rowRecordset1['moisture'] == 1) {echo "moisture resistant";} ?> remove the quotes around the one.. Quote Link to comment https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/#findComment-1283283 Share on other sites More sharing options...
jonnewbie12 Posted October 29, 2011 Author Share Posted October 29, 2011 tried that same result Quote Link to comment https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/#findComment-1283284 Share on other sites More sharing options...
AyKay47 Posted October 29, 2011 Share Posted October 29, 2011 thought as much, the string "1" should convert to an INT 1 anyway.. can you post some of the relevant code around this so that we can help you further.. Quote Link to comment https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/#findComment-1283286 Share on other sites More sharing options...
jonnewbie12 Posted October 29, 2011 Author Share Posted October 29, 2011 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/#findComment-1283291 Share on other sites More sharing options...
AyKay47 Posted October 29, 2011 Share Posted October 29, 2011 shouldn't $rowRecordset1['moisture'] ==1 be $row_Recordset1['moisture'] ==1 instead? I believe that you forgot the underscore in your final two uses of the query record set Quote Link to comment https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/#findComment-1283292 Share on other sites More sharing options...
jonnewbie12 Posted October 29, 2011 Author Share Posted October 29, 2011 DOHHHHH whole day mucking about for an underscore. THANK YOU VERY VERY MUCH Quote Link to comment https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/#findComment-1283293 Share on other sites More sharing options...
AyKay47 Posted October 29, 2011 Share Posted October 29, 2011 Believe me... I've had those days too. Quote Link to comment https://forums.phpfreaks.com/topic/250060-if-operator-playing-up-in-simple-code/#findComment-1283296 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.