Don´t say, I know, I really need to learn more.

Post here is you are having problems with any of the tutorials.
Post Reply
wizzuriz
Posts: 53
Joined: Mon Jul 25, 2011 4:22 pm

Don´t say, I know, I really need to learn more.

Post by wizzuriz »

Now I did follow the user register system + cookie + Email activation and all is working just ( expect that I don´t get the mail but that I will look in to later. ) Now my problem is I can get the user id from my database but if I want to pull more date all I get is the same user id number.
// This is to get the username
$u_id= $_SESSION['username'];
// here I take the username and make it to user_id. 
function get_userid($u_id){
    
    $sql = "SELECT
        `user_id` AS `id`,
        `user_weight` AS `weight`
        FROM `users`
        WHERE `user_name` ='{$u_id}'";
        
        $data = mysql_query($sql);
        
        return mysql_result($data, 0);
}


Now I think should me a Mysql_fetch_array here but what my problem is I don´t know how to pull the user id out from the other function.
I can echo it out on the protected.php with $user_info = get_userid($u_id); + <p>User id: <?php echo $user_info['id']; ?></p> That shows the right user id but if I try the fetch array from the user profile video I get many errors and I did try to check them but its not syntax errors.

I did try to create a myslq_fetch_array(); for todays now but its still not working. any idea?

Best regards
Wuzzuriz
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Don´t say, I know, I really need to learn more.

Post by jacek »

Mysql_result can only return one table cell as a string, so you do need to use mysql_fetch_assoc or _array.

You have to have the function return an array now, meaning it cant be used as you are currently.
function get_userid($u_id){
   
    $sql = "SELECT
       `user_id` AS `id`,
       `user_weight` AS `weight`
       FROM `users`
       WHERE `user_name` ='{$u_id}'";
       
        $data = mysql_query($sql);
       
        return mysql_fetch_assoc($data);
}
the result of calling this function would then be an array with two elements, you can use print_r to see what it looks like.
Image
Post Reply