-1

TABLE から複数の列を選択したいのですが、while ループが始まるとスクリプトが機能しません。私のphpとhtmlコードは次のとおりです。

<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 ループの開始中に正確に停止することに気付きました

4

2 に答える 2

1
  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);は、スクリプトの先頭で使用してください。

編集: 申し訳ありませんが、MySQLi を使用しています。を使用し$mysqli->errorます。

于 2013-03-30T10:21:26.460 に答える
0

コードの最初の行に開始 PHP タグがありません。そのはず:

<table border="0"><?
于 2015-12-21T08:35:25.357 に答える