PHP - Filtering by MySQL field value

前端 未结 2 1542
Happy的楠姐
Happy的楠姐 2021-01-24 10:13

I\'ve got a table with some rows that contain 3 fields (category, title, image). At first I created a foreach loop that returned some html with the information from each of the

2条回答
  •  爱一瞬间的悲伤
    2021-01-24 11:04

    Either use the WHERE clause as asifrc suggested.

    Or do something like this

    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        if($row['category'] == 'category1') {
          // do some stuff example
          $html_output .= '

    Important category: ' . $row['title'] . '

    '; } else if($row['category'] == 'category2') { // do other stuff $html_output .= '

    Not important category: ' . $row['title'] . '

    '; } }

提交回复
热议问题