Topic: displaying profile image thumbnail in the <example.php> page (Read 544 times)
Atari ST fan
Posts: 8
64 credits Members referred : 0
« on: Apr 30, 2007, 01:17:24 PM »
I'm a php/mysql newbie, and I have been playing around with access_user_class for about two weeks. Today I wanted to find a way of displaying a profile thumbnail image when the user has logged in and goes to <example.php>. To achieve this I created a folder in the filesystem to hold the imagefile, and a new field in the table <users> in the database to hold the URL to the imagefile. Here's the php-code that was added to <example.php>, and I would like some comments to find out if I did this the correct way or not :
<img src=" <?php
#connecting to database mysql_connect("localhost", "db_username", "db_password"); mysql_select_db("db_name");
#defines the variable $image
# table name="users", field name that holds the URL to the imagefile="profile_thumb"
$image = mysql_query("SELECT profile_thumb FROM users WHERE login='$page_protect->user'")
or die(mysql_error());
#displaying the result of the db query while($result_image = mysql_fetch_array( $image )) { echo $result_image['profile_thumb']; }
#disconnecting from mysql mysql_close();
?> " border="1">
This is how the script works (. . . or at least how I think it works) : The script accesses the database, finds the correct table, looks for the field that contains the image-URL's and finds the URL that belongs to the user that is currently logged in. To find the correct username and the URL that belongs to it, it uses the variable $page_protect->user Instead of displaying the URL as text, it diplays the URL inside a <img src>-tag.
I would like some comments on this please. -Is this sensible php-scripting, or am I totally mistaken? The script actually works, so maybe I'm at least on the right track
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6440
39464 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Apr 30, 2007, 01:30:20 PM »
you should use one of the profile user fields, this way you can use the existing methods and you have no problems with later class updates
Atari ST fan
Posts: 8
64 credits Members referred : 0
« Reply #2 on: Apr 30, 2007, 01:54:32 PM »
I have been thinking the same,-using one of the fields in the profile user table would be better. The problem is, I would need more fields in the profile user table as time goes by. I've tried to use one of the existing fields, and even adding new fields but I can't make that work. Adding new fields to the profile user table is easy, but it seems like new fields need to be defined in some way so that the access_user_class can use them. Being a newbie, this is something I don't understand.
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6440
39464 credits Members referred : 374