SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Complex SELECT Statments

    I looked for this topic first, but didn't find anything...


    I have a select statement, and from the table I want all the rows, ie

    SELECT * FROM table_name

    However, I know that in table_name there is the row joejoe and a row doedoe. I want joejoe to be the first column in the returned set of rows, and doedoe to be last column. Now I thought I could do something like this:

    SELECT joejoe, *, doedoe FROM table_name

    But that gives me a big fat error. Is there a way to do this or am I doomed to write out every single stupid row name in the SELECT statement?

    Gracias!
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  2. #2
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes or assign column names to varibles in the WHILE statement.

  3. #3
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by CyberFuture
    Yes or assign column names to varibles in the WHILE statement.
    How would that work?
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  4. #4
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $sql="SELECT * FROM table_name";
    $result mysql_query($sql);
    echo 
    "<table><tr><td> A Name</td><td> SomeOther Name</td><td> etc...</td></tr>";
    while (
    $row mysql_fetch_array($result))
    {
    echo 
    "<tr><td> $row['joejoe']</td><td> $row['columnName']</td><td> $row['doedoe']</td></tr>";
    }
    echo 
    "</table>"
    That's one way.

  5. #5
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    heh

    Unfortuneately that's not going to work.

    See i have it set up so that the columns are displayed dynamically. IE, I give a function a set of results, and it gives me back a table with the data in nice pretty rows/columns. The function scales to whatever the results are, so that means that the results need to come in the correct order.

    I'm loooking for a way to sort the columns so that I can define a few specific ones at the beginning, a few specific ones at the end, and then all the rest in the middle.

    I'm starting to think this may not be possible.
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  6. #6
    SitePoint Enthusiast lieblick's Avatar
    Join Date
    Jun 2001
    Location
    Tallahassee, FL
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how bout $row[0] ---- $row[x]
    Vendor Ratings, Coupons & Specials:
    http://www.outcrier.com
    My Personal Site:
    http://www.epock.com

  7. #7
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    does it always have to be the same order?

    If so, go into mysql and reorder the table columns in the order you want the data displayed....

    If not, simply request each field explicitly:
    select joejoe, field2, field3, doedoe from table_name

    --Viral


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
  •