phpretard Posted March 24, 2009 Share Posted March 24, 2009 I am trying to combine 2 words from a row called key. The row key has 20 entries and all are different words. For example one word in row key is "Green" Anthoer is "Spoon". On a random basis I would like to echo "GreenSpoon" // or any other combination of words The code below only works on one page by itself. I need to include it in another page and when I do it only echos 1 word. <? include ("../db.php"); $EmailKey=mysql_query("SELECT * FROM emailkeys ORDER BY RAND() limit 2"); if (!$EmailKey){die(mysql_error());} WHILE ($row=mysql_fetch_array($EmailKey)){ $key1=$row['key']; echo $key1; } mysql_close($con); ?> Thank you! Link to comment https://forums.phpfreaks.com/topic/150859-solved-code-only-work-when-not-included/ Share on other sites More sharing options...
trq Posted March 24, 2009 Share Posted March 24, 2009 $key1 .= $row['key']; Link to comment https://forums.phpfreaks.com/topic/150859-solved-code-only-work-when-not-included/#findComment-792476 Share on other sites More sharing options...
phpretard Posted March 24, 2009 Author Share Posted March 24, 2009 Why does that work because of a freekin dot???? Link to comment https://forums.phpfreaks.com/topic/150859-solved-code-only-work-when-not-included/#findComment-792477 Share on other sites More sharing options...
trq Posted March 24, 2009 Share Posted March 24, 2009 Because otherwise you simply overiding $key1 with a new word each iteration of your loop. Link to comment https://forums.phpfreaks.com/topic/150859-solved-code-only-work-when-not-included/#findComment-792479 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 LOL .= is short for "add onto" So, $a=$a.' this is added onto the end'; is the same as $a.=' this is added onto the end'; Link to comment https://forums.phpfreaks.com/topic/150859-solved-code-only-work-when-not-included/#findComment-792480 Share on other sites More sharing options...
phpretard Posted March 24, 2009 Author Share Posted March 24, 2009 Thank you! That was painful. Link to comment https://forums.phpfreaks.com/topic/150859-solved-code-only-work-when-not-included/#findComment-792482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.