Hello,

I would like to combine words from different rows in a table into a single string.

from

this
is
what
I
want

to look like

this is what I want

I need the results to be available as a single variable to another part of my script.

Any one like to point me in the right starting direction?

Much appreciated.

    Thanks,

    I think I can get CONCAT_WS() to work to combine different columns in the same row, but can't figure what to do to combine the contents of 1 column from 4 rows into a single string. Does that make any sense?

      At the moment, as far as I've got, is to extract them from the database using a select statement, and echo them out using a do / while loop. But what I really need to do, is make them available as a single string thats assigned to a variable

      as I see it!
      
      SELECT tags FROM store
      
      $alltags = COMBINED results of SELECT STATEMENT SEPERATED WITH A COMMA
      
      

      Hope that makes sense?

        less and less clear, how about posting your current code.

          Sorry!

          OK, this is the code that selects the required data from my database

          mysql_select_db($database_connCMS, $connCMS);
          $query_rsCloud = "SELECT tag FROM tagcloud";
          $rsCloud = mysql_query($query_rsCloud, $connCMS) or die(mysql_error());
          $row_rsCloud = mysql_fetch_assoc($rsCloud);
          

          And then this loop happily spits out the results into the body of the page

          <?php do { ?>
            <div><a href="<?php echo $row_rsCloud['url']; ?>"><?php echo $row_rsCloud['tag']; ?></a></div>
            <?php } while ($row_rsCloud = mysql_fetch_assoc($rsCloud)); ?>
          
            <div>
            <?php do { ?>
              <a href="<?php echo $row_rsCloud['url']; ?>"><?php echo $row_rsCloud['tag']; ?></a>, 
              <?php }?>
            
            </div>
            <?php
             while ($row_rsCloud = mysql_fetch_assoc($rsCloud)); ?> 
            

            The reason they are on a line each is they are each in a div which is a block level element so I re arranged things so they are all in one div. An html issue not a php one.

              Sorry about that. But the html issue wasn't really my issue.

              The issue for me is how to get that data that I can spit out onto the screen, into a single variable in the same format?

              Appreciate your patience.

                for ($i = 1; $i <= 10; $i++) {
                    $moo .= $i.' ';
                }
                echo $moo;
                
                

                result: " 1 2 3 4 5 6 7 8 9 10 "

                  Write a Reply...