Jump to content

Need help with my PHP and mysql

lachiebw

I have the following query and its returning the result of resource id #4;


$account = mysql_query("Select type from adminaccounts where username='$username'") or die(mysql_error());


If I run the query in mysql the result is "admin" as I require.


After doing some reasearch I am aware that resources are special. Could you please tell me how I could change this to just display the "admin" that I need for further if statements.


thanks,


Lachie


Link to comment
Share on other sites

Link to post
Share on other sites

It what mysql_query function does. It returns resource. You can use mysql_fetch_assoc on that resource to fetch one row of result (Or any other mysql_fetch_ function).

 

For more information see:

http://php.net/manual/en/function.mysql-query.php

http://php.net/manual/en/function.mysql-fetch-assoc.php

 

Its good to read what function returns to know what to do with this result further. So first thing is to check documentation.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

 

I have the following query and its returning the result of resource id #4;

$account = mysql_query("Select type from adminaccounts where username='$username'") or die(mysql_error());

If I run the query in mysql the result is "admin" as I require.

After doing some reasearch I am aware that resources are special. Could you please tell me how I could change this to just display the "admin" that I need for further if statements.

thanks,

Lachie

 

I know the topic is old but you want to bare this in mind.

 

"This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used."

 

Sources:

http://php.net/manual/en/function.mysql-query.php

Our Lord and Saviour Chunt!!!

Link to comment
Share on other sites

Link to post
Share on other sites

 

I have the following query and its returning the result of resource id #4;

$account = mysql_query("Select type from adminaccounts where username='$username'") or die(mysql_error());

If I run the query in mysql the result is "admin" as I require.

After doing some reasearch I am aware that resources are special. Could you please tell me how I could change this to just display the "admin" that I need for further if statements.

thanks,

Lachie

 

 

Resources are PHP's way of telling you that the query worked. Now you just have to pull it correctly from the database. Since a relational database is table based that sort of representative is usually represented by an array or even more precesiely each row. So, like was mentioned you have to use a mysql_fetch_array or mysql_fetch_row to get what you want.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×