Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: How to import a memo type field to mySQL

  1. #11
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Holy crap. I can't even follow that logically nevermind write code to execute it. I thought this was going to be easier. I'm going to try phpMyAdmin again once I have the data ready. God help me if that doesn't work!

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Imagine this setup: 1,2,3;4,5,6;3,9,0;#,#,#;....

    So you have two levels of repetition: groups of 3 numbers [which is itself a group].

    PHP Code:
    //In order to separate it you use:
    $string '1,2,3;4,5,6;3,9,0;#,#,#;....';
    $split explode(';',$string); //split the entries apart in the data
    foreach($split as $key=>$value) { //go through each entry then
    $split[$key] = explode(',',$value); //split up the entry into its parts
    }
    //now $split is a two-level array-- an array of entries, each of which is an array of items

    //now, to USE this you do:
    foreach($split as $entry) {
    echo 
    $entry[0],$entry[1],$entry[2]; //prints out '123' or '456', '390', ###, ....

    So it's just two layers of arrays: one to hold each entry and one FOR each entry that splits up the data into its parts.


    (Note: this is the reason that databases are nice-- without them everything would be like this when organizing data.)



    Also, be aware that whenever you are doing this level of string parsing, it is CRUCIAL that the data have no errors or inconsistencies. Batch processing will do very unpredictable things when there's even one error in a particularly wrong place. Error-checking is much harder to program, so it's better to make good input than fool-proof code. (Of course it's the opposite if you have users of your website inputting text-- then you must verify. But here you're the only one using it so it should be ok.)



    I hope that clarifies somewhat. If you can get phpmysqladmin to work, great. If not, this is probably your only other option ('this' in the general sense-- using PHP to parse it. You might find another way to split the data).
    Last edited by djr33; 04-16-2010 at 07:50 AM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    kuau (04-16-2010)

  4. #13
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Hey Daniel... After I manipulated the data a bit, I tried the import again and it worked!! Which is a huge relief because from Access I could find no way to specify a record separator and there didn't seem to be one (maybe a CR or LF).

    Anyway, the data is all safe and sound on the server and I can go to bed. Thanks so much for your help. I actually think your for each code may work for doing something I thought was impossible with the data, now that it is accessible. But that is not the priority at the moment. Later...

  5. #14
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    This script will export all the data in your table and also append the date and time of the export to the filename it is generating.

    <?php
    $host = 'localhost';
    $user = 'mysqlUser';
    $pass = 'myUserPass';
    $db = 'myDatabase';
    $table = 'products_info';
    $file = 'export';

    $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
    mysql_select_db($db) or die("Can not connect.");

    $result = mysql_query("SHOW COLUMNS FROM ".$table."");
    $i = 0;
    if (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
    $csv_output .= $row['Field']."; ";
    $i++;
    }
    }
    $csv_output .= "\n";

    $values = mysql_query("SELECT * FROM ".$table."");
    while ($rowr = mysql_fetch_row($values)) {
    for ($j=0;$j<$i;$j++) {
    $csv_output .= $rowr[$j]."; ";
    }
    $csv_output .= "\n";
    }

    $filename = $file."_".date("Y-m-d_H-i",time());
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: csv" . date("Y-m-d") . ".csv");
    header( "Content-disposition: filename=".$filename.".csv");
    print $csv_output;
    exit;
    ?>

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
  •