Jump to content

Converting data into HTML table


kraybrett

Recommended Posts

I am new to coding and working on a website, I have data coming from my data base in this format to my product description area:

 

Length=8 in|Width=0.180 in|Thickness=|Size Group=|Bundle Diam=1.9000 in [Max]|Material=Nylon|Color=Weather Resistant

 

I need to somehow convert the data to this format in an HTML table in the same area:

 

Length 8 in

Width 0.180 in

Thickness

Size Group

Bundle Diam 1.9000 in [Max]

|Material=Nylon

Color=Weather Resistant

 

I know it seems friggin easy, but I am stumped!

 

Any help will be appreciated!

Link to comment
Share on other sites

explode on the |  (pipe). Use foreach to loop over the returned array. In the loop start a new table row (<tr>) and a new table cell (<td>). For the current item use str_replace to replace the = with  </td><td>  after close the table cell (</td>)  and  the table row (</tr>). Code:

$data = 'Length=8 in|Width=0.180 in|Thickness=|Size Group=|Bundle Diam=1.9000 in [Max]|Material=Nylon|Color=Weather Resistant';
echo '<table>';
foreach(explode('|', $data) as $item)
{
   echo '<tr><th>'.str_replace('=', '</th><td>', $item) . '</td></tr>';
}
echo '</table>';
Edited by Ch0cu3r
Link to comment
Share on other sites

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.