maliary Posted July 13, 2007 Share Posted July 13, 2007 Hi guys, I've the following information that I retrive from the database : 1.The little fox jumped over a green hedge.2.The hare ate fish.3.The little fox jumped over a green hedge 4.Alligator jumped a green hedge.5.The little fox jumped over a green hedge How would I display it thus : 1.The little fox jumped over a green hedge 2.The hare ate fish 3.The little fox jumped over a green hedge 4.Alligator jumped a green hedge. 5.The little fox jumped over a green hedge Quote Link to comment Share on other sites More sharing options...
hackerkts Posted July 13, 2007 Share Posted July 13, 2007 How was your database structured? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 add <br> after each fetch! total guess req. more info! Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 <?php $string = "1.The little fox jumped over a green hedge.2.The hare ate fish.3.The little fox jumped over a green hedge4.Alligator jumped a green hedge.5.The little fox jumped over a green hedge"; print preg_replace("([2-100])","<br>\\0",$string); ?> Does this help? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 or <?php $string = "1.The little fox jumped over a green hedge.2.The hare ate fish.3.The little fox jumped over a green hedge4.Alligator jumped a green hedge.5.The little fox jumped over a green hedge"; print $result = preg_replace('/(?<=.+)(\d\.)/i', "\r\n\$1", $string); ?> Quote Link to comment Share on other sites More sharing options...
maliary Posted July 13, 2007 Author Share Posted July 13, 2007 Ok, The notes field in the database is of datatype text. $depts = $db->Execute("SELECT * FROM test_find WHERE job_id='$batch_nr'"); while($row= $depts->FetchRow()){ $notes = $row['notes']; } <td><?php echo $notes; ?></td> This gives the following out put : 1.The little fox jumped over a green hedge.2.The hare ate fish.3.The little fox jumped over a green hedge 4.Alligator jumped a green hedge.5.The little fox jumped over a green hedge Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 try <?php $depts = $db->Execute("SELECT * FROM test_find WHERE job_id='$batch_nr'"); while($row= $depts->FetchRow()){ $notes = $row['notes']."<br>"; } ?> <td><?php echo $notes; ?></td> Quote Link to comment Share on other sites More sharing options...
maliary Posted July 13, 2007 Author Share Posted July 13, 2007 Thanks, But the output is still jumbled up. How can I display the beginning and end of a sentence? To distinguish diffrent sentences? Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 Thanks, But the output is still jumbled up. How can I display the beginning and end of a sentence? To distinguish diffrent sentences? Use MadTechie's preg_match expression. Quote Link to comment Share on other sites More sharing options...
maliary Posted July 13, 2007 Author Share Posted July 13, 2007 You mean preg_replace() ? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 This should be fine.. define "jumbled up".. try <?php $depts = $db->Execute("SELECT * FROM test_find WHERE job_id='$batch_nr'"); while($row= $depts->FetchRow()){ $notes = $row['notes']."<br>"; } ?> <td><?php echo $notes; ?></td> maybe a more complete code!? ie the full table setup (HTML table) Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 You mean preg_replace() ? Yes. Is your output all one one line, and you want to break up each point (1. One2. Two3. Three) into 1. One 2. Two 3. Three ? I'm very unclear. Quote Link to comment Share on other sites More sharing options...
maliary Posted July 16, 2007 Author Share Posted July 16, 2007 1. Yes, I want to break up the out put that way as in: 1.One 2.Two 3.Three I've realised that, If I out put the data from the database in a text area, if formats itself fine,Without using any functions. What's wrong with the <td></td> tags then? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 16, 2007 Share Posted July 16, 2007 If it's ok in a text area then echo nl2br($notes); Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 16, 2007 Share Posted July 16, 2007 What's wrong with the <td></td> tags then? Nothing but you need to start a table first Quote Link to comment Share on other sites More sharing options...
maliary Posted July 18, 2007 Author Share Posted July 18, 2007 This worked. Thanks. If it's ok in a text area then echo nl2br($notes); Quote Link to comment 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.