2011-07-20 80 views
0

我在我的php页面中使用了内部连接。问题是当我在mysql查询浏览器中启动查询时,它获取近6行。并且都是正确的,但是当我在我的php页面中使用它时,它只能读取一行。这是只有一个值..内部连接问题

while($row=mysql_fetch_array($result1)) 
{ 
while ($resultpoet = mysql_fetch_array($poet)) { 
    ?> 
    <tr> 
     <td><?= $iCounter?> 
      . </td> 
     <td><? if(($row['roman']=="")&&($row['hindi']=="")) { ?> 
      <?=$row['name'] ?> 
      <? } else { ?> 
      <a href="sview.php?title=<?=$row['sid'] ?>"> 
      <?=$row['name'] ?> 
      </a> 
      <? } ?></td> 
     <td width="216"><? 

if($resultpoet['pstatus']!='u') 
print '<a href="pview.php?title='.$resultpoet['pname'].'">'.$resultpoet['pname'].'</a>'; 
else 
print $resultpoet['pname']; 

      ?> 



      </td> 
     <td width="135"><?=$row['category'] ?></td> 
     <td width="67"><a href="songtitle_action.php?title=<?=$row['sid'] ?>"> Edit </a> 
      <input name="check[]" type="checkbox" value="<?=$row[s_id]?>" id="checkbox_<?=$row[sid]?>"></td> 
     <td width="75"><? if(($row['roman']=="")&&($row['hindi']=="")) { ?> 
      <a href="song_add_lyrics.php?title=<?=$row['sid'] ?>"> Add Lyrics</a> 
      <? } ?></td> 
    </tr> 
    <? } 
      $iCounter++; 
     }?> 

回答

2

你只叫mysql_fetch_array一次,所以你只能得到一个行。

您需要改为使用while进行迭代,并为查询返回的每个行执行输出。这是一个非常简单的例子:

$poet= mysql_query("SELECT p.name as pname, p.status as pstatus from poet p INNER JOIN song s ON p.pid=s.pid"); 
while ($resultpoet= mysql_fetch_array($poet)) { 
    if($resultpoet['pstatus']=='u') 
    print '<a href="pview.php?title='.$resultpoet['pname'].'">'.$resultpoet['pname'].'</a>'; 
    else 
    print $resultpoet['pname']; 
} 

退房the documentation for mysql_fetch_array,示例代码阐述了这一原则。

+0

是的,我忘了这么做......正确的..从一个小时以来一直困惑。 – Aditii

+0

因为我在其他while循环中使用它,所以每次外部获取值时,它都会获取该特定列或元组的所有calue组。如何管理两个while循环? – Aditii

+0

只要确保使用不同的变量名称,就可以嵌套while循环。 :) –

2

你必须不断的打电话fetch_array

while ($result = mysql_fetch_array($poet)) 
{ 
    /* do stuff with $result */ 
}