SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A few PHP MySQL questions.

    So far, Sitepoint has not yet failed to help in my quest to program my site. And now, before I ask for help from you people I say thankyou very much for all your help. So anyway, here goes.

    1) I have in my database, 4 tables. When I select the info from the table, i use limit 50. So it only has 50 entries. I display all 50. NOW. The 4th table, is filled with people's e-mail addresses. I don't want them to be public, it's their for when their entry is bumped off, an e-mail will be autosent. the problem is, is that I don't how to access the 50th entry, for only the e-mail category. Help please?

    2) When someone clicks a link to a page in this site, I want it to register. As in, if someone clicks.

    The 'apple' link (it doesn't really exist this is just an example)
    I want the page, 'apple' to register that they've clicked it. How would I go about doing that? Thankyou.

  2. #2
    SitePoint Evangelist ldivinag's Avatar
    Join Date
    Jan 2005
    Location
    N37 33* W122 3*
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you post the query statement and a schema dump of the tables?
    leo d.

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    insane,

    Quote Originally Posted by insanekilla
    1) I have in my database, 4 tables. When I select the info from the table, i use limit 50. So it only has 50 entries. I display all 50. NOW. The 4th table, is filled with people's e-mail addresses. I don't want them to be public, it's their for when their entry is bumped off, an e-mail will be autosent. the problem is, is that I don't how to access the 50th entry, for only the e-mail category. Help please?
    Whoops! LIMIT 50 limits the number of records retrieved FROM the database, not the number of table entries!

    The reason for tables is that you can associate one-to-many records (etc.) efficiently and without duplication. What you need is one table is the ID to relate to the ID (or some other KEY field) in the other table.

    Rather than try to dust off a rusty mind and try to recall lectures from years ago, may I suggest you Google for "Normalization" of databases. I know that there are a lot of pages out there that would help you immensely.

    Quote Originally Posted by insanekilla
    2) When someone clicks a link to a page in this site, I want it to register. As in, if someone clicks.

    The 'apple' link (it doesn't really exist this is just an example)
    I want the page, 'apple' to register that they've clicked it. How would I go about doing that?
    It's not clear in my mind what you're doing -- unless it's a visit counter. If so, the page script would merely SELECT that page's counter, increment and UPDATE before going on to write the page. It's that simple! Moreover, you COULD use an auto_prepend file to fetch the filename and update from the database before serving ANY page -- but then Apache does that for its logs, doesn't it? That must mean you either don't have access to your Apache logs or don't trust them OR I've missed the boat completely. Votes on that one?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Missed the boat 100% completely. I want to access one, one email from that table.
    Table is
    Item 1 Item 2 Item 3 Item 4

    I want number 50 of item 4.

    As for the second thing, I don't have a clue what you're talking about.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    insane,

    Thanks! That clears things up a LOT!

    A database is made up of tables which can be interrelated (normalization is the process to optimize their interrelationships). Each table has a certain number of columns which contain specified types of data. Each table also has records (think of them in terms of rows) which can contain data in any or all columns. The mistake above was that you called the columns "tables."

    Okay, to rephrase your original question, you want to access just one COLUMN of your ONE table, specifically item #50. Depending upon how you have identified item #50, your $query string could be:

    "SELECT e-mail FROM table WHERE unique_key='$unique_key_value'" if you have the value of the unique key so you can select that record.

    IF you have used id, an integer, as the primary key and auto_incremented its value, the OLDEST record will have the lowest value of id so you can SELECT the oldest (FIFO - first in, first out) to obtain the e-mail then DELETE the same way: "SELECT e-mail FROM table ORDER BY id ASC LIMIT 1" to get the oldest e-mail and e-mail them (be sure to fetch it out of the mysql_fetch_array() before using "DELETE * FROM table ORDER BY id ASC LIMIT 1" to remove that record.

    [Note: If you want LIFO, Last In First Out, change the ASCending order to DESCending order.]

    Now, I think I've hit upon what you REALLY wanted to do and given some QUERY strings to deal with that. However, I'll also recommend that you do a little reading about database design -- EVERY PHP/MySQL book discusses this topic so it won't be hard to find.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And this, ladies and gentlemen, is why I ****ing love SitePoint.

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    insane,

    Does that mean "problem solved?"

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •