SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I was wondering what kind of while loop to use when I want to do something with every post in a table. Since the primary key of the table is an Email address, I can't run through it using a number that increments by one and then fetches the ID, so how do I do this?

    Thanks in advance !
    Sincerely,

    Eirik Johansen
    Netmaking AS

  2. #2
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, good question. Maybe you should reconsider using the e-mail as a primary key. Don't know exactly what you are wanting to do overall but I do my tables like this :

    Table 1, AUTHORS contained:

    ID EMAIL NAME
    1 one@one.com joe
    2 two@two.com sue

    Table 2, STORIES Contained:

    ID MESSAGE REFID
    1 Story by one@one.com 1 <--- authors ID
    2 Story by one@one.com 1
    3 Story by one@one.com 1
    4 Story by two@two.com 2


    select name, email, message from AUTHORS, STORIES where authors.id = stories.refid AND email = 'two@two.com';

    would produce :

    sue two@two.com Story by two@two.com

    OR

    select name, email, message from authors, stories where authors.id = stories.refid AND email = 'one@one.com';

    would produce :

    joe one@one.com Story by one@one.com
    joe one@one.com Story by one@one.com
    joe one@one.com Story by one@one.com

    ----------------------------

    In short the REFID in the articles table connects to the authors ID from the authors table.

    Dunno if this is what your getting at, if not, well it might help someone else at least.

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing you mean something like this:
    PHP Code:
    // query the database to select every row in tableName
    $result mysql_query('SELECT * FROM tableName');

    // the following while loop will keep looping while
    // there are more rows to extract in the result set
    while ($row mysql_fetch_array($result)) {
        
    // do whatever you want to each row here



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
  •