May 24, 2010

Echo items with value of three

Question by user342391

I need to echo all items in my column that have the value of three. If a field has the value of three I then need to echo the ‘name’ and ‘description’ on that row.

This is what I have so far

$result = mysql_query($query1) or die(mysql_error());    
while ($row = mysql_fetch_array($result))    
{  
  echo $row['status'];
}

I need to write ‘if $row[`status´ == 3 echo ‘description’ ‘name’ else echo ‘no current staus’

I hope I made some sense because I am seriously confused

Answer by Starx

You can actually select the result which only has 3 value in its status

for that use this

$query = "SELECT * FROM yourtable WHERE status='3'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array(result)) {
      echo "Name: ".$row['name']."<br>Description: ".$row['description'];
}

and if you want to parse you result to display only those of value this then use this

$query = "SELECT * FROM yourtable";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array(result)) {
      if($row['status']==3) {
           echo "Name: ".$row['name']."<br>Description: ".$row['description'];
      }
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!