Jump to content

How if statement will work


yakk0

Recommended Posts

I can't seem to get the if statement to work and its now displaying blank on the page.

 

<?php

 

include "config.php";

 

$query="SELECT story_title, story_num FROM data order by story_num desc limit 5";

$result=mysql_query($query);

$num=mysql_numrows($result);

 

$i=0;

while ($i < $num) {

 

$story_title=mysql_result($result,$i,"story_title");

$story_num=mysql_result($result,$i,"story_num");

$story_note=['note'];

 

if ($story_note==1)

            {

echo "<img src='images/notice.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";

$i++;

            }

 

elseif ($story_note==2)

        {

echo "<img src='images/updated.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";

$i++;

}

 

elseif ($story_note==3)

{

echo "<img src='images/event.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";

$i++; 

 

elseif ($story_note==4)

{

echo "<img src='images/important.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";

$i++;

}

 

else

            {

echo "<img src='images/notice.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";

$i++;

            }

 

 

mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/137094-how-if-statement-will-work/
Share on other sites

try this instead

 

<?php

include "config.php";

$query="SELECT story_title, story_num FROM data order by story_num desc limit 5";
$result=mysql_query($query);

$i=0;
while($row = mysql_fetch_array($result)) {

$story_title = $row['story_title'];
$story_num = $row['story_num'];
$story_note = $row['note'];

if ($story_note==1)
             {
echo "<img src='images/notice.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";
$i++;
             }
         
elseif ($story_note==2)
            {
echo "<img src='images/updated.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";
$i++;
         }
         
elseif ($story_note==3)
         {
echo "<img src='images/event.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";
$i++; 
         } 
         
elseif ($story_note==4)
         {
echo "<img src='images/important.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";
$i++;
}

else
             {
echo "<img src='images/notice.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>";
$i++;
             }


mysql_close();
?>

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.