Jump to content

Recommended Posts

Hi, I have a chunk of text I am pulling from a mysql db like below.

 

Air conditioning in rooms

24 Hour Reception

Smoking rooms available

 

How can I write this into -

 

<ul>

<li>Air conditioning in rooms</li>

<li>24 Hour Reception</li>

<li>Smoking rooms available</li>

</ul>

 

Many thanks.

Link to comment
https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/
Share on other sites

Thanks so much. I am very new to php, as you have probably figured. I am having trouble getting this to work. This is what I have -

 

<?php

$query = $row['Property_Facilities_General'];

echo '<ul>';

while($result = mysql_fetch_array($query))

{

echo '<li>'.$result['column_name'].'</li>';

}

echo '</ul>';

?>

 

Any ideas?

 

Thank you.

$query should be your actual query where you get the information from the database.

 

<?php
$query = mysql_query("SELECT * FROM table") or die(mysql_error());  \\ use your table names
echo '<ul>';
while($result = mysql_fetch_array($query))
{
echo '<li>'.$result['Property_Facilities_General'].'</li>';
}
echo '</ul>';
?>

Really appreciate your help as I may not have explained this well. The chunk of code below is in one field (not several) called Property_Facilities_General.

 

Air conditioning in rooms

24 Hour Reception

Smoking rooms available

 

Is what I want possible?

 

Thanks.

Yes, attached are screenshots of db. Code I am using is -

 

<?php

// Make a MySQL Connection

mysql_connect("localhost", "???????????", "?????????") or die(mysql_error());

mysql_select_db("dalyanhotels") or die(mysql_error());

 

$query = mysql_query("SELECT * FROM properties") or die(mysql_error());  \\ use your table names

echo '<ul>';

while($result = mysql_fetch_array($query))

{

echo '<li>'.$result['Property_Facilities_General'].'</li>';

}

echo '</ul>';

 

?>

 

At the moment the code kills the whole page and is blank when i use this code.

 

Really appreciate your help.

 

[attachment deleted by admin]

The code is most likely dying 'cause somone has used the wrong slashes for the comment "\\ use your table names"

 

You really should have error reporting set to all in the php.ini file for developing to stop blank pages and show what the errors are.

 

The layout that you are looking for is going to be quite complex to achieve given the dataset in the table.  You are going to need to run a substring select based on the line break character used in your database text field.  It's then going to have to itterate through the full text field and select each new line as a distinct entity to post between the list item tags, this is going to need to be done for every record that you pull from the database.  I personaly would look at restructuring your database tables, as in my opinion what you have is less than optimal.

Having another look at the table you are using, and I am not just saying this to try and upset you, I mean taking it appart and starting again.  Using four or five tables instead of the one that you have now.  It will make things better in the long run.

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.