Jump to content

How to rendering different markup for each record from mysql select?


thara

Recommended Posts

I have a set of items to select from mysql. And then I want to display these items on my page with different 'markup`.

This is how my HTML look like for each item.

    <ul class='unstyled main-facilities row'>
        <li class='info-facility-item '>
            <span class='fa-stack'>
                <i class='fa fa-square fa-stack-2x'></i>
                <i class='fa fa fa-cutlery fa-stack-1x fa-inverse'></i>
            </span> Item-01
        </li>
        <li class='info-facility-item '>
            <span class='fa-stack'>
                <i class='fa fa-square fa-stack-2x'></i>
                <i class='fa fa fa-rss fa-stack-1x fa-inverse'></i>
            </span> Item-02
        </li>
        <li class='info-facility-item '>
            <span class='fa-stack'>
                <i class='fa fa-square fa-stack-2x'></i>
                <i class='fa fa-refresh fa-stack-1x fa-inverse'></i>
            </span> Item-03
        </li>
        ...
        ...
        ...
        
    </ul>

If I have same markup for each item, then I can do it like this:

    // Fetch all the records:
    while ($stmt->fetch()) {
    
        $result  = "<li class='info-facility-item '>\n";
        $result .= "    <span class='fa-stack'>\n";
        $result .= "        <i class='fa fa-square fa-stack-2x'></i>\n";
        $result .= "        <i class='fa fa fa-rss fa-stack-1x fa-inverse'></i>\n";
        $result .= "    </span>{$item}\n";
        $result .= "</li>\n";
        $items[] = $result;     
        }            
    }  

But I am not sure how to modify my `while` loop to render different markup for each item.

Can anybody tell me is there a way to do this in PHP?

Thank you.

How would you, as a human, know what to change about the markup? How do you know which item gets two fas (really?) or whether it should be called "cutlery" or "rss" or "refresh"?

 

Once you have that answered it shouldn't be hard to make the code do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.