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'];
}
}