benwiggy
asked on
Easy question: Collect data from mySQL database
If have a table, lets say phpbb_users, and it has the fields username & user_id.
If I have the username stored as a variable, how can I find the corresponding user_id and store it as a variable?
{ Moved to PHP & Databases - Diablo84/PHP Page Editor }
If I have the username stored as a variable, how can I find the corresponding user_id and store it as a variable?
{ Moved to PHP & Databases - Diablo84/PHP Page Editor }
ASKER
No I'm not trying to fit into phpbb so don't worry - will try - I'm integrating a jokes portal membership system - thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks - for others browsing through, the code I ended up using and how I used it:
$sql = "SELECT * FROM `phpbb_users` WHERE `username` = '".$userdata['username']." ' LIMIT 1";
$dosql = mysql_query($sql, $db);
$result = mysql_fetch_assoc($dosql);
$u_id = $result['user_id'];
$accounttitle = "Welcome ".$userdata['username'];
$sql = "select jokeid from jokes where userid = $u_id";
$result = mysql_query($sql ,$db);
$mycount = mysql_num_rows($result);
Thanks again for quick response!
$sql = "SELECT * FROM `phpbb_users` WHERE `username` = '".$userdata['username']."
$dosql = mysql_query($sql, $db);
$result = mysql_fetch_assoc($dosql);
$u_id = $result['user_id'];
$accounttitle = "Welcome ".$userdata['username'];
$sql = "select jokeid from jokes where userid = $u_id";
$result = mysql_query($sql ,$db);
$mycount = mysql_num_rows($result);
Thanks again for quick response!
no problem mate :-)
<?php
$connect = mysql_connect($mysql_serve
mysql_select_db($mysql_dbn
function username2userid($username)
{
global $connect;
if(!isset($username))
{
return false;
}
else
{
$sql = "SELECT * FROM `phpbb_users` WHERE `username` = '".$username."' LIMIT 1";
$dosql = mysql_query($sql, $connect);
$result = mysql_fetch_assoc($dosql);
return $result['user_id'];
}
}
?>
You might need to alter it to fit into phpbb...ill check it up for you now.