oceanv5 Posted May 21, 2010 Share Posted May 21, 2010 Hi so I'm trying to get a string of letters to print: abdfgkerhwkjhkwjher as the result of a query for each letter's ID. it looks like this in the database: n3_1, a n3_2, b n3_3, d and so on... $num3 = mysql_query("SELECT * FROM segment WHERE id LIKE 'n3%' ") or die(mysql_error()); while($row = mysql_fetch_array( $num3 )) { $number3 = $row['base']; echo $number3; } This shows the string from the column "base" fine. so I get "abdfgkerhwkjhkwjher" However, when I try to query outside the php header code Blah: <?php echo $number3 ?><br> I only get the last letter of the string of letters so it prints Blah: r instead of Blah: abdfgkerhwkjhkwjher Any idea what could be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/ Share on other sites More sharing options...
premiso Posted May 21, 2010 Share Posted May 21, 2010 while($row = mysql_fetch_array( $num3 )) { $number3 .= $row['base']; } echo $number3; You have to concatenate the value in order to achieve that. Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061775 Share on other sites More sharing options...
oceanv5 Posted May 21, 2010 Author Share Posted May 21, 2010 Sweet thank you so much!!! Is there anywhere I can find out the theory behind this? Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061777 Share on other sites More sharing options...
oceanv5 Posted May 21, 2010 Author Share Posted May 21, 2010 Actually I have an additional question-- When the string of letters prints, instead of breaking at the end of the DIV or even at the browser it just continues as a long unbroken string... instead of RGQERGREGERGERGERGERGJUTWEONHEI it should be like RQHIEWRHEWR WERWERWERWE WERWERWEWWE within the contstraints. But I can't put <BR>s because they is coming from the database and I have no idea where the line should break. Any solutions? Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061781 Share on other sites More sharing options...
kenrbnsn Posted May 21, 2010 Share Posted May 21, 2010 So you want to split the character string every 11 characters? Do something like this: <?php while($row = mysql_fetch_array( $num3 )) { $number3 .= $row['base']; } echo implode("<br>\n",str_split($number3,11)); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061783 Share on other sites More sharing options...
oceanv5 Posted May 21, 2010 Author Share Posted May 21, 2010 No, that was an example, is there any way to have the string split in accordance with the space available not the characters? (linebreak) I am producing something like this CONSTANT [variable] CONSTANT [variable] CONSTANT CONSTANT [variable] and all the variables aren't the same length (using javascript to modify to variables). Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061784 Share on other sites More sharing options...
Mchl Posted May 21, 2010 Share Posted May 21, 2010 nl2br ? Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061790 Share on other sites More sharing options...
oceanv5 Posted May 21, 2010 Author Share Posted May 21, 2010 <?php echo $number3 ?> with n2blr? how? Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061803 Share on other sites More sharing options...
Mchl Posted May 21, 2010 Share Posted May 21, 2010 <?php echo nl2br($number3) ?> Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061808 Share on other sites More sharing options...
oceanv5 Posted May 21, 2010 Author Share Posted May 21, 2010 Hi, Still doesn't work and shows up as a long broken unstring, despite the <?php echo nl2br($number3); ?> Quote Link to comment https://forums.phpfreaks.com/topic/202540-mysql-query-string-doesnt-work/#findComment-1061810 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.