Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    c q
    c q is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php and mySQL functions.....

    heyy !!!
    I ws wondering how to create a mySQL database that has a table with say 5 fields. Out of which some fields themselves contain another table. I sort of looked thru the manual, but I'm still confused.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    This belongs in the MySQL forum as mentioned in the Must Read thread at the top of this forum. I'll move it there....
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    c q
    c q is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    uhh ohh I think I forgot to add.....I'd llike to be using php to do this...

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You can't create database and tables with PHP. SQL is what is used to create it. PHP just makes the connection to MySQL and sends the commnads to MySQL.

    Easiest way to do this is once again to use phpMyAdmin. It's a graphical tool so no need to learn SQL to create the database or tables.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    c q
    c q is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    arre....this is news to me.
    coz when I ws installing mySQL on my system, I followed a tutorial tht gave me this code....

    <h3> Press RELOAD to add a record to the MySQL database:</h3>
    <?
    //establish user connection
    mysql_connect("localhost");
    //open up database
    mysql_create_db("testdatabase");
    mysql_select_db("testdatabase");
    //create table
    mysql_query("CREATE TABLE newone(firstName VARCHAR(25),lastName VARCHAR(25))");
    mysql_query ("INSERT INTO newone (firstName, lastName) VALUES ('Amir', 'Khan')");
    //display the information
    $result = mysql_query ("SELECT * FROM newone");
    while($row = mysql_fetch_array($result))
    {
    print ("Added record: " . $row["firstName"]." ".$row["lastName"]." <br>\n");
    }
    //close user connection
    mysql_close();
    ?>

    now that sort of made me believe that php can as well create a table.
    ok anyhow methinks that phpmyAdmin is much simpler and lot quicker

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    PHP doesn't create tables. All PHP does is send a command to MySQl whom which then creates the tables. So all PHP is doing is passing messages.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    c q
    c q is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okie....getting my phpmyadmin right now....the link aparently is www.phpmyadmin.net
    thanx for the help ...

  • #8
    c q
    c q is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    awwp

    hmm....again that myadmin is not really helping me...
    made a nice database alright, and a table with 3 pretty fields.
    I cant make out how I can create a "field" which contains an array. Is it possible in the first place ?
    wht i really need is a field that'll store a list of items I will access later. so if I have ten entries in the table, each of those ten entries will have a list corresponding to them....dunno how to proceed.

  • #9
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It depends on how you want to use your data.

    You could have a field which stores contents such as "6,2,9,2,4,7" which could be an array, but it depends on if that will work for you or now.

    Or, make another new table for your array, and link the two tables with ID numbers. Are you familiar with database normalization and joining tables?

  • #10
    c q
    c q is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well....I only recently started reading up on databases.
    I'm trying to build me own little CBT; roughly sketched, I can say here's wht the fields look like...
    id | word | meaning | synonyms | antonyms
    the last 2 fields synonyms and antonyms need to be arrays.
    becoz when compiling my questions, I will randomly select any antonym corresoinding to the already selected word.
    that about summarises my plan

  • #11
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, well then in the database, separate multiple words (the synonyms and antonyms) with commas in their DB field.

    Then read the values out of the database and into a variable, so the long string of synonyms get put into a variable $synonyms lets just say.

    Then, if you are using PHP, you can turn the comma separated words in the $synonyms variable into an array of words by using the explode() function. Look it up at php.net

  • #12
    c q
    c q is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    boss something just struck me real hard...
    what if I create an object that stores these arrays...
    and enter this object in my field ?
    just a weird idea...but somehow it strikes as the only way to do it. what say ?
    but I need help with the coding again !!

  • #13
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you might be able to do it that way. how do you store objects in the DB?

  • #14
    c q
    c q is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Dylan Leblanc
    ok, well then in the database, separate multiple words (the synonyms and antonyms) with commas in their DB field.

    Then read the values out of the database and into a variable, so the long string of synonyms get put into a variable $synonyms lets just say.

    Then, if you are using PHP, you can turn the comma separated words in the $synonyms variable into an array of words by using the explode() function. Look it up at php.net

    ths simply a kewl idea...much simpler I must say. thanx buddy u solved my biiiiiiig problem !


    by the ways....Re: how do you store objects in the DB?
    emm....I heard that storing data as 'blob' is used for this purpose.
    neways, methinks your idea is nicer, I'll sort of work on it...thanks again.

  • #15
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Check out the serialize() and unserialize() php functions to make a string representation of an object and store that in your table, of course in an appropriate field of some text type (text, mediumtext, even blob if you like consume as much space as possible).

    And I can only second Dylan Leblancs suggestions: Reconsider your approach to a relational database. Perhaps a different database design could server your needs in a more efficient and straightforward way. Alternativley, there are also object oriented databases, though I can't provide you much info about them.


  •  

    Posting Permissions

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