Jump to content

This seems beyond simple, but it's not working. Please help!


Recommended Posts

I am beyond confused and am hoping that you can help!

I have a database and one table looks like this:
dbTable {
  RowID int(10) unsigned  <this value is created automatically>
  Str varchar(100)
  Val int(10) unsigned
}

In my html/php, I have the following test code:
$sql = "SELECT * FROM dbTable WHERE RowID = 5";
$entityData = $mysqli->query($sql);
$EntityInfo = $entityData->fetch_assoc();
$dStr = $EntityInfo[Str];
$dVal = $EntityInfo[Val];

echo “first line”;
echo "str: " . $dStr;
echo "val: " . $dVal;
$sum = $dVal +5;
echo "sum: " . $sum;
if ($dVal > 0) {
 echo "if Val: " . $dVal;
}

The first four echo statements work, however, I cannot get the code to enter the if loop. It seems that the code knows that $dVal is an integer because the sum shown is correct. What must I do to make the if statement work?

You could use some quotes on those elements of EntityInfo.

You don't have an if loop.  You are simply testing a value of something and if it is true, outputting something.  One time.  

And - I don't like the add of + 5 to dVal but you don't save it.  So dVal is whatever it was in the table.

If php is still new to you I would like to suggest that you stop using mixed case names.  It is a case-sensitive language so if you get into the JS style of coding you are probably going to run into problems all down the road from mis-typing var names all the time.  Stick with all lowercase.

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.