PHP/MySQL打印int值内部的0
当我尝试在ID字段中输入标记我的个人帖子(帖子ID:1932等)时,值总是打印为0,而不是数据库的值 该查询采用$\u请求的topic变量(通过单击链接生成) 这是我的密码:PHP/MySQL打印int值内部的0,php,mysql,printf,Php,Mysql,Printf,当我尝试在ID字段中输入标记我的个人帖子(帖子ID:1932等)时,值总是打印为0,而不是数据库的值 该查询采用$\u请求的topic变量(通过单击链接生成) 这是我的密码: <?php require_once 'connect.php'; $topic = $_REQUEST['topic']; // Build the SELECT statement $select_posts = "SELECT p.topic, p.title, p.pic_id, p.sni
<?php
require_once 'connect.php';
$topic = $_REQUEST['topic'];
// Build the SELECT statement
$select_posts =
"SELECT p.topic, p.title, p.pic_id, p.snippet, p.content, p.author_id, p.date FROM posts p WHERE p.topic = '" . $topic . "' OR p.topic='Admin' ORDER BY p.date DESC";
// Run the Query
$result = mysql_query($select_posts);
?>
<?php
$post_count=0;
while ($post_count<10 && $posts = mysql_fetch_array($result)) {
$posts_row = sprintf(
'<entry>
<headline>%s</headline>
<pic><img class=inlinepic src=/Sustenance/assets/post-pics/%d.jpg></pic>
<snippet class=on id="%d snippet">%s</snippet>
<readmore id="readmore%d" class=on onclick=readmore("%d")>Read More</readmore>
<content id="%d" class="less">%s
<readmore class=on onclick=readless(%d)>Show Less</readmore>
</content>
<byline>
<by>by</by>
<author>%s</author>
</byline>
</entry>',
$posts['topic'], $posts['title'], $posts['pic_id'], $posts['post_id'], $posts['snippet'], $posts['post_id'], $posts['post_id'], $posts['post_id'], $posts['content'], $posts['post_id'], $posts['author_id']);
echo $posts_row;
$post_count++;
}
?>
你必须把
$divid=$posts['post_id'];
在while
循环中。现在的方式是,在循环头中第一次分配值之前,它尝试获取一个值$posts['post_id']
,因此它是0
,并且永远不会更改(因为它从未被重新分配)。不应该$divid=$posts['post_id'];在while循环中?这是一个很好的观点!我把它移回了应该放的地方。然而,这似乎并没有解决问题。