0

我对 mysqli 还是有点陌生​​,所以请放轻松。我正在尝试转换为 MYSQLI,这就是我想出的。

db_conx.php

<?php
$db_conx = mysqli_connect("localhost", "use", "pass", "db");
// Evaluate the connection
if (mysqli_connect_errno()) {
    echo mysqli_connect_error();
    exit();
}
?>

<?php
    // Connect to the MySQL database  



include "includes/db_conx.php"; 
$sql = "SELECT * FROM content ORDER BY id DESC";

$result = mysqli_query($db_conx,$sql);
$productCount = mysqli_num_rows($result);

        $blogList = "";
    if ($productCount > 0) {

$adverts = array(
'test',
'test 2');
$counter = 0;

while($row = mysqli_fetch_assoc($sqltwo)){
$id = $row["id"];
$article_title = $row["article_title"];
$category = $row["category"];
$author = $row["author"];
$date_added = $row["date_added"];
$article = $row["article"];
$short = substr(strip_tags($article), 0, 750);
$shortTitle = substr(strip_tags($article_title), 0, 45);

if($readmore == ''){
//Code for new post
$blogList .= '<div class="blogSnippetTitle"><a href="http://www..php?id='.$id.'"><h2>'.$article_title.'</h2></a></div><div class="blogSnippet"><div class="blogImage"><img src="http://www./'.$id.'.jpg" height="142px" width="200px" alt="'.$category.' '.$shortTitle.'" /></div><div class="blogSnippetPrev"><div class="citation">By <span style="color:#006699;">'.$author.'</span> on <span style="color:#99aacc;">'.$date_added.'</span> in <span style="color:#006699;">'.$category.'</span></div>
<div class="snippet">'.$short.'...<br /></div>
<div class="readMoreButton"><br /><a href="http://www..php?id='.$id.'"><img src="http://www.read_more.png" alt="read more graphic" /></a></div>
</div>
</div>';
}
else{
//Code for old post
$blogList .= '<div class="blogSnippetTitle"><a href="'.$readmore.'"><h2>'.$article_title.'</h2></a></div><div class="blogSnippet"><div class="blogImage"><img src="http://www./'.$id.'.jpg" height="142px" width="200px" alt="'.$category.' '.$shortTitle.'" /></div><div class="blogSnippetPrev"><div class="citation">By <span style="color:#006699;">'.$author.'</span> on <span style="color:#99aacc;">'.$date_added.'</span> in <span style="color:#006699;">'.$category.'</span></div>
<div class="snippet">'.$short.'...<br /></div>
<div class="readMoreButton"><br /><a href="'.$readmore.'"><img src="http://www.read_more.png" alt="read more graphic" /></a></div>
</div>
</div>';
}
if($counter < 2){
$blogList .= $adverts[$counter];
$counter++;
}
}
}
?>

我得到的错误是

[07-Aug-2013 22:18:26 America/Denver] PHP 警告:mysqli_fetch_assoc() 期望参数 1 为 mysqli_result,在第 23 行的 /home/learnsit/public_html/site-design-blog.php 中给出 null

4

1 回答 1

3

你正在传递sqltwomysqli_fetch_assoc() mysqli_result它需要一个类似的论点 $result

尝试这个,

while($row = mysqli_fetch_assoc($result)){

代替

while($row = mysqli_fetch_assoc($sqltwo)){

读取mysqli_fetch_assoc()

于 2013-08-08T04:28:08.330 回答