Results 1 to 16 of 16

Thread: MySQL with PHP Help plz

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Location
    Ohio
    Posts
    153

    MySQL with PHP Help plz

    Hi, I have a mysql table named users with a list of users in them.

    Does anyone know how I would go about displaying each user in the table on a page with each username having a link going to a certain page on it.

    So a page would display every user in the database. Then the displayed users would each have their own link, linking you to a different page for each user when clicked.

    Thanks in advance

  2. #2
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: MySQL with PHP Help plz

    assuming you have already connected, and logged into MySQL from PHP...

    heres my table:
    __________________
    | username | link |
    ---------------------
    | bone | wheretolinkto1 |
    | dude | wheretolinkto2 |
    | ares | wheretolinkto3 |
    ------------------------

    PHP Code:
    $query "SELECT * FROM users";
    $result mysql_query($query);
    while(
    $row mysql_fetch_array($result))
    {
           echo 
    "<a href='".$row['link']."'>".$row['username']."</a><br/>";

    this would return
    HTML Code:
    <a href='wheretolinkto1'>bone</a><br/>
    <a href='wheretolinkto2'>dude</a><br/>
    <a href='wheretolinkto3'>ares</a><br/>

  3. #3
    Member AWC_Joe's Avatar
    Join Date
    Jan 2006
    Location
    Located
    Posts
    49

    Re: MySQL with PHP Help plz

    Or... to work off BoneCrif's post:
    Code:
    id | username | link          | first name | last name
    --------------------------------------------------
    1  | bone     | personal link | Tom        | Jones
    2  | dude     | personal link | Fred       | Hickery
    3  | ares     | personal link | Nancy      | Smith
    PHP Code:
     $query "SELECT id, username FROM users";
    $result mysql_query($query);
    while(
    $row mysql_fetch_array($result))
    {
           echo 
    "<a href='users.php?id=".$row['id']."'>".$row['username']."</a><br/>";

    Then you could hold more info about the user in the 'users' table and display it on the user.php page. Then you could use $_GET['id'] on the users.php to pull from the 'users' table.

    Just a thouhgt.

    _
    |
    Some programs and scripts ive made: http://wiki.anotherwebcom.com
    What was once an opinion, became a fact, to be later proven wrong...

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Location
    Ohio
    Posts
    153

    Re: MySQL with PHP Help plz

    Hey thanks for the replies

    Also, if I were going to have each user upload their own images on their page, would I have to make a new table just for that, or could I add that into the users table?

  5. #5
    Member AWC_Joe's Avatar
    Join Date
    Jan 2006
    Location
    Located
    Posts
    49

    Re: MySQL with PHP Help plz

    Quote Originally Posted by hlstriker
    Hey thanks for the replies

    Also, if I were going to have each user upload their own images on their page, would I have to make a new table just for that, or could I add that into the users table?
    Personaly , i would use the 'users' table and only store the path to the pic. Storing pics in a dbase is not all that efficient and take up alot of space. You could have them upload the pic to a genteral dir, when the pic is saved to your server have the pic renamed to a long-random name (so theres no duplacates) and then store the path to the pic in the dabse. Some people use md5() to rename the pic, its quick and easy.


    _
    |
    Some programs and scripts ive made: http://wiki.anotherwebcom.com
    What was once an opinion, became a fact, to be later proven wrong...

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Location
    Ohio
    Posts
    153

    Re: MySQL with PHP Help plz

    Ok now I come across a problem. I don't have a clue on how to have it show the images saved in the 'image' column when the username is clicked.

    When the user name is clicked, it's supposed to show all the images on the usernames page, that the username has in its database. In the image column it has the link to the image, not actual image.

    I think I would use the code something like this...
    Code:
    {
           echo "<img src='".$row['image']."'><br/>";
    }
    My problem is this will show all the images for every username. I want it to show just the usernames image whose page its on.

  7. #7
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: MySQL with PHP Help plz

    it would be something like this (assuming that you have a users page)
    PHP Code:
    $query "SELECT * FROM users WHERE username = '".$username."'"
    OR
    PHP Code:
    $query "SELECT * FROM users WHERE id = '".$id."'"
    PHP Code:
    $result mysql_query($query); 
    $row mysql_fetch_array($result);
    echo 
    "<img src='".$row['image']."'><br/>"

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Location
    Ohio
    Posts
    153

    Re: MySQL with PHP Help plz

    I don't know how to setup a users page. Do I just stick this code in users.php?

    Sorry I am extremely new to using MySQL with PHP.

  9. #9
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: MySQL with PHP Help plz

    Quote Originally Posted by hlstriker
    I don't know how to setup a users page. Do I just stick this code in users.php?

    Sorry I am extremely new to using MySQL with PHP.
    stick it in where you need it...

  10. #10
    Member AWC_Joe's Avatar
    Join Date
    Jan 2006
    Location
    Located
    Posts
    49

    Re: MySQL with PHP Help plz

    Quote Originally Posted by BoneCrif
    PHP Code:
    $query "SELECT * FROM users WHERE id = '".$_GET['id']."'";

    # i edited that from $id to $_GET['id'] 
    PHP Code:
    $result mysql_query($query); 
    $row mysql_fetch_array($result);
    echo 
    "<img src='".$row['image']."'><br/>"
    Quote Originally Posted by hlstriker
    I don't know how to setup a users page. Do I just stick this code in users.php?
    yes.

    _
    |
    Some programs and scripts ive made: http://wiki.anotherwebcom.com
    What was once an opinion, became a fact, to be later proven wrong...

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Location
    Ohio
    Posts
    153

    Re: MySQL with PHP Help plz

    Ok just to make sure I didn't screw this up to bad heres a check for my table...

    I have a table named users.

    In the 'users' table I have 8 fields.
    Field 1 = id
    Field 2 = username
    Field 3 = password
    Field 4 = ip
    Field 5 = date
    Field 6 = category
    Field 7 = images
    Field 8 = comments

    1. The id is the id number for each user.
    2. The username is the username a user chooses when signing up.
    3. The password is the password a user chooses when signing up.
    4. The ip is the ip that the user logs in as (should update each time user logs in)
    5. The date will hold the date that each image that is submitted.
    6. The category will hold the name of the category the images go to.
    7. The images hold the link to the image.
    8. The comments hold comments about each image that is submitted.

    What is supposed to happen is...
    A user signs up with a username and password.

    Once the user is signed up, they can enter a control panel type page which from there they can maintain the images, comments and categories. When signing in it will log their ip in the ip field.

    The users will be able to make categories, and upload images with comments and the date of the upload.

    Note that they should be able to make and upload as many categories and images they want.

    Is all this possible the way I have the table setup? I think I made this sound more complicated then it actually is.

    Thanks in advance!

  12. #12
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: MySQL with PHP Help plz

    you should have your id field as the primary
    but yes, it should be possible if there are no errors in your code

  13. #13
    Member AWC_Joe's Avatar
    Join Date
    Jan 2006
    Location
    Located
    Posts
    49

    Re: MySQL with PHP Help plz

    You have not memntioned how you are going to save the password in the dbase, so... i thouhgt i would say: its not good practice to save passwords in plan text, peroid.

    One way of saving a password would be to md5() it, save the hashed password in the databse and when your member logs-in have the password they are submitting checked against the hashed password (by md5()ing the submitted password).

    _
    |
    Some programs and scripts ive made: http://wiki.anotherwebcom.com
    What was once an opinion, became a fact, to be later proven wrong...

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Location
    Ohio
    Posts
    153

    Re: MySQL with PHP Help plz

    The password just needs to be hashed when submitting right? Then the hashed password can go into a varchar field? Is this correct?

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Location
    Ohio
    Posts
    153

    Re: MySQL with PHP Help plz

    Another question!

    Would it be safe to use the PHPBB users that already have a username and password?

    Would this even work if the users are in one database, and the images and other stuff in another database?

  16. #16
    Fanatic Member
    Join Date
    Oct 2004
    Posts
    751

    Re: MySQL with PHP Help plz

    Quote Originally Posted by hlstriker
    The password just needs to be hashed when submitting right? Then the hashed password can go into a varchar field? Is this correct?
    Correct.
    It will be something like
    $password = md5($_POST['password']);

    Quote Originally Posted by hlstriker
    Another question!

    Would it be safe to use the PHPBB users that already have a username and password?

    Would this even work if the users are in one database, and the images and other stuff in another database?
    Yes it would be safe, as a matter of fact its almost common to do such a thing. But what most people do is that, disabled registration in phpBB then add a register page to their site and when a user registers all the information will get put into their user's DB and the phpBB's user table.
    Or you could easily just make querys to the 2 different tables.
    My Projects: [ Instant Messagener Client/Server ] [ VBPictochat ]

    My Sites:
    [ Datanethost ]
    [ Helpdesk ]

    Remember if my post was helpful then Rate This Post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width