kevin66 Posted April 14, 2011 Share Posted April 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/ Share on other sites More sharing options...
doddsey_65 Posted April 14, 2011 Share Posted April 14, 2011 you would use a while loop: echo '<ul>'; while($result = mysql_fetch_array($query)) { echo '<li>'.$result['column_name'].'</li>'; } echo '</ul>'; Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201500 Share on other sites More sharing options...
kevin66 Posted April 14, 2011 Author Share Posted April 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201514 Share on other sites More sharing options...
doddsey_65 Posted April 14, 2011 Share Posted April 14, 2011 $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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201532 Share on other sites More sharing options...
kevin66 Posted April 14, 2011 Author Share Posted April 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201652 Share on other sites More sharing options...
doddsey_65 Posted April 14, 2011 Share Posted April 14, 2011 can you show how your table is set up? what is the name of the database table? Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201655 Share on other sites More sharing options...
kevin66 Posted April 15, 2011 Author Share Posted April 15, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201923 Share on other sites More sharing options...
Muddy_Funster Posted April 15, 2011 Share Posted April 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201947 Share on other sites More sharing options...
kevin66 Posted April 15, 2011 Author Share Posted April 15, 2011 Thanks for the info. When you say restructing the table, what do you mean? The other fields are OK as I just use the whole chunk. Just this one I want to write as a list. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201957 Share on other sites More sharing options...
Muddy_Funster Posted April 15, 2011 Share Posted April 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201962 Share on other sites More sharing options...
kevin66 Posted April 15, 2011 Author Share Posted April 15, 2011 I understand now. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/233704-using-php-to-create-a-html-list/#findComment-1201964 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.