gpt4 book ai didi

php - 无法在 PHP 中查看数据库中的表

转载 作者:行者123 更新时间:2023-11-29 13:37:56 24 4
gpt4 key购买 nike

我的 PhpMyAdmin 中有这张表 jurnal_training

-------------------------------------------------------------------
| id_jurnal | kategori | judul | isi_jurnal | status |
-------------------------------------------------------------------
| 1 | WS | Example 1 | content example 1 | 0 |
| 2 | WS | Example 2 | content example 2 | 1 |
| 3 | WS | Example 3 | content example 3 | 1 |
| 4 | WS | Example 4 | content example 4 | 0 |
.
.
.

在 PHP 中,我只需要查看“类别”和“期刊”,其中“状态”为 0;

这是我的代码:

<?
$rec_limit = 9;
$sql = "SELECT count(judul) FROM jurnal_training ";
$retval = mysql_query($sql);
$row = mysql_fetch_array($retval);
$rec_count = $row[0];

if( isset($_GET{'paging_view'} ) )
{
$paging = $_GET{'paging_view'} + 1;
$offset = $rec_limit * $paging ;
}
else
{
$paging = 0;
$offset = 0;
}
$left_rec = $rec_count - ($paging * $rec_limit);

$sql = "SELECT * ".
"FROM jurnal_training ".
"LIMIT $offset , $rec_limit ".
"WHERE status = 1";

$count=1;
$retval = mysql_query($sql) or die(mysql_error());;
while ($row = mysql_fetch_array($retval))
{
echo "<tr >
<td>",$count,"</td>
<td>",$row['kategori'],"</td>
<td><a href='index.php?do=view_jurnal&id_jurnal=",$row['id_jurnal'],"'>",$row['judul'],"</a></td>
<td><a href='index.php?do=edit_jurnal&id_jurnal=",$row['id_jurnal'],"' class='process_button_s' >Edit</a><a href='index.php?do=delete_jurnal&id_jurnal=",$row['id_jurnal'],"'class='process_button_s'>Delete</a></td>
<td><a href='index.php?do=train_process&id_jurnal=",$row['id_jurnal'],"' class='process_button'>Train Data</a></td>
</tr>";
$count++;
}
?>

在上面的变量 $sql 中,如果我不在查询末尾添加“WHERE status = 0”,则在 PHP 中查看该表格。但是,如果我输入“WHERE status = 0”,则不会查看表并得到错误结果:

“您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本对应的手册,了解在第 1 行 'WHERE status = 0' 附近使用的正确语法”

最佳答案

您有 SQL 语句:

SELECT * 
FROM jurnal_training
LIMIT $offset , $rec_limit
WHERE status = 1

LIMIT 位于 WHERE 之后:

SELECT * 
FROM jurnal_training
WHERE status = 1
LIMIT $offset , $rec_limit

关于php - 无法在 PHP 中查看数据库中的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18524241/

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