tags:

views:

83

answers:

2

I have to split a field with an abundance of text into 2 variables, display one in one section of the page and then carry on with the remainder of the field in another spot. Any ideas?

Edit:

Thanks for the input. I have no delimiter available as the user inputs the text via FCKeditor..is it possible to get the length of the inputted text, insert a special character and then use as a delimiter? It is presented as a story, with one page having a certain height and the other page continuing the story much like a book. Here's what the query looks like:

    $query = "select * from tablename";
$result = mysql_query($query) or die(mysql_error());
$num_results = mysql_num_rows($result);
if ($num_results !="0")
{

    echo "<table class='style1'>";
    echo "<tr>";
    echo "<td>";
    for ($i=0;$i<$num_results;$i++)
    {
        $row = mysql_fetch_array($result);
        $description = stripslashes($row['description']);
        echo $description;
    }
    echo "</td>";
    echo "</tr>";
    echo "</table>";

}
A: 

Depending on the exact requirements, either explode() or substr() should satisfy your needs.

tdammers
A: 
$sql = mysql_query($query);
$sql = mysql_fetch_array($sql);

$data = explode($delimiter,$sql["field"]);

echo $data[0];

...

echo $data[1];

Something like this?

Webarto
You're missing `$` signs for `$data[0];` and `$data[1];`, and, it may be appropriate to use, `explode($delimiter, $sql["field"], 2);` so as to guarantee no more than 2 elements in `$data`.... though it's hard to tell from the question if using the limit would be helpful.
Peter Ajtai
I edited it, though I'm pretty sure I typed it :\An example text would be nice, for now this is just a guess.
Webarto