potnoodle Posted March 25, 2007 Share Posted March 25, 2007 I'm new to php so forgive me for asking noobie questions as I don't have my books with me.. How do I modify my current code to allow me to only retrieve a brief part of the content, say this first 600 words or so? $get_information = mysql_query("SELECT * FROM information WHERE category = '1'") or die(mysql_error()); while($information = @mysql_fetch_assoc($get_information)) { $information_title = $information['title']; $information_content = $information['content']; echo "<b>" . $information_title . "</b><br />" . $information_content . "<hr>" ; } Also, how do I put information retrieved from the database into a form? Thanks for your help, greatly appreciated.. Link to comment https://forums.phpfreaks.com/topic/44198-noobie-question-retrieving-data-from-database-stuff/ Share on other sites More sharing options...
tauchai83 Posted March 25, 2007 Share Posted March 25, 2007 maybe in the SQL you use LIMIT to limit the record to 600..or else you may use for loop...for $i=0; $i<600; $i++ here you are using while loop...which will retrieve ALL data that match ur query at once. regards, chai Link to comment https://forums.phpfreaks.com/topic/44198-noobie-question-retrieving-data-from-database-stuff/#findComment-214633 Share on other sites More sharing options...
tauchai83 Posted March 25, 2007 Share Posted March 25, 2007 Oopsss..my bad...do you want 600 first words? sorry for did not see properly...hehe... Link to comment https://forums.phpfreaks.com/topic/44198-noobie-question-retrieving-data-from-database-stuff/#findComment-214636 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 <?php $get_information = mysql_query("SELECT * FROM information WHERE category = '1'") or die(mysql_error()); while($information = @mysql_fetch_assoc($get_information)) { $information_title = $information['title']; $information_content = substr($information['content'], 0, 500) ; echo "<b>" . $information_title . "</b><br />" . $information_content . "<hr>" ; } ?> will do the 500 characters Link to comment https://forums.phpfreaks.com/topic/44198-noobie-question-retrieving-data-from-database-stuff/#findComment-214642 Share on other sites More sharing options...
grimmier Posted March 25, 2007 Share Posted March 25, 2007 <?php $get_information = mysql_query("SELECT * FROM information WHERE category = '1'") or die(mysql_error()); $information = @mysql_fetch_assoc($get_information) $information_title = $information['title']; $information_content = explode(' ',$information['content']) ; $n = 0; echo ($information_title .'<br><br />'); while($n <= 599) { echo $information_content['$n']; $n++; } echo '<hr>'; ?> Link to comment https://forums.phpfreaks.com/topic/44198-noobie-question-retrieving-data-from-database-stuff/#findComment-214742 Share on other sites More sharing options...
JasonLewis Posted March 25, 2007 Share Posted March 25, 2007 grimmier, this: echo $information_content['$n']; can be just this: echo $information_content[$n]; //you dont need ' around it and dont place ( ) around your echo statements. Link to comment https://forums.phpfreaks.com/topic/44198-noobie-question-retrieving-data-from-database-stuff/#findComment-214747 Share on other sites More sharing options...
grimmier Posted March 26, 2007 Share Posted March 26, 2007 my bad, did that while tired. Link to comment https://forums.phpfreaks.com/topic/44198-noobie-question-retrieving-data-from-database-stuff/#findComment-215268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.