2014-01-05 197 views
-1

給我知道有這個問題的超過10分的答案,但我仍然無法找到我的錯誤布爾值。 所以我想一個新聞滑塊有五個不同的變量連接。任何變量是在我的帖子表中的職位數據庫。ERROR:mysql_fetch_array()預計參數1是資源,在

這裏是PHP代碼:

<?php 
     include("includes/connect.php"); 

    $select_posts1= "SELECT FROM posts WHERE post_id = 1"; 
    $select_posts2= "SELECT FROM posts WHERE post_id = 2"; 
    $select_posts3= "SELECT FROM posts WHERE post_id = 3"; 
$select_posts4= "SELECT FROM posts WHERE post_id = 4"; 
$select_posts5= "SELECT FROM posts WHERE post_id = 5"; 

     $run_posts1 = mysql_query($select_posts1); 
    $run_posts2 = mysql_query($select_posts2); 
    $run_posts3 = mysql_query($select_posts3); 
$run_posts4 = mysql_query($select_posts4); 
    $run_posts5 = mysql_query($select_posts5); 

     $News1=mysql_fetch_array($run_posts1); 
    $News2=mysql_fetch_array($run_posts2); 
    $News3=mysql_fetch_array($run_posts3); 
     $News4=mysql_fetch_array($run_posts4); 
    $News5=mysql_fetch_array($run_posts5); 

    $post_id = $News1['post_id']; 
    $post_title = $News1['post_title']; 
    $post_date = $News1['post_date']; 
    $post_author = $News1['post_author']; 
    $post_image = $News1['post_image']; 
    $post_content = substr($News1['post_content'],0,50); 


    $post_id2= $News2['post_id']; 
    $post_title2 = $News2['post_title']; 
    $post_date2 = $News2['post_date']; 
    $post_author2 = $News2['post_author']; 
    $post_image2 = $News2['post_image']; 
    $post_content2 = substr($News2['post_content'],0,50); 


     $post_id3= $News3['post_id']; 
    $post_title3 = $News3['post_title']; 
    $post_date3 = $News3['post_date']; 
    $post_author3 = $News3['post_author']; 
    $post_image3 = $News3['post_image']; 
    $post_content3 = substr($News3['post_content'],0,50); 

    $post_id4= $News4['post_id']; 
    $post_title4 = $News4['post_title']; 
    $post_date4 = $News4['post_date']; 
    $post_author4 = $News4['post_author']; 
    $post_image4 = $News4['post_image']; 
    $post_content4 = substr($News4['post_content'],0,50); 

    $post_id5 = $News5['post_id']; 
    $post_title5 = $News5['post_title']; 
    $post_date5 = $News5['post_date']; 
    $post_author5 = $News5['post_author']; 
    $post_image5 = $News5['post_image']; 
    $post_content5 = substr($News5['post_content'],0,50); 

     ?> 

這裏是滑蓋的代碼:

<li><center><img src="images/<?php echo $post_image; ?>" width="500" height="300" /></center> 
     <div class="panel-overlay"> 
      <h2><?php echo $post_title; ?></h2> 
      <p align="justify"><?php echo $post_content; ?></p><br/> 
      <a href="pages.php">Continue Reading &raquo;</a> 
      </div> 
      </li> 

      <li><center><img src="images/<?php echo $post_image2; ?>" width="500" height="300" /></center> 
     <div class="panel-overlay"> 
      <h2><?php echo $post_title2; ?></h2> 
      <p align="justify"><?php echo $post_content2; ?></p><br/> 
      <a href="pages.php">Continue Reading &raquo;</a> 
      </div> 
      </li> 



     <li><center><img src="images/<?php echo $post_image3; ?>" width="500" height="300" /></center> 
     <div class="panel-overlay"> 
      <h2><?php echo $post_title3; ?></h2> 
      <p align="justify"><?php echo $post_content3; ?></p><br/> 
      <a href="pages.php">Continue Reading &raquo;</a> 
      </div> 
      </li> 

    <li><center><img src="images/<?php echo $post_image4; ?>" width="500" height="300" /></center> 
     <div class="panel-overlay"> 
      <h2><?php echo $post_title4; ?></h2> 
      <p align="justify"><?php echo $post_content4; ?></p><br/> 
      <a href="pages.php">Continue Reading &raquo;</a> 
      </div> 
      </li> 



    <li><center><img src="images/<?php echo $post_image5; ?>" width="500" height="300" /></center> 
     <div class="panel-overlay"> 
      <h2><?php echo $post_title5; ?></h2> 
      <p align="justify"><?php echo $post_content5; ?></p><br/> 
      <a href="pages.php">Continue Reading &raquo;</a> 
      </div> 
      </li> 

    </ul> 
    </div> 
</div> 
</div> 
<?php ?> 

+0

是否查詢工作,如果你的東西,像phpMyAdmin運行呢? – pstenstrm

+0

很多時候,該錯誤消息與不連接到數據庫或壞的查詢檢查。在你的情況下,你沒有選擇任何東西。請參閱下面的'Abhik Chakraborty's'答案。 –

+1

(1)'mysql_query'已棄用。切換到mysqli或PDO。 (2)使用相同的代碼5次是什麼?你有沒有認真從未聽說過'for'循環或數組的數組的? (3)通過硬編碼ID訪問的職位似乎非常搖搖晃晃的給我。 – cHao

回答

3
$select_posts1= "SELECT FROM posts WHERE post_id = 1"; 
$select_posts2= "SELECT FROM posts WHERE post_id = 2"; 
$select_posts3= "SELECT FROM posts WHERE post_id = 3"; 
$select_posts4= "SELECT FROM posts WHERE post_id = 4"; 
$select_posts5= "SELECT FROM posts WHERE post_id = 5"; 

在您的查詢,它缺少字段列表和mysql是返回錯誤。

要麼添加字段列表中SELECT或者只是添加*

$select_posts1= "SELECT * FROM posts WHERE post_id = 1"; 
$select_posts2= "SELECT * FROM posts WHERE post_id = 2"; 
$select_posts3= "SELECT * FROM posts WHERE post_id = 3"; 
$select_posts4= "SELECT * FROM posts WHERE post_id = 4"; 
$select_posts5= "SELECT * FROM posts WHERE post_id = 5"; 
相關問題