scottybwoy Posted August 25, 2006 Share Posted August 25, 2006 I have this code here :[code]<?php$domain_user = explode("\\", $_SERVER['LOGON_USER']);$user = $domain_user[1];echo $user;$AUTH_DB_NAME = 'mri_sql';$AUTH_DB_TBL = 'users'; mssql_connect("localhost,1433", "user", "pass", "") or die("Failed Connection"); mssql_select_db("$AUTH_DB_NAME") or die ("cannot connect to database");$result = mssql_query("SELECT USER_ID FROM users WHERE uNAME = '" . $user . "' AND ACTIVE = '1'");echo $result;?>[/code]And I get this result :technicalResource id #2Shouldn't I get :technical3technical being my username and 3 being my ID Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/ Share on other sites More sharing options...
Gruzin Posted August 25, 2006 Share Posted August 25, 2006 think u have to use mysql_fetch_arry:[code]while($row = mysql_fetch_array($result)) { echo $row['yourow']; echo "<br />"; }[/code] Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80277 Share on other sites More sharing options...
onlyican Posted August 25, 2006 Share Posted August 25, 2006 I prefer mysql_fetch_assoc()[code]<?php$query = "SELECT USER_ID FROM users WHERE uNAME = '".$user."' AND active = '1'");$result = mysql_query($query);while($row = mysql_fetch_assoc($result)){$user_id = $row["USER_ID"];}[/code] Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80279 Share on other sites More sharing options...
scottybwoy Posted August 25, 2006 Author Share Posted August 25, 2006 maybe, that didn't return anything except technical. How am I supposed to know the row number ($row['yourow']) when what I am after is the user ID from the row containing the user name.Tried both and they return the same, only the user nameThanks though Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80283 Share on other sites More sharing options...
radalin Posted August 25, 2006 Share Posted August 25, 2006 well use something like:[code]$query = "SELECT * FROM users where uName = '$user' AND active = 1";$result = mysql_query($query);while($row = mysql_fetch_assoc($result)){if ($row[uName] == $user)$idImLookingFor = $row['user_id'];}[/code] Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80285 Share on other sites More sharing options...
scottybwoy Posted August 25, 2006 Author Share Posted August 25, 2006 Still no joy, same result. My active column is set to BIT but when viewed shows TRUE of FALSE values, if I put AND active = TRUE in my query it doesn't like it, but shouldn't 1 return the same as TRUE? Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80289 Share on other sites More sharing options...
Jenk Posted August 25, 2006 Share Posted August 25, 2006 var_dump your $row variable to see what is available. Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80334 Share on other sites More sharing options...
onlyican Posted August 25, 2006 Share Posted August 25, 2006 he means use somethig likeprint_r($row); Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80343 Share on other sites More sharing options...
scottybwoy Posted August 25, 2006 Author Share Posted August 25, 2006 OK this is my code now :[code]<?php$domain_user = explode("\\", $_SERVER['LOGON_USER']);$user = $domain_user[1] . "<br />";echo $user;$AUTH_DB_NAME = 'mri_sql';$AUTH_DB_TBL = 'users'; mssql_connect("localhost", "1433", "user", "pass") or die("cannot connect"); mssql_select_db("$AUTH_DB_NAME") or die ("cannot connect to database");$query = "SELECT * FROM users where uName = '$user' AND active = 1";$query = stripslashes($query);$result = mssql_query($query);while($row = mssql_fetch_assoc($result)){if ($row[uName] == $user)$idImLookingFor = $row['user_id'];}print_r($row);?>[/code]Which output's :technical Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80364 Share on other sites More sharing options...
onlyican Posted August 25, 2006 Share Posted August 25, 2006 try print_r($row) within the while loop Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80366 Share on other sites More sharing options...
scottybwoy Posted August 25, 2006 Author Share Posted August 25, 2006 Sorry but still no joy, it still outputs the same Link to comment https://forums.phpfreaks.com/topic/18633-small-query-an-easy-one/#findComment-80368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.