Table and PHP scripts for existing data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron

    #1

    Table and PHP scripts for existing data

    I've been using MySQL for several months and enjoyed great success
    when installing other people's scripts to databses I make using
    phpMyAdmin.

    My challenge is developing from scratch the scripts, for which I've
    got good resources, manuals, and much time into practice and test.

    My question is three-fold, as I have 14,000 records of Security
    Dealers that I want to install in MySQL at www.securitydealers.com

    1) what should my table SQL statement look like for data (sample) as
    follows;

    "John Doe","Managing Partner","BM SECURITIES LTD.","P.O. Box
    201","Grand Cayman","Cayman Islands,"",""," 345--555-5999",

    2) once the table is created inside my database on MySQL, how do I
    load the data in?

    3) what is the best choice of variables, operators and arrays for my
    PHP script, to display only records from a certain city, country,
    company name or Dealer name?
  • Geoff Berrow

    #2
    Re: Table and PHP scripts for existing data

    I noticed that Message-ID:
    <cbc70ed4.04031 10727.2a0625e7@ posting.google. com> from Aaron contained
    the following:
    [color=blue]
    >
    >1) what should my table SQL statement look like for data (sample) as
    >follows;
    >
    > "John Doe","Managing Partner","BM SECURITIES LTD.","P.O. Box
    >201","Grand Cayman","Cayman Islands,"",""," 345--555-5999",[/color]

    You already said you used phpMyAdmin. Set the table up using that. I'd
    include a primary key that is an integer and set it to auto_increment.
    Everything else is a VARCHAR (yes, even the phone number) I'll leave it
    to you to decide what length. What about the two fields with no data?
    What are they for?
    [color=blue]
    >
    >2) once the table is created inside my database on MySQL, how do I
    >load the data in?[/color]

    Assuming the data is a .csv or a .txt file you upload it and then us e a
    scrtipt similar to the one below

    In this case the file is called query1.txt

    # Connect to the database
    mysql_connect(' host',user,pass );

    # Delete the current content of the table
    $result = mysql_db_query( $sql_db,"DELETE FROM $table") or die ("Invalid
    DELETE query");

    # Optimize the current table (recover empty space)
    $result = mysql_db_query( $sql_db,"OPTIMI ZE TABLE $table") or die
    ("Invalid OPTIMIZE query");

    # Load local comma separated, fields enclosed by quotes text database -
    File has to be in the same directory of this file
    $result = mysql_db_query( $sql_db,"LOAD DATA LOCAL INFILE 'query1.txt'
    INTO TABLE $table FIELDS TERMINATED BY ';' ENCLOSED BY ''") or die
    ("Invalid DATA LOAD query");

    # Get how many records are present in the table now
    $result = mysql_db_query( $sql_db,"SELECT * from $table") or die
    ("Invalid SELECT query");
    $rows_count = mysql_num_rows( $result);

    echo "Records: $rows_count"; mysql_free_resu lt($result);

    ?>[color=blue]
    >
    >3) what is the best choice of variables, operators and arrays for my
    >PHP script, to display only records from a certain city, country,
    >company name or Dealer name?[/color]

    I think you need to work your way through a PHP/MySQL tutorial

    Try http://hotwired.lycos.com/webmonkey/99/21/index2a.html
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    Working...