调试MYSQLI转换

时间:2013-08-08 04:26:12

标签: php mysqli

我在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++;
}
}
}
?>

我得到的错误是

  

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

1 个答案:

答案 0 :(得分:3)

您正在sqltwo 中传递mysqli_fetch_assoc()但是它需要参数 mysqli_result就像$result

一样

试试这个,

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

取代

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

阅读mysqli_fetch_assoc()