SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding stuff to mySQL: A fast way?

    Hey Everyone,

    I have a table called 'Pictures' right now I'm moving all of my pictures from my website into a mySQL database considering I have hundreds of pictures I don't want to be typing this into Telnet all day:

    mysql> INSERT INTO Pictures SET
    -> Title = "picture one",
    -> Date = "2001-03-01";

    mysql> INSERT INTO Pictures SET
    -> Title = "picture two",
    -> Date = "2001-03-02";

    and so on, and so on for hundreds of pictures!!!

    Now is there a faster way to do this somehow?
    Let's hope so or I know what I'll be doing all Memorial Day weekend

    Thanks!

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are your pictures stored at the moment? If in HTML files and image files then all you can do is write a script to read the HTML files and take out the paths and descriptions etc, which would probably be more hassle than what you're doing.

    A slightly easier way would be to make a PHP file with this:
    PHP Code:
    <?php
    mysql_connect
    ("server""user""pass");
    mysql_select_db("db");

    mysql_query("INSERT INTO pictures SET title='picture one', date='2001-03-01'");
    ?>
    and copy and paste the mysql_query line replacing the title and date with appropriate ones. It won't be much quicker but will be a bit.

  3. #3
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not actually adding the pictures just their titles and, and the also that date that goes along with the title.

    I'll just keep doign it the old way for now, would it be possible to write a PHP script, and have it be a form where I could just type in the title and date and it would go right into the database?

    That would save alot of time, not knowing much PHP at the moment I wouldn't know if this would work or not.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use PHPMyAdmin which is a really easy way. You can download it at http://www.phpwizard.net.
    Stuart Briscar Consulting - Free Website Consulting

  5. #5
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you design an admin utility for yourself? I designed one for my self in perl/php/mysql before for www.greatkara.com and it makes my/my girl friend's life much more easy(even though I dont have any more time to update site anymore). We are now able to add/edit/delete/change status of pictures/picture groups/diary items or we can check the status of how many times individually pictures/diaries are visited.
    PS: I recommend you to check phplib classes for database access, it would be good start for you. Search for forums about where you can find them(I added my some of function and updated it for my own needs)

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Woah. You're able to count how many time each one is accessed? Someone told me you couldn't do it. Do you think you could show me?
    Stuart Briscar Consulting - Free Website Consulting

  7. #7
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stuart,

    Just create an extra column in your table called "views" or something similar, the data type should probably be an unsigned integer of some sort.

    Now, when the given element from the table is requested by a user, just increment the value in the "views" column for that row.
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok my new table looks like this...

    Type: INT
    Length/Set: [nothing]
    Attributes: UNSIGNED
    Null: not null
    Default: [nothing]
    Extra: Auto Increment

    Neither Primary, Index, nor Unique are checked.
    Stuart Briscar Consulting - Free Website Consulting

  9. #9
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It shouldn't be auto-increment. When the page/picture is viewed you update the record and make the number bigger by one.

    -Peter

  10. #10
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stuart
    it is not your new table, it is your new field
    for my images I have a table with 4 columns(simplified)
    Table structure
    id | title | location | view

    and urls for the images are usually something like,
    mydomain.com/galery/show.php?id=3

    in show.php
    increase view count from given id
    show the images from given id

    of course if you wanna have more detailed statistics you can have a seperate table which inserting every information(id of image, time visited, referer, ....)

  11. #11
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do any of you know where I can find a tutorial on this because I'm a beginner with PHP and I only really know how to do table structure and how to do queries.
    Stuart Briscar Consulting - Free Website Consulting

  12. #12
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    start reading Kevin's tutorial at sitepoint.com first, it has been mentioned hundreds of times in this forum

  13. #13
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've read his PHP/MySQL tutorial. That where I learned the basics from. I'll read over it again just in case.
    Stuart Briscar Consulting - Free Website Consulting


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
  •