Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:55:05+00:00 2026-06-05T01:55:05+00:00

I want to display my database records in <ul> <li> format. I have using

  • 0

I want to display my database records in <ul> <li> format. I have using a free template to design my front end. I am reading database data like this

while ($row = mysql_fetch_assoc($result)) {
    $categoryname = $row['category_name'];
}

and within the loop i have to display records like this

<li class="odd"><a href="services.html">Processors</a></li>
         <li class="even"><a href="services.html">Motherboards</a></li>
        <li class="odd"><a href="1_service.html">Processors</a></li>
        <li class="even"><a href="2_services.html">Motherboards</a></li>
         <li class="odd"><a href="3_services.html">Desktops</a></li>
        <li class="even"><a href="4_services.html">Laptops & Notebooks</a></li>
         <li class="odd"><a href="5_services.html">Processors</a></li>
         <li class="even"><a href="6_services.html">Motherboards</a></li>
        </ul>

How to do like this. Please suggest

if i want to give seperate page link to each lik like this

<li class="odd"><a href="services.html">Processors</a></li>
         <li class="even"><a href="services.html">Motherboards</a></li>
        <li class="odd"><a href="services.html">Processors</a></li>
        <li class="even"><a href="services.html">Motherboards</a></li>
         <li class="odd"><a href="services.html">Desktops</a></li>
        <li class="even"><a href="services.html">Laptops & Notebooks</a></li>
         <li class="odd"><a href="services.html">Processors</a></li>
         <li class="even"><a href="services.html">Motherboards</a></li>
        </ul>

then how to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:55:07+00:00Added an answer on June 5, 2026 at 1:55 am

    You’ll need to watch the iteration to tell if you’re on an even or odd cycle:

    $output  = "";
    $counter = -1;
    
    while ( $row = mysql_fetch_assoc( $result ) ) {
      $class = $counter++ % 2 === 0 ? "even" : "odd" ;
      $href  = $row["category_url"];
      $text  = $row["category_name"];
      $output .= "<li class='{$class}'><a href='foo?id={$href}'>{$text}</a></li>";
    }
    
    echo "<ul>{$output}</ul>";
    

    Native CSS Solution

    Determining which elements are odd, and which are even is something that doesn’t necessarily need to be done with PHP. In fact, it doesn’t really require adding a classname to style each list item. CSS has a fancy selector, :nth-child(n), that can handle this for you:

    li:nth-child(even) {
        background: #f1f1f1;
        color: #CCC;
    }
    

    Demo: http://jsfiddle.net/rquXK/

    This means you can avoid determining the value of $class, and move that logic instead to your CSS. Just keep in mind that some older browsers won’t support the feature.

    Support Tables: http://caniuse.com/#feat=css-sel3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to have function like delete file from database by using link instead
I have a sample database like below, and I want to display only the
I'm using a datagridview to display the records of a database. I also have
I want display data from database in Listbox...Here is my code, It is not
I want to display data from database in DataGridView...This is my code...Its not working...Can
I want to display data feed from an external database in a sidebar in
Using VB.NET I want to display the date in datetimepicker from the database. Code.
I want to pull data from a database to display into a ComboBox, and
I'm trying to display data from a database and I want to know what
I have a database of map points, and I want to limit the display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.