MrGarcia Posted April 20, 2010 Share Posted April 20, 2010 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 More sharing options...
trq Posted April 20, 2010 Share Posted April 20, 2010 Your assigning $myrow['text1'] to $message before $myrow is defined. Move it within the loop. Link to comment https://forums.phpfreaks.com/topic/199141-cant-display-the-assign-variable/#findComment-1045151 Share on other sites More sharing options...
MrGarcia Posted April 20, 2010 Author Share Posted April 20, 2010 what do you mean?? i dont get what you mean.. can you do a sample from a code above.. thank you.. Link to comment https://forums.phpfreaks.com/topic/199141-cant-display-the-assign-variable/#findComment-1045153 Share on other sites More sharing options...
trq Posted April 20, 2010 Share Posted April 20, 2010 $myrow isn't defined where you try to use it, its not defined until two lines afterwoods within the while(). Link to comment https://forums.phpfreaks.com/topic/199141-cant-display-the-assign-variable/#findComment-1045155 Share on other sites More sharing options...
Ken2k7 Posted April 20, 2010 Share Posted April 20, 2010 $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. Link to comment https://forums.phpfreaks.com/topic/199141-cant-display-the-assign-variable/#findComment-1045157 Share on other sites More sharing options...
MrGarcia Posted April 20, 2010 Author Share Posted April 20, 2010 $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 https://forums.phpfreaks.com/topic/199141-cant-display-the-assign-variable/#findComment-1045160 Share on other sites More sharing options...
Ken2k7 Posted April 20, 2010 Share Posted April 20, 2010 oh i see.. so what will i do in able to define it and make it work ?? Please re-read all of thorpe's post. He already told you what to do twice to solve this issue. Link to comment https://forums.phpfreaks.com/topic/199141-cant-display-the-assign-variable/#findComment-1045164 Share on other sites More sharing options...
MrGarcia Posted April 20, 2010 Author Share Posted April 20, 2010 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 https://forums.phpfreaks.com/topic/199141-cant-display-the-assign-variable/#findComment-1045170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.