/    Sign up×
Community /Pin to ProfileBookmark

$result = mysql_query… What is ‘$result’? An array?

Assume the following code:

[code=php]
<?php
$username=”david”;
$password=”passwd123″;
$database=”dbase1″;

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);

$query = “SELECT * FROM contacts”;
$result=mysql_query($query);

mysql_close();

?>
[/code]

What type of variable is $result? I assumed it was a multi-dimensional array, but why can’t I echo one of its values to the browser by using:

echo $result[first][0];

(There is a field in the table called ‘first’).

Does the function mysql_query() create some sort of special data type that can only be used by other, pre-defined functions?

Thanks.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 24.2006 — ...

Does the function mysql_query() create some sort of special data type that can only be used other, pre-defined functions?

Thanks.[/QUOTE]

Yes, it returns a "resource ID" which can then be used by any of the mysql_fetch_*() functions, and other functions such as mysql_data_seek() and mysql_num_rows().
Copy linkTweet thisAlerts:
@callumdauthorAug 24.2006 — Thanks NogDog,

Lightning quick answer, much appreciated.

Callum.
Copy linkTweet thisAlerts:
@NogDogAug 24.2006 — No problem. See http://www.php.net/manual/en/function.mysql-fetch-assoc.php for a typical example of using a mysql_query() result.
×

Success!

Help @callumd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...