sad beginner sad beginner - 7 months ago 12
SQL Question

php while loop + where


list table



  • id

  • name

  • illness

  • recipe

  • directions

    $illness = 'Highblood';
    $list = mysql_query("SELECT * FROM list ",$con);
    while($row=mysql_fetch_array($list, MYSQL_ASSOC)){
    $test[] = $row['recipe'];
    $test2[] = $row['directions'];
    }



I want to only get the rows


  • $row['recipe'];

  • $row['directions'];



if the value of illness column is equals to highblood.
how do I do this?

Answer

Select only required rows.

$list = mysql_query("SELECT recipe,directions FROM list WHERE illness='Highblood'",$con);
while($row=mysql_fetch_array($list, MYSQL_ASSOC)){
  $test[] = $row['recipe'];
  $test2[] = $row['directions'];
}