my code is not working plzz help me out

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hari_reddyc
Forum Newbie
Posts: 1
Joined: Wed Jul 09, 2008 11:29 pm

my code is not working plzz help me out

Post by hari_reddyc »

CODE
{
mysql_connect('localhost','username','password');
mysql_select_db('some database');
$res=mysql_query("select dept_name from dept where deptid=1);
echo $res;
}


i tried to print value of res variable but it is showing output as "RESOURCE ID #4" or some value followed by resource id

but "i think the value shud be the value returned by mysql_connect function'

i donno why actual value of $res is not shown

so kinldly work on this and let me know how to print the actual value of $res
parimala
Forum Newbie
Posts: 8
Joined: Wed Jun 11, 2008 7:21 am

Re: my code is not working plzz help me out

Post by parimala »

hari to display the value you have to use mysql_result($res,0);
or use mysql_fetch_array,mysql_fetch_assoc,mysql_fetch_row

you will get your required results

thanks and regards
pari
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: my code is not working plzz help me out

Post by califdon »

[quote="hari_reddyc"]

Code: Select all

 
$res=mysql_query("select dept_name from dept where deptid=1);
echo $res;
The result of mysql_query() is just a pointer to a "resource", meaning that it is a potentially huge array of data, so you can't just echo or print it. You have to use other mysql functions to recover the data, as the previous responder explained.
Post Reply