Jump to content

Noobie question.. retrieving data from database stuff


potnoodle

Recommended Posts

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

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

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

 

 

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

 

Archived

This topic is now archived and is closed to further replies.

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