gpt4 book ai didi

php - 如果值设置为 0,如何排除数据?

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:37 25 4
gpt4 key购买 nike

我正在尝试从 MySQL 数据库中解析一些数据,我有一个名为 is_approved 的列,其值为 01 ( 0表示否,1表示是)

我只想回显所有被批准的内容

我该怎么做?

<?php
// Connect to MySQL
$link = mysql_connect( 'localhost', 'username', 'password' );
if ( !$link ) {
die( 'Could not connect: ' . mysql_error() );
}

// Select the data base
$db = mysql_select_db( 'DATABASE', $link );
if ( !$db ) {
die ( 'Error selecting database \'DATABASE\' : ' . mysql_error() );
}

// Fetch the data
$query = "
SELECT *
FROM prayer
ORDER BY created_at DESC";
$result = mysql_query( $query );

// All good?
if ( !$result ) {
// Nope
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die( $message );
}

// Print out rows
while ( $row = mysql_fetch_assoc( $result ) ) {
//echo json_encode($row);
echo 'Name: '.$row['first_name'] . ' ' . $row['last_name'] . ' <br>Gypsy Name: ' .$row['gypsy_name'].'<br>Veetsa: ' .$row['veetsa'].'<br> Location: ' .$row['location'].'<br>' .$row['created_at'].'<br>' .$row['content'] . "<hr>";
}

// Close the connection
mysql_close($link);
?>

计划是吐出 JSON 以便我可以在另一台服务器上使用它

最佳答案

只需在查询中添加一个 WHERE 子句:

SELECT *
FROM prayer
WHERE is_approved = 1
ORDER BY created_at DESC

关于php - 如果值设置为 0,如何排除数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26769868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com