SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    295
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    assigning a string to a while loop list

    please i am trying to assign a while loop result to a string so as to be able to send the list in an email, but cant get it, i tried to echo the string $list but the result came back as with only the last row inserted
    PHP Code:
        $pplresult mysql_query("SELECT * FROM repplac");
        while(
    $row mysql_fetch_assoc($pplresult)){
        
    $list $row['Sname'] .$row['Pname'] .$row['Psize'] .$row['Pcolour'] .$row['Pquantity'] .$row['Price'] ;}
        echo 
    "$list";
        die();
        
    // sending email
        
    $to $email;
        
    $subject "YOUR ORDER LIST FROM FINDER";
        
    $headers "From: donotreply@finder.co.uk";
        
    $body "$list";
        
    //send emil
        
    mail($to,$subject,$body,$headers);
        
    $transfer mysql_query("INSERT INTO wishlist SELECT * FROM repplac")or die(mysql_error());
        
    $deletetable mysql_query("DELETE FROM repplac")or die(mysql_error());
        
    redirect_to('youraccount.php'); 

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    // init the string (or use and empty string "")
    $list "My start of string: ";  

       while(
    $row mysql_fetch_assoc($pplresult)){ 

    // concat string with .= (no space between them!)
        
    $list .= $row['Sname'] . ', ' .$row['Pname'] .$row['Psize'] .$row['Pcolour'] .$row['Pquantity'] .$row['Price'] ;



    // does not need quotes to echo it out
        
    echo $list
        die(); 
    Also shows concat . ', ' . to add a comma, space.

    HTH


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •