本文介绍了脚本(while循环)停止,并且具有没有输出时选择了多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从TABLE中选择多个列,但是一旦while循环开始,脚本就无法工作.我的php和html代码是:

I want to select more than one columns from TABLE but the script is not working once the while loop starts. my php and html code is:

<table border="0">
include_once $_SERVER['DOCUMENT_ROOT'].'/include/db.inc.php' ;
$sql="select post_title,post_desc,post_date,course,semester,firstname,lastname 
      FROM wbut_forum_posts left join users on post_by = email
      ORDER BY post_id DESC LIMIT 25";
$result = mysqli_query($link,$sql );

if (!$result) {
    include_once "wall.html.php";
    echo'<tr><td align="center"> OOOOPPPPPSSS!!!SORRY,UNABLE TO DISPLAY LATEST 25 TOPICS</td></tr>';
    exit();
}

while ($row = mysqli_fetch_array($result)) {
    $titles[] = $row['post_title'];
    $descs[] = $row['post_desc'];
    $dates[] = $row['post_date'];
    $courses[] = $row['course'];
    $semesters[] = $row['semester'];
    $firstnames[] = $row['firstname'];
    $lastnames[] = $row['lastname'];
}

$cnt=0;
foreach ($titles as $x) {
    $title[$cnt]=$x;
    $cnt=$cnt+1;
}

$cnt=0;
foreach ($firstnames as $x) {
    $firstname[$cnt]=$x;
    $cnt=$cnt+1;
}

$cnt=0;
foreach ($lastnames as $x) {
    $lastname[$cnt]=$x;
    $cnt=$cnt+1;
}

$cnt=0;
foreach ($descs as $x) {
    $descs[$cnt]=$x;
    $cnt=$cnt+1;
}

$cnt=0;
foreach ($dates as $x) {
    $date[$cnt]=$x;
    $cnt=$cnt+1;
}

$cnt=0;
foreach ($courses as $x) {
    $courses[$cnt]=$x;
    $cnt=$cnt+1;
}

$cnt=0;
foreach ($semesters as $x) {
    $semester[$cnt]=$x;
    $cnt=$cnt+1;
}

echo'AFTER FOREACHES';
for ($i=0;$i<$cnt;$i=$i+1) {

    echo'<table border="0">';
        echo'<tr>';
            echo '<td align="left"><span class="style1">';
                echo $firstname[$i] . " " . $lastname[$i] ;
            echo '</span></td>';
            echo '<td align="center"  colspan="2">RELATED COURSE :';
                echo $course[$i];
                echo '&nbsp;&nbsp;&nbsp;&nbsp; RELATED SEMESTER:';
                echo $semester[$i];
            echo '</td>';
        echo '</tr>';
        echo '<tr>';
            echo '<td>&nbsp;</td>';
            echo'<td align="left"><span class="style3">';
                echo  $desc[$i];
            echo '</span></td>';
            echo'<td valign="baseline">';
                echo $date[$i];
            echo '</td>';
        echo '</tr>';
        echo'<tr>';
            echo '<td>&nbsp;</td>';
            echo '<td align="left" background="reply_bg.gif"><span class="style3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                echo 'echo the replies here';
                echo '</span>';
            echo '</td>';
            echo'<td>&nbsp;</td>';
        echo '</tr>';
        echo '<tr>';
            echo '<td>&nbsp;</td>';
            echo '<form action="reply.html.php" method="post"><td align="left" ><textarea rows="5" cols="40" name="reply" id="reply"></textarea>    </td><td valign="baseline"><input type="submit" name="asd" value="REPLY" /><input type="hidden" name="reply" value="reply" /></td></form>';
        echo '  </tr>';
        echo '</table>';        
    }
    echo' CLOSING MAIN FOR ';
?>
</table>

注意1:无法正常工作.当while循环开始时,我注意到它恰好停止了

note 1:not working..I have echoed in various place. What I noticed it exactly stops while the while loop starts

推荐答案

  1. 变量$sql之后,$result在哪里?
  2. $result = mysql_query($sql) **or die(mysql_error)** // to give the output error from MySQL if there is any
  3. while之前,使用var_dump($row)print_r($row).
  4. 如果遇到空白页或没有错误报告,请在脚本开头使用error_reporting(E_ALL);.
  1. After the variable $sql, where is $result?
  2. $result = mysql_query($sql) **or die(mysql_error)** // to give the output error from MySQL if there is any
  3. Before the while, use either var_dump($row), or print_r($row).
  4. If you encounter blank pages or no error reporting, use error_reporting(E_ALL); at he beginning of your script.

对不起,您正在使用MySQLi.使用$mysqli->error.

Sorry, you're using MySQLi. Use $mysqli->error.

这篇关于脚本(while循环)停止,并且具有没有输出时选择了多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:43