2013-03-09 73 views
0

怎麼來的,當我使用此代碼:PHP只能選擇一個條目顯示

$emailc = '[email protected]_classes'; 
$emaila = '[email protected]_assignments'; 
$emailp = '[email protected]_projects'; 

$resulty = mysqli_query($con,"SELECT * FROM `$emailc` ORDER BY period"); if (!$result) echo mysqli_error(); else // ok, do your thing. 
$resulti = mysqli_query($con,"SELECT * FROM `$emaila` ORDER BY duehw"); if (!$result) echo mysqli_error(); else // ok, do your thing. 
$resulto = mysqli_query($con,"SELECT * FROM `$emailp` ORDER BY dueproj"); if (!$result) echo mysqli_error(); else // ok, do your thing. 

$classcount = 1; 


while($row = mysqli_fetch_array($resulty)) 
    { 

    $period = $row['period']; 
    $teacher = $row['teacher']; 
    $subject = $row['subject']; 
    $subjecto = strtolower($subject); 
    $subjecto = str_replace(' ', '', $subjecto); 
    $grade = $rowy['grade']; 

    echo "<section id='" . $subjecto . "'> \n"; 
    echo "<p class='title'>" . $subject . "</p> \n"; 
    echo "<a style='cursor:pointer;' onclick='homework" . $classcount . "()'>Homework&nbsp;</a>|<a style='cursor:pointer;' onclick='projects" . $classcount . "()'>&nbsp;Projects</a> \n"; 
    echo "<div id='homework" . $classcount . "'><br /><a onclick='addassignment()'>Add Assignment</a><br />"; 
    echo "<table class='homework'>"; 
    echo "<tr>"; 
    echo "<th class='title'>"; 
    echo "Title"; 
    echo "</th>"; 
    echo "<th class='duedate'>"; 
    echo "Due Date"; 
    echo "</th>"; 
    echo "</tr>"; 

    while($row = mysqli_fetch_array($resulti)) 
    { 

     $subjecthw = $row['subjecthw']; 
     $namehw = $row['namehw']; 
     $duehw = $row['duehw']; 

     echo "<tr>"; 
     echo "<td class='title'>"; 
     echo $namehw; 
     echo "</td>"; 
     echo "<td class='duedate'>March "; 
     echo $duehw; 
     echo "</td>"; 
     echo "</tr>"; 

    } 

    echo "</table>"; 
    echo "</div> \n"; 
    echo "<div id='projects" . $classcount . "'><br /><a onclick='addassignment()'>Add Assignment</a><br />"; 
    echo "<table class='homework'>"; 
    echo "<tr>"; 
    echo "<th class='title'>"; 
    echo "Title"; 
    echo "</th>"; 
    echo "<th class='duedate'>"; 
    echo "Due Date"; 
    echo "</th>"; 
    echo "</tr>"; 

    while($row = mysqli_fetch_array($resulto)) 
    { 

     $subjectproj = $row['subjectproj']; 
     $nameproj = $row['nameproj']; 
     $dueproj = $row['dueproj']; 

     echo "<tr>"; 
     echo "<td class='title'>"; 
     echo $nameproj; 
     echo "</td>"; 
     echo "<td class='duedate'>March "; 
     echo $dueproj; 
     echo "</td>"; 
     echo "</tr>"; 

    } 

    echo "</table>"; 
    echo "</div> \n"; 
    echo "</section> \n"; 

    $classcount += 1; 

    } 

我只得到了硬件和凸出的一個部分。我做錯了嗎?謝謝!我知道它可能永遠不會工作,但我該如何解決它?我有3個表格,我需要從它們中獲取數據。

+0

你爲什麼要讓你的服務器如此努力工作以讓PHP回聲靜態元素? – 2013-03-09 02:04:22

+0

他們是動態的,從分區 – 2013-03-09 02:37:13

+0

似乎代碼是絕對好的,但想知道如何在DB中的腸炎... – Vineet1982 2013-03-09 02:58:05

回答

0

請勿在while循環內使用$row

e.g

while($row = mysql_fetch_row($resulti)){ 
    while($row2 = mysql_fetch_row($resulto)){ 

    } 
} 

也沒有時間去通過代碼,但它從來沒有在一個循環中運行SQL是一個好主意。

相關問題