Hi

I have been given a task to create some SQL reports.

One of the reports is to display all the customers who have purchased a certain product based on user selection and then have those results able to be extracted to a mailing list.

So ive got the report done. Some drop down boxes allow a user to select a product and once submitted the results are then displayed.

But i dont even know where to begin with extracting those results to a mailing list. Could someone help me please? What method should I use? and where do i begin? Any code would be helpful but i think its more the method of doing this that im after mostly. BTW im a rookie with PHP/Mysql ive just got my first job since leaving university and this is a task ive been given at work so any quick and helpful replies are greatly appreciated 🙂

Thanks in advance.

    you could create an export button that will pass arguments to a page or ajax/jquery that will create a csv file of your results.

    <?php
    function export_excel_csv()
    {
        $conn = mysql_connect("localhost","root","");
        $db = mysql_select_db("database",$conn);
    
    $sql = "SELECT * FROM table";
    $rec = mysql_query($sql) or die (mysql_error());
    
    $num_fields = mysql_num_fields($rec);
    
    for($i = 0; $i < $num_fields; $i++ )
    {
        $header .= mysql_field_name($rec,$i)."\\t";
    }
    
    while($row = mysql_fetch_row($rec))
    {
        $line = '';
        foreach($row as $value)
        {                                           
            if((!isset($value)) || ($value == ""))
            {
                $value = "\\t";
            }
            else
            {
                $value = str_replace( '"' , '""' , $value );
                $value = '"' . $value . '"' . "\\t";
            }
            $line .= $value;
        }
        $data .= trim( $line ) . "\\n";
    }
    
    $data = str_replace("\\r" , "" , $data);
    
    if ($data == "")
    {
        $data = "\\n No Record Found!\n";                       
    }
    
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=reports.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    print "$header\\n$data";
    }
    ?>
    
    

      Hi Busby,

      Not too sure what you are after, but maybe this script can help, if you need me to explain it, just ask 🙂

      <?php
      session_start();

      $id=$_SESSION['user_id'];

      $connect=mysql_connect("localhost","some_user","some_password");

      $select=mysql_select_db("database",$connect);

      $query_users=mysql_query("SELECT * FROM users WHERE id=''$id" );

      while($row=mysql_fetch_array($query_users)){
      $user=$row['username'];
      $has_bought=$row['bought'];
      }

      $emailSubject = 'testemail';
      $webMaster = 'someuser@somedomain.com';

      $firstname = "Website";
      $lastname = "Admin";
      $email = "php@script.com";
      $description = "Test email!";

      $body = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
      'http://www.w3.org/TR/html4/loose.dtd'><html><head>
      <style>
      <!--
      body
      {
      background-color: #000000;
      color: #FFFFFF;
      }
      #mess{
      text-align:center;
      font-size:24px;
      font-family:'Arial Black';
      }
      -->
      </style>
      </head>
      <body>
      <div id='mess'>
      Hello $user,<br /><br />if ($has_bought==true){You are a paid member!}else{click <a href=\"member_buy.html\">Here!</a> to become a member.}</div>
      </div>
      </body>
      </html>
      ";

      $headers = "From: php@script.co.uk\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

      $success = mail($webMaster, $emailSubject, $body, $headers); //<<

      $theResults = <<<EOD
      (Message sent successful, worked!)
      EOD;
      echo "$theResults";
      ?>

      I quickly typed the script up so if there is any errors please ask and i will correct them.

        awbrowni30's script is much better, but i am not too sure if it is too complicated, so if you need i can still explain the script, i posted the script half an hour after so i didnt know awbrowni30 had replied. After looking at awbrowni30's script i realise what you want to do and you will need foreach loops that awbrowni30 provides.

          thanks guys...aw's script helped me a lot and thanks to you too alternate 🙂 got it sorted now

            Write a Reply...