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.. Quote 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 Quote 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... Quote 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 Quote 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>'; ?> Quote 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. Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.