2011-05-30 50 views
0

我想做出7個下拉列表,最後5個有相同的內容,現在我的問題是,第三個顯示所有的內容,但其餘(4,5,6,7)只顯示「選擇電影」。 下面是代碼:如何在表單中添加相同的下拉列表5次?

@$pro=$_GET['pro']; 
if(strlen($pro) > 0 and !is_numeric($pro)){/
    echo "Data Error"; 
    exit; 
} 
$quer=mysql_query('SELECT DISTINCT programName,programId FROM '.TBL_PROGRAM.' order by programId'); 
if(isset($pro) and strlen($pro) > 0){ 
    $quer2=mysql_query("SELECT DISTINCT categorieName,id FROM ".TBL_CATEGORIE."where id=$pro order by id"); 
    }else{ 
    $quer2=mysql_query("SELECT DISTINCT categorieName,id FROM ".TBL_CATEGORIE." order by id"); 
    } 
if(isset($pro) and strlen($pro) > 0){ 
    $quer3=mysql_query("SELECT DISTINCT movieName,movieId FROM ".TBL_MOVIE." where movieId=$pro order by movieId"); 
    }else{ 
    $quer3=mysql_query("SELECT DISTINCT movieName,movieId FROM ".TBL_MOVIE." order by movieId"); 
    } 
echo "<form method=POST name=f1 action='program.php'>"; 
    echo "<select name='pro[]' style='width:150' onchange=\"reload(this.form)\"><option value=''>Make your Program</option>"; 
    while($noticia = mysql_fetch_array($quer)) { 
     if($noticia['programId'][email protected]$pro) 
     { 
      echo "<option selected value='$noticia[programId]'>$noticia[programName]</option>"."<BR>";} 
     else{ 
     echo "<option value='$noticia[programId]'>$noticia[programName]</option>";} 
     } 
    echo "</select>"; 
    echo "<BR>"; 
    echo "<select name='pro[]' style='width:150' onchange=\"reload3(this.form)\"><option value=''>Choose Categorie</option>"; 
    while($noticia2 = mysql_fetch_array($quer2)) { 
    if($noticia2['id'][email protected]$pro) 
    { 
     echo "<option selected value='$noticia2[id]'>$noticia2[categorieName]</option>"."<BR>";} 
    else{ 
     echo "<option value='$noticia2[id]'>$noticia2[categorieName]</option>";} 
    } 
    echo "</select>"; 
    echo "<BR>"; 
    $i=0; 
    while($i<5){ 
     echo "<select name='pro[]' style='width:150' ><option value=''>Select movie</option>"; 

     while($noticia3 = mysql_fetch_array($quer3)) { 

     echo "<option value='$noticia3[movieId]'>$noticia3[movieName]</option> "; 

    } 
    echo "</select>"; 
    echo "<BR>"; 
    $i++; 
    } 
echo"<input type=hidden name=submit value=1>"; 
echo "<input type=submit value=Submit>"; 
echo "</form>"; 
?> 

任何意見,任何其他方法welcome.Thank你。

回答

0

一旦你從mysql結果中獲取記錄,它將它的位置移動到下一行...在第一個循環結束時,位置將保持在記錄狀態的結尾所以從第二次循環它只會打印空白。

因此,更好地: 1)保存串 2.選項列表)打印循環

的列表,而不是使用:

$i=0; 
$strOptions = ''; 
while($noticia3 = mysql_fetch_array($quer3)) { 

    $strOptions .= "<option value='$noticia3[movieId]'>$noticia3[movieName]</option>"; 

} 
while($i<5){ 
    echo "<select name='pro[]' style='width:150' ><option value=''>Select movie</option>"; 
    echo $strOptions; 
    echo "</select>"; 
    echo "<BR>"; 
    $i++; 
} 
+0

謝謝you.It workes。 – user747192 2011-05-30 17:26:36

0
while($noticia3 = mysql_fetch_array($quer3)) { 

這將通過您的$i < 5 while循環獲取所有從$quer3在第一次的結果。所以當$ i = 0時,你打印出所有的查詢結果。然後i = 1出現,並且沒有更多結果行。相同的i = 2,i = 3等...

相關問題