PHP MySQL Order list

93

Can anyone help?

My code is like this:

<ol><li>{$student_Value}</li> <ol>'

it gives result:

 1. Student101Name
 1. Student102Name
 1. Student103Name

I want something like:

  1. Student101Name
  2. Student102Name
  3. Student103Name

Please help... Thank you!

38

Answer

Solution:

Do not close the OL tag every time

OL = Ordered List

LI = List item

If you close and reopen the OL, it creates a new ordered list, and so restarting at 1.

<pre>

echo "&lt;ol&gt;";
foreach loop {
echo "&lt;li&gt;{$student_Value}&lt;/li&gt;";
}
echo "&lt;/ol&gt;";

</pre>

Good luck.

775

Answer

Solution:

If you useMySQL to get the data you can addORDER BY to the query to order the result!

Here more info how to use ORDER BY

And change the HTML Code to be:

<ol>
    <li>$student_Value</li>
    <li>$student_Value</li>
    <li>$student_Value</li>
</ol>

PHP Code will be:

echo "<ol>";
echo "   <li> $student_Value </li> ";//write all student values like this
//more student values
echo "</ol>";
525

Answer

Solution:

It looks like your problem is more CSS related than PHP or SQL.

The reason is probably that your output is:

<ol><li>$student_Value</li></ol>
<ol><li>$student_Value</li></ol>
<ol><li>$student_Value</li></ol>

Each student should be a list item within the ordered list:

<?php

print "<ol>";

while ($row = $result->fetch_assoc())
{
    print "<li>{$row['student']}</li>";
}

print "</ol>";

?>
625

Answer

Solution:

You need something like that

<ol>
<?php
   for($i=0; $i<count($studentValue); $i++)
   {
?>
      <li><?php echo $studentValue[$i]; ?></li>
<?php 
   }
?>
<ol>

I am giving you above example to tell you that under a 'ol' tag 'li' must be multiple to get your require result.

People are also looking for solutions to the problem: php - Finding last entity of a joined entity in entityRepository (Symfony2 & Doctrine2)

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.