开发者

Problem with inner join

开发者 https://www.devze.com 2023-03-21 23:31 出处:网络
I have used inner join in my php page. Problem is when I fire query in mysql query browser it fetches nearly 6 rows. and all are correct but when I use same in my php page it fetch only one row. That

I have used inner join in my php page. Problem is when I fire query in mysql query browser it fetches nearly 6 rows. and all are correct but when I use same in my php page it fetch only one row. That is only one value..

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++;
         }?>


You are only calling mysql_fetch_array once, so you only get one row.

You need to instead iterate using while and do your output for each of the rows returned by the query. This is a pretty simplistic example:

$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'];
}

Check out the documentation for mysql_fetch_array, the example code elaborates on this principle.


You have to keep calling fetch_array:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号