joomtalk Posted April 25, 2012 Share Posted April 25, 2012 Hi everybody i am beginnet with working with sql in php..so i confused.....i made one scripte and i am making the secound and now i am facing a problem....i hope u could help!! i have a dat=abse of my chatroom....this is the code i typed...please have a look at it! $usern=$_SESSION['etchat_'.$this->_prefix.'username']; $con1 = mysql_connect("localhost","manosir_main","********"); if (!$con1) { die('Could not connect: ' . mysql_error()); } mysql_select_db("manosir_manoshos_main", $con1); $users= mysql_query(" select etchat_user_online_user_sex from db1_etchat_useronline where etchat_user_online_user_name = $usern "); in my database, i ahve a table called db1_etchat_useronline that keeps record of online users in chatroom. as u usee i qant to to get the user sex ( etchat_user_online_user_sex) of th current user!!! as u see i conected to database correctly but now i dont know how to echo the $users . before this i echo my sql results with mysql_fetch_array ..but now i cant.......i got nothing!!!! can someone help me!!!!! :confused: Link to comment https://forums.phpfreaks.com/topic/261567-beginner-problem-in-select-statement/ Share on other sites More sharing options...
trq Posted April 25, 2012 Share Posted April 25, 2012 Sorry, but your post is unreadable. Link to comment https://forums.phpfreaks.com/topic/261567-beginner-problem-in-select-statement/#findComment-1340357 Share on other sites More sharing options...
joomtalk Posted April 25, 2012 Author Share Posted April 25, 2012 hi! what is unreadable??? let me say it again! i want to get the gender of the user who is seeing the page... as u see i get the username from the session! in this line $usern=$_SESSION['etchat_'.$this->_prefix.'username']; then i am going to connect to database and find the gender of this username $usern so i used this code: $users= mysql_query(" select etchat_user_online_user_sex from db1_etchat_useronline where etchat_user_online_user_name = $usern "); the problem is: i dont know how to echo the result... the reslut will be m(male) or f(female) or n(unknown) in other projects i used to echo the result with mysql_fetch_array..but in this one i dfont know how can i do this! i attached my db table!!! thanx!!!! Link to comment https://forums.phpfreaks.com/topic/261567-beginner-problem-in-select-statement/#findComment-1340360 Share on other sites More sharing options...
joomtalk Posted April 25, 2012 Author Share Posted April 25, 2012 please!!somebody helps....is it still unreadable???? :shrug: :shrug: Link to comment https://forums.phpfreaks.com/topic/261567-beginner-problem-in-select-statement/#findComment-1340487 Share on other sites More sharing options...
Psycho Posted April 25, 2012 Share Posted April 25, 2012 $query = "SELECT etchat_user_online_user_sex AS gender FROM db1_etchat_useronline WHERE etchat_user_online_user_name = '$usern'"; $result= mysql_query($query); $user = mysql_fetch_assoc($result); echo "DB gender value: {$user['gender']}<br>\n"; $displayGender = "Unknown"; if($user['gender']=='m') { $displayGender = "Male"; } if($user['gender']=='f') { $displayGender = "Female"; } echo "Full gender description: {$displayGender}<br>\n"; Link to comment https://forums.phpfreaks.com/topic/261567-beginner-problem-in-select-statement/#findComment-1340488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.