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
https://forums.phpfreaks.com/topic/199141-cant-display-the-assign-variable/
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 ??

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

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.