Domanda

I'm creating an unordered list with PHP. The list is outputting fine, just as expected. However, after every list item, an extra, empty list item appears. I can't figure out why this is happening. There's really nothing else to explain or elaborate on.

Here's the code:

    echo '      <div><ul>';
    $i=0;
    while($i<$length && $i<$amount) {
        do {
            $id = rand(0, $amount-1);
        } while(($priority[$id] > $cur_prior || $used[$id]));

        do { $cur_prior++; } while(!in_array($cur_prior, $priority) && $cur_prior <= max($priority));

        if(!$used[$id]) {
            $cur_views = $views[$id]+1;
            $cur_id = $ids[$id];
            mysql_query("   UPDATE table SET views = '$cur_views'
                            WHERE id = '$cur_id'")
                or die('Database error.');

            $used[$id] = true;

            echo '  <li><a href="'.$ids[$id]).'/'.$url[$id].'" target="_blank">
                        <img src="'.$img['main']['folder'].$img[$id].'?'.time().'" alt="'.$name[$id].'" title="'.$name[$id].'">
                    </a><li>';

            $i++;
        }
    }
    echo '      </ul></div>';

Hope someone can help, thanks :)

È stato utile?

Soluzione

your echo statement doesn't close li, it creates a new li

Try this instead:

echo '  <li><a href="'.ids[$id]).'/'.$aurl[$id].'" target="_blank">
    <img src="'.$img['main']['folder'].$img[$id].'?'.time().'" alt="'.$name[$id].'" title="'.$name[$id].'">
    </a></li>'; // fixed this line

Altri suggerimenti

Your problem is on the

  • echo

    echo '  <li><a href="'.ids[$id]).'/'.$aurl[$id].'" target="_blank">
                        <img src="'.$img['main']['folder'].$img[$id].'?'.time().'" alt="'.$name[$id].'" title="'.$name[$id].'">
                    </a><li>';
    

    you don't close the <li> you have to close it </li>

  • Autorizzato sotto: CC-BY-SA insieme a attribuzione
    Non affiliato a StackOverflow
    scroll top