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

Link to comment
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.