/    Sign up×
Community /Pin to ProfileBookmark

MySQL query problem

I have the following MySQL query which works fine in PHPMyAdmin:

[CODE]Select COUNT(*) from todo_todolist where compl = 0[/CODE]

The output looks like

[QUOTE]

COUNT(*)
3

[/QUOTE]

Now I want to show the count number in PHP but it doesn’t work:

[code=php]$dbuser=”user”;
$dbpass=”pass”;
$dbname=”dbname”; //the name of the database
$chandle=mysql_connect(“localhost”, $dbuser, $dbpass) or die(“Connection Failure to Database”);
mysql_select_db($dbname, $chandle) or die ($dbname . ” Database not found. ” . $dbuser);
$query1=”Select COUNT(*) from todo_todolist where compl = 0″;
$result=mysql_query($query1) or die(“Failed Query of ” . $query1);
$thisrow=mysql_result($result);[/code]

When I add

[code=php]echo $result . $thisrow[0];[/code]

it shows me “Resource id #29 ” so echo $result gives me ths resource id #29 error and echo $thisrow is empty.
How can I display the count number from the SQL query in PHP?
Thanks in advance.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@GenixdeaeJan 14.2010 — the resource id isn't an error, that's the ID that mysql uses to access your DB connection(hence resource). Tho might I suggest using mysql_num_rows().
Copy linkTweet thisAlerts:
@MindzaiJan 14.2010 — Change:

[code=php]
$thisrow=mysql_result($result);
[/code]


to:

[code=php]
$thisrow=mysql_fetch_row($result);
[/code]


And you should be sorted.
Copy linkTweet thisAlerts:
@DaSilvaauthorJan 15.2010 — Thanks, both answers were helpful ?
×

Success!

Help @DaSilva 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.28,
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,
)...