dousou2897 2013-05-11 00:52
浏览 59
已采纳

虽然循环:工作,但也循环HTML并输出两次(一次反向?)

I have a while loop. It is supposed to loop through the database table and output the results found, which it does fine. However, it also duplicates the HTML in the while loop (outputting it twice, once in reverse??).

SEE:

1) Jazzminder Soundscape 2) 3) 1) 2) Jazzminder Dandelion 3)

SHOULD READ:

1) Jazzminder Soundscape 2) Jazzminder Dandelion 3)

I've tried tweaking and rewriting the code, but I can't isolate the problem. I've not had this problem before.

This is the block of code:

 <p> <a href="promote_next_step.php?promote=<?php echo $_GET['promote']?>">
<strong>        [More To Next Step]</strong></a></p>
<strong><font color="gray">Included so far:</font></strong><br/>

<?php 
  $sql2="SELECT * FROM `promote_track_lists` WHERE `promo_title`='".     $_GET['promote1']."'";
  $result2=mysql_query($sql2);
  while($row2 = mysql_fetch_assoc($result2)){
?>
  1) <font color="orange"><strong><?php echo $row2['artist_name1'] ?> <?php echo     $row2['track_title1'] ?></strong></font>
  2) <font color="orange"><strong><?php echo $row2['artist_name2'] ?> <?php echo     $row2['track_title2'] ?></strong></font>
  3) <font color="orange"><strong><?php echo $row2['artist_name3'] ?> <?php echo     $row2['track_title3'] ?></strong></font>

<?php 
  }
?>

Thanks for the replies!! The thing is, I have another page which pulls the information from the database just fine:

  if (isset ($_GET['promote1']) === true) {
  $sql3="SELECT * FROM `promote_track_lists` where `promo_title`    ='".$_GET['promote1']."' "; 
  $result3= mysql_query ($sql3);
 while ($row3 = mysql_fetch_assoc ($result3)) {   
 ?>
              <div id="promotion_files">
              <!------- track1 ------->
               <?php  if ($row3['iframe1']) {?>
                <div class="promotion_track_name"><strong><?php echo     $row3['artist_name1'] ?>-<?php echo $row3['track_title1'] ?></strong></div>
                <?php echo $row3['iframe1']?>
                <?php
                if (isset ($_POST['submit'])===true && empty     ($_POST['feedback']) === false) {
                ?>
                <a href="mp3_download.php?promote1=<?php echo     $row['title'] ?>"><img src='images/design images/iPodDownload.png' /></a>
                <?php
                }
                }
            ?>
                           <!------- track2 -------> 

It does this 20 times without problem, but for some reason on the other page it loops over the HTML and outputs (just the html) twice. I've tried to work the database so that entries are completely unique from one another, but so that everything can be pulled with one query. ...If that makes sense.

  • 写回答

2条回答 默认 最新

  • duananyantan04633 2013-05-11 01:16
    关注

    I'm going to take a stab at this but I could be wrong without the complete code. my guess is the problem is with your MySQL. according to what you are trying to output. one record would look like this

    artist_name1 | artist_name2 | artist_name3 | track_title1 | track_title2 | track_title3

    but based on what you are stating is the way your output is displaying, more than likely your table looks like this artist_name | track_title

    can you show me what your table looks like?

    fyi it's not showing things in reverse, it's showing all 3 line 3 times but your only seeing one set of values each time. so your seeing 1 -data- 2 3 then 1 2 -data- 3 then 1 2 3 -data- I hope that makes sense

    so looking at your image and the additional code you posted, I noticed this condition on the second block of code that isn't in your first block of code.

                <?php  if ($row3['iframe1']) {?>
    

    so my question for you is this. in your database if iframe2 is blank. is artist2 blank? if this is the case and based on what you described in your original email it looks like artist1 title1 and iframe1 all contains values but the rest of the values for that row is blank and in the next record in your table artist2 title2 and iframe2 is filled and the rest of the fields are blank and the same is true for the third.... IF this is the case then you need to do the following to your while loop...

    while($row2 = mysql_fetch_assoc($result2)){
         if ($row2['iframe1']) {?>
      1) <font color="orange"><strong><?php echo $row2['artist_name1'] ?> <?php echo     $row2['track_title1'] ?></strong></font>
      <?php  else if ($row2['iframe2']) {?>
      2) <font color="orange"><strong><?php echo $row2['artist_name2'] ?> <?php echo     $row2['track_title2'] ?></strong></font>
      <?php else if ($row2['iframe3']) {?>
    
      3) <font color="orange"><strong><?php echo $row2['artist_name3'] ?> <?php echo     $row2['track_title3'] ?></strong></font>
      <?php }
    

    } ?>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题