0

I didn´t get an answer yesterday on this question. https://stackoverflow.com/questions/15206351/jquery-slider-with-newest-content-first-gets-reversed-thumbnails-clicking-on-fi

So I tried for a simpler solution. I want to change this code:

$news_countpp = 6;
$result = mysqli_query($con,"SELECT * FROM tbl_news ORDER BY id DESC LIMIT ".($news_page * $news_countpp).", $news_countpp");
while($row = mysqli_fetch_array($result))
{
echo "<div><a href='#".$row['id']."' class='cross-link'><img src='/assets/images/news/news_".$row['id']."_slider_thumb.jpg' alt='".$row['news_img_alt']."'  class='nav-thumb' alt='temp-thumb' style='width:60px; height:40px;'></a></div>";
}

The Part <a href='#".$row['id']." would echo descending numbers from #6 - #1. (newest news hast highest ID) I want the numbers to be ascending instead (not according to the id) than it works.

I tried the following array instead of ".row['id'].":

$thumblink = array ('1', '2', '3', '4', '5', '6');
for ($i = 0; $i < 6; $i++) {
echo $thumblink[$i];
}

But this gives each of my 6 thumbnails the href "123456" instead of ascending numbers from 1 - 6 for the individual thumbnails. Do you know what I do wrong?

4

3 回答 3

1
$news_countpp = 6;
$result = mysqli_query($con,"SELECT * FROM tbl_news ORDER BY id DESC LIMIT ".($news_page * $news_countpp).", $news_countpp");
$i = 1
while($row = mysqli_fetch_array($result))
{
echo "<div><a href='#".$i."' class='cross-link'><img src='/assets/images/news/news_".$row['id']."_slider_thumb.jpg' alt='".$row['news_img_alt']."'  class='nav-thumb' alt='temp-thumb' style='width:60px; height:40px;'></a></div>";
$i++;    
}
于 2013-03-05T09:19:35.540 回答
0

我猜你正在为循环的每次迭代迭代整个数组while。相反,0在循环之前初始化数组和计数器变量while,并且每次迭代只访问一个元素(这样做时将计数器加一)。

于 2013-03-05T09:17:22.727 回答
0

这样的事情怎么样?

$i = 0;
while($row = mysqli_fetch_array($result)) {
  $i++;
  echo 
    "<div>",
      "<a href='#".$row['id']."' class='cross-link'>",
        "<img src='/assets/images/news/news_", $row[$i], "_slider_thumb.jpg'
          alt='".$row['news_img_alt']."'  
          class='nav-thumb' alt='temp-thumb' 
          style='width:60px; height:40px;'>",
      "</a>",
    "</div>";
}
于 2013-03-05T09:21:29.040 回答