groston Posted November 15, 2021 Share Posted November 15, 2021 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? Quote Link to comment https://forums.phpfreaks.com/topic/314238-this-seems-beyond-simple-but-its-not-working-please-help/ Share on other sites More sharing options...
ginerjm Posted November 15, 2021 Share Posted November 15, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/314238-this-seems-beyond-simple-but-its-not-working-please-help/#findComment-1592159 Share on other sites More sharing options...
mac_gyver Posted November 16, 2021 Share Posted November 16, 2021 2 hours ago, groston said: The first four echo statements work and what exactly was the output that you got from those statements? Quote Link to comment https://forums.phpfreaks.com/topic/314238-this-seems-beyond-simple-but-its-not-working-please-help/#findComment-1592161 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.