Jump to content

Recommended Posts

i want to check my mysql database for the row if it is 0 or 1 or whatever it is and then print a word/words into a sentence according to the result..

for ex: my TABLE has a row named HEALTH and its value is 3. i want to use a variable in a sentences that will print GOOD. but if it were 2, script would print NOT BAD and for 1, print BAD.. my sentences is like this: Hi bla bla, your health is $var now.. how can i do this.. with if else tag i can make it print a sentences but cant do as a $var in a sentence???

Link to comment
https://forums.phpfreaks.com/topic/51332-solved-if-else-and-mysql/
Share on other sites

after connected to the database, the code must be something like this : (gives parse error, couldnt do that)

 

if (row['health']=="3")

  $var = 'good';

elseif (row['health']=="2")

  $var = 'normal';

elseif (row['health']=="1")

  $var = 'bad';

else

  echo "";

 

 

your health is $var .

 

 

Can you post the error?

 

I think the error is going to tell you that you need brackets:

 

if (row['health']=="3") {
  $var = 'good'; }
elseif (row['health']=="2") {
  $var = 'normal'; }
elseif (row['health']=="1") {
  $var = 'bad'; }
else {
  echo ""; }

echo "Your health is $var";

$result = mysql_query("SELECT * FROM utopia
WHERE kullaniciadi='$session->username'");

if (row['disgorunus']=="3") {
  $var = 'good'; }
elseif (row['disgorunus']=="2") {
  $var = 'normal'; }
elseif (row['disgorunus']=="1") {
  $var = 'bad'; }
else {
  echo ""; }

echo "Your health is $var";  //this is not here originally.

while($row = mysql_fetch_array($result))
  {
  echo $row['karakteradi'] . " şu an " . $row['disgorunus'] . " görünüyor ve kendini " . $row['ruhhali']. " hissediyor. " . $row['karizma']. " karizmaya sahip ve sağlığı " . $row['saglik']. ".";
  }

 

this is the code i am using.

gives parse error for the line if (row['disgorunus']=="3") { says: parse error on this line ..

 

Also, you do the query, but you never fetch the row information. Try something like this:

<?php
$result = mysql_query("SELECT * FROM utopia WHERE kullaniciadi='$session->username'");
$row = mysql_fetch_assoc($result);
switch ($row['disgorunus']) {
     case '1':
          $var = 'bad';
          break;
     case '2':
          $var = 'normal';
          break;
     case '3':
          $var = 'good';
          break;
      default:
          $var = '';
}
echo "Your health is $var";  //this is not here originally.
?>

 

Ken

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.