Jump to content

Using php to create a html list


kevin66

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

Link to comment
Share on other sites

$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>';
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

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.