Jump to content

Can't display the assign variable.


MrGarcia

Recommended Posts

i have this code..

 

<?php
include("config.php");
        $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
                while($myrow = mysql_fetch_assoc($result))
             {//begin of loop
               //now print the results:
               echo "<strong>";
               echo $myrow['title'];
               echo "</strong><br>On: <i>";
               echo $myrow['dtime'];
               echo "</i><br><br>";
               echo $myrow['text1'];
               echo "<br>";
               break;
             }//end of loop
?>

 

and i see this code in other site..

 

<?

$position=14; // Define how many character you want to display.

$message="You are now joining over 2000 current";
$post = substr($message, 0, $position);

echo $post;
echo "...";

?>

 

now, i tried to assign my variable $myrow['text1] to $message.

here's now my new code..

 

<?php
include("config.php");
        $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
        $position=14;
        $message=$myrow['text1'];
        $post = substr($message, 0, $position);
                while($myrow = mysql_fetch_assoc($result))
             {//begin of loop
               //now print the results:
               echo "<strong>";
               echo $myrow['title'];
               echo "</strong><br>On: <i>";
               echo $myrow['dtime'];
               echo "</i><br><br>";
               echo $post;
               echo "...";
               echo "<br>";
               break;
             }//end of loop
?>

 

 

it only shows the item inside $myrow['title'] and $myrow['dtime']..

 

but the $post doesn't display anything.. or even shorten the text..

 

can anyone here have alternative way to do this or to get this work..

 

thank you..

Link to comment
Share on other sites

        $message=$myrow['text1'];

In your new code, find that line. thorpe pointed out that the variable $myrow is not defined. That variable is only defined when you started your while loop.

 

oh i see..

so what will i do in able to define it and make it work ??

Link to comment
Share on other sites

i got it..

 

thanks so much thorpe & ken2k7..

 

i have a new problem now..

when im posting a news.. and submit it..

the text has no LINE BREAK or <BR>

 

example..

i submit this news:

 

------------

Welcome to my site.

i hope you like it..

 

thank you.

admin

------------

 

after submitting it..

this is the result:

 

Welcome to my site. i hope you like it.. thank you. admin

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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