[SOLVED] Making a text segment a variable for loop.
Posted: Wed Sep 29, 2004 3:48 pm
Hey everyone, new to PHP (and this forum!), and having issues with this, and none of my PHP buddies are online to help me out, so I was hoping someone on here might be able to tell me real quick. I don't think what I'm trying to do is hard. Or maybe it is. At the bottom of the code, there's a chunk that makes a "text segement" for a longtext field in the database. I need to make it so that it is a variable that I can loop.
Can anyone help me format it to a variable that I can loop? Sounds simple to me, but I can't figure it out, but I've only been at PHP for a few weeks, so I'm still trying to figure it all out.
Thanks in advance for any help you can give me!
S
Can anyone help me format it to a variable that I can loop? Sounds simple to me, but I can't figure it out, but I've only been at PHP for a few weeks, so I'm still trying to figure it all out.
Thanks in advance for any help you can give me!
S
Code: Select all
<?php
$username="blood_admin";
$password="*********";
$database="blood_bands";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select databse");
$query="SELECT * FROM stories";
$result=mysql_query($query);
$num=mysql_num_rows($result);
?>
<?
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"name");
$title=mysql_result($result,$i,"title");
$story=mysql_result($result,$i,"story");
?>
<?
$str = "$story";
$no_of_words = 20;
$str_array = split(" ",$str,$no_of_words+1);
if(count($str_array)>$no_of_words) {
for($i=0; $i < $no_of_words; $i++) {
echo $str_array[$i]." "; }
echo "<b>...........(more)</b>";}
?>
<?
$i++;
}
?>