Jump to content

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


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.

Edited by thara

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.