Yet another PHP question from brds...

Discussion in 'OT Technology' started by brds, Mar 12, 2007.

  1. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,651
    Likes Received:
    15
    Location:
    Atlanta
    Okay php guys... need some help. I've created a MySQL database that displays records that were entered in a form. I got it to all come out how i want it. The only thing is that i would like the user to be able to click on the column heading and have the page load up that column in alphabetical order. I have the code to do this, but i just can't make the hyperlinks to allow the user to jump from one page to another.

    Here's my code:
    Code:
    echo "<table border='1'>
    <tr bgcolor=#990000>
    <th><font color=#FFFFFF>Name</font></th>
    <th><font color=#FFFFFF>Phone Number</font></th>
    <th><font color=#FFFFFF>Email Address</font></th>
    <th><font color=#FFFFFF>Work Building</font></th>
    <th><font color=#FFFFFF>Work Office</font></th>
    <th><font color=#FFFFFF>Operating System</font></th>
    <th><font color=#FFFFFF>IP Address</font></th>
    <th><font color=#FFFFFF>MAC Address</font></th>
    </tr>";
    while ($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['Last'] . ", " . $row['First'] . "</td>";
    echo "<td>" . $row['Phone'] . "</td>";
    echo "<td>" . $row['Email'] . "</td>";
    echo "<td>" . $row['Building'] . "</td>";
    echo "<td>" . $row['Office'] . "</td>";
    echo "<td>" . $row['OS'] . "</td>";
    echo "<td>" . $row['IP'] . "</td>";
    echo "<td>" . $row['macid'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";
    
    During the first part of the table, i would like to make something like this:

    Code:
    <tr bgcolor=#990000>
    <th><font color=#FFFFFF><a href="./getName.php">Name</a></font></th>
    <th><font color=#FFFFFF><a href="./getPhone.php">Phone Number</a></font></th>
    <th><font color=#FFFFFF><a href="getEmail.php">Email Address</a></font></th>
    
    
    etc....
    
    
    
    anybody know how to do this?
     
  2. Tk

    Tk Well-Known Member

    Joined:
    Dec 23, 2001
    Messages:
    23,086
    Likes Received:
    285
    Location:
    nw iowa
    ill give a hint....

    like as you have now, each of the column headings will point to a new page. or rather, you could use 1 page and set the different outputs of the page by the (( orderedPage.php?order=Phone ))

    just have the new page run a new query on the DB and use an 'ORDER BY' clause pointed at the field you wish to order by, then choose ASC or DESC (obviously ascending and descending)
     
  3. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    Tk is right on, if you get stuck then post again.
     
  4. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,651
    Likes Received:
    15
    Location:
    Atlanta
    figured out that one... now i would like to know how to make it so i can put a "delete" hyperlink at the end of each row and then, upon selection, ask for a password and then (if the password is correct) delete the entire row. I know you have to figure out the row ID, but i dont know how to do that.

    Any helpful hints or examples?
     
  5. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    Thats too messy... why dont you put in a login system, with permissions. If its an admin thats logged in, he will have a permission to delete it.

    As for deleting, make a file delete.php and make it get the id variable... so then you link to delete.php?id=1234

    It takes the id 1234 and runs a query

     
  6. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,651
    Likes Received:
    15
    Location:
    Atlanta
    But how do i get the ID?
     
  7. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    You could learn about session management.
    http://www.phpdeveloper.org/news/5704

    I'm not that familiar with PHP but with Java using sessions is very easy and powerful.
     
  8. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,651
    Likes Received:
    15
    Location:
    Atlanta
    how does a session help me query the database for the ID number of a specific row?
     
  9. o2

    o2 Witty Title Here OT Supporter

    Joined:
    Oct 4, 2005
    Messages:
    16,099
    Likes Received:
    12
    Location:
    Toronto
    Each row in the DB should have an ID, if it doesn't add an id column, set it to unique, and auto_increasement. Then just echo out the ID in your while loop.
     
  10. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    It doesn't.

    If you need the unique ID of a particular row, that's called the primary key and to obtain that, you need to know SQL. Once obtained, I guess you could pass this primary key around to your different pages if you needed it.

    That's not what we did tho....we'd simply accept the user data (name/password) and verify that info was in the DB...if it was they had an account and we'd then create a session number. Then I've handled it 2 different ways, one way was to store a session number in another table and pass that sessionId to each page via GET method....we did this in PHP.

    The other way was to create a unique session object then push the data we need to store to that session object...we did this using Java. This session object is stored on the clients machine via cookies but that part is transparent to the server programmer. However, if the client doesn't have cookies enabled, this will likely not work.

    I don't know if PHP has a similar feature to the Java one but the point is, your verification only needs to be done once. That's what session tracking helps you with.
     

Share This Page