Re: Exporting from Multiple mySQL Tables into One - SOLVED!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ave,

I was fiddling my way around with foreach and found a solution to my
problem. Here's my code:

    // define the array
    $tChoice = array(
       "lodispo_osma" => "ATL",
       "lodispo_osmh" => "HOU",
       "lodispo_osmj" => "JAX",
       "lodispo_osmt" => "TPA",
       "lodispo" => "VB",
       "lodispo_hfd" => "HFD"
    );

    // database "definition"
    $def = array(
      array("phone","C", 10),
      array("comments","C", 254),
      array("starttime","C", 10),
      array("endtime","C", 10),
      array("dispo","C", 80),
      array("lo", "C", 50),
      array("verifier", "C", 50),
      array("branch","C",3)
    );
            
    // creation
    if (!dbase_create('dbf/ALL.dbf', $def)) {
      echo "<BR><BR>Error, can't create the database<BR><BR>";
    }
    
                   
    // open in read-write mode
    $db2 = dbase_open("dbf/ALL.dbf", 2);
    if ($db2) {

            // Let's Run Array Loops!
            foreach ($tChoice as $tblQ => $bxQ) {
            
            // connect to mySQL table
            mysql_select_db($database_imslead_transfer, $imslead_transfer);
            $query_loDispo = "SELECT * FROM $tblQ";
            $loDispo = mysql_query($query_loDispo, $imslead_transfer) or
die(mysql_error());
            $row_loDispo = mysql_fetch_assoc($loDispo);
            $totalRows_loDispo = mysql_num_rows($loDispo);
              
            // write mySql data to Dbf
            do {
                 dbase_add_record($db2, array(
                     $row_loDispo['phone'],
                     $row_loDispo['comments'],
                     $row_loDispo['starttime'],
                     $row_loDispo['endtime'],
                     $row_loDispo['dispo'],
                     $row_loDispo['loanofficer'],
                     $row_loDispo['verifier'],
                     $bxQ));
                 } while ($row_loDispo = mysql_fetch_assoc($loDispo));
            }
         
         
    dbase_close($db2);
    }
    
    mysql_free_result($loDispo);
    header("Location: dbf/ALL.dbf");

Works like a charm!

Thanks!

Rahul S. Johari
Supervisor, Internet & Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: rahul@xxxxxxxxxxxxxxxxxxxx
http://www.informed-sources.com



On 1/18/07 11:14 AM, "Rahul S. Johari" <rjohari@xxxxxxxxxxxx> wrote:

> Ave,
> 
> I¹m not sure how to execute this. I can easily write a long, tedious code to
> handle each table separately, but I¹m sure there is an Array/For Each way to
> do this. 
> 
> I¹ve got 6 mySQL tables. I¹ve written a code that dumps data from each table
> into one corresponding DBF table. While writing to the DBF, I also add a
> field & a value to it identifying the table.
> I need to dump data from all the mySQL tables into one DBF table, and also
> have that added field & identifier value added to each table¹s data.
> 
> Here¹s my code to export from 1 mySQL table into 1 DBF table.
> ($tChoice & $bx are Table Name & Identifier Value that are passed on from a
> previous page):
> 
>     // database "definition"
>     $def = array(
>       array("phone","C", 10),
>       array("comments","C", 254),
>       array("starttime","C", 10),
>       array("endtime","C", 10),
>       array("dispo","C", 80),
>       array("lo", "C", 50),
>       array("verifier", "C", 50),
>       array("branch","C",3)
>     );
>             
>     // creation
>     if (!dbase_create('dbf/'.$bx.'.dbf', $def)) {
>       echo "<BR><BR>Error, can't create the database<BR><BR>";
>     }
>                  
>     // open in read-write mode
>     $db2 = dbase_open("dbf/".$bx.".dbf", 2);
>     if ($db2) {
>       
> mysql_select_db($database_imslead_transfer, $imslead_transfer);
> $query_loDispo = "SELECT * FROM $tChoice";
> $loDispo = mysql_query($query_loDispo, $imslead_transfer) or
> die(mysql_error());
> $row_loDispo = mysql_fetch_assoc($loDispo);
> $totalRows_loDispo = mysql_num_rows($loDispo);
> 
>       // write mySql data to Dbf
>       do {
>          dbase_add_record($db2, array(
>              $row_loDispo['phone'],
>              $row_loDispo['comments'],
>              $row_loDispo['starttime'],
>              $row_loDispo['endtime'],
>              $row_loDispo['dispo'],
>              $row_loDispo['loanofficer'],
>              $row_loDispo['verifier'],
>              $bx));
>          } while ($row_loDispo = mysql_fetch_assoc($loDispo));
>          
>     dbase_close($db2);
>     }
>     
>     mysql_free_result($loDispo);
>     header("Location: dbf/$bx.dbf");
> 
> Now I just need to write a code which takes data from each table, one by
> one, and appends it to the DBF, alongwith adding a field that carries the
> Identifier Value for each table.
> 
> Any suggestions?
> 
> Rahul S. Johari
> Supervisor, Internet & Administration
> Informed Marketing Services Inc.
> 500 Federal Street, Suite 201
> Troy NY 12180
> 
> Tel: (518) 687-6700 x154
> Fax: (518) 687-6799
> Email: rahul@xxxxxxxxxxxxxxxxxxxx
> http://www.informed-sources.com
> 
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux