Jump to content

beginner problem in select statement


joomtalk

Recommended Posts

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: :confused:

Link to comment
https://forums.phpfreaks.com/topic/261567-beginner-problem-in-select-statement/
Share on other sites

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!!!!

post-133450-13482403465214_thumb.jpg

$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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.