PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 18th, 2000, 04:09 PM
marcus of exley marcus of exley is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 12 marcus of exley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi can any one tell me please why i keep getting a value of 2 when i include this scipt (i know i have over 200 items)it works fine from a mysql prompt as select count(FIELD) from table; gives correct result
but this in php gives a result of 2 ?


$item_count = "SELECT count(FIELD)FROM table";


$item_result = mysql_query($item_count)
or die("Couldn't get count");

if ($item_result == "1") {
echo "<strong>1</strong> item.";
} else {
echo "<strong>$item_result</strong> items.";
}


Reply With Quote
  #2  
Old June 18th, 2000, 07:19 PM
scoobydoo scoobydoo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Sydney, Australia
Posts: 32 scoobydoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
I think you still need to use,
mysql_fetch_array.

eg,

$item_count = "SELECT count(FIELD) AS numbers FROM table";

$item_result = mysql_fetch_array(mysql_query($item_count))
or die("Couldn't get count");

if ($item_result['numbers'] == "1") {
echo "<strong>1</strong> item.";
} else {
echo "<strong>$item_result['numbers']</strong> items.";
}

good luck,
scoobydoo

Reply With Quote
  #3  
Old June 19th, 2000, 04:26 AM
marcus of exley marcus of exley is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 12 marcus of exley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi scoobydoo thanks for replying, i tried this and got the following error:

Parse error: parse error, expecting `STRING' or `NUM_STRING' or `'$'' in



Reply With Quote
  #4  
Old June 19th, 2000, 04:49 AM
scoobydoo scoobydoo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Sydney, Australia
Posts: 32 scoobydoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
oops.. sorry marcus.. made a big mistake
it's $item_result["numbers"]

" not the '

scoobydoo

Reply With Quote
  #5  
Old June 20th, 2000, 04:32 AM
marcus of exley marcus of exley is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 12 marcus of exley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi scoobydoo , i made the changes but still get the same error?

Reply With Quote
  #6  
Old June 20th, 2000, 02:51 PM
ujludwig ujludwig is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 63 ujludwig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
The result your getting is the integet id of the result, not the result itself. For example, if I run a query against the database
$connection = mysql_connnect($host,$user,$pwd);
echo $connection; // This will be an integer identifier for a php connection
$result = mysql_query("select * from customers", $connection);
echo $connection; // This will be an integer identifier for a php result set

// Now you need to get the data out of the result set....

$last_name = mysql_result($result, 0, "last_name"); // where 0 is the first row in the result set

// So to get your query to work properly,
//you need to read out the result as I did
//above but remember to name the field
//otherwise you have to access it by offset
//and not by name

$result = mysql_query("select count(*) as mycount from customers", $connection);

$thecount = mysql_result($result,0,"mycount");

// or if you leave out the as in the sql:

$result = mysql_query("select count(*)from customers", $connection);

$thecount = mysql_result($result,0,0);

// You can also use mysql_fetch_array which
//moves a whole result set into an array
//which you can then manipulate in php.

mssql_fetch_array($result);



Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Displaying number of items in mysql database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap