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.. Quote Link to comment 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. Quote Link to comment 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.. Quote Link to comment 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(). Quote Link to comment 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. Quote Link to comment 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 ?? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.