473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

count database lisitngs

How would i go about asking the database how many listings there are with
the same "Town" field?

I want a page that eventually says:
"We found XXX listings in ZZZ"
Where XXX is the number of listings found and ZZZ is the town.

Thanks,
--
¿ Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk
Jul 17 '05 #1
4 8478
try this:

-------------------------------------------------------------------
$sql = "SELECT * FROM mytable WHERE town = \"$mytown\" ";
$query = mysql_query($sql);
$num_rows = mysql_num_rows($query);
echo "We found " .$num_rows ." listings of " .$mytown;
-------------------------------------------------------------------

look here for more ::
http://www.php.net/manual/en/functio...l-num-rows.php

is that what you want ?

Neil Trigger wrote:
How would i go about asking the database how many listings there are with
the same "Town" field?

I want a page that eventually says:
"We found XXX listings in ZZZ"
Where XXX is the number of listings found and ZZZ is the town.

Thanks,
--
¿ Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk


Jul 17 '05 #2
mysql_num_rows() was not always so efective.

If it fails try this:

$count = mysql_fetch_array(mysql_query("select count(*) from table where
town=example"));
echo "$count";

It has been always useful for me.

Regards

Domin
Jul 17 '05 #3
On 2003-12-18, Gerard <ga******@WYTNIJwp.pl> wrote:
mysql_num_rows() was not always so efective.

If it fails try this:

$count = mysql_fetch_array(mysql_query("select count(*) from table where
town=example"));
echo "$count";


I think you are doing "weird stuff" to get the count(*) ...

$result = mysql_query("SELECT COUNT(*) as count FROM TABLE WHERE Town='example'");
$row = mysql_fetch_assoc($result);
Now it is in $row['count'] ;)

--
verum ipsum factum
Jul 17 '05 #4
I think it's better to use ...

$sql = "SELECT count(*) as numRows FROM mytable WHERE town = \"$mytown\" ";
$query = mysql_query($sql);
$aRow = mysql_fetch_array($query);
echo "We found " .$aRow[numRows] ." listings of " .$mytown;

.... because in this case MySql don't return useless data.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Schraalhans Keukenmeester | last post by:
X-Followup: comp.lang.php I have a PHP script that adds messages to a simple MySQL Database. (PHP 5.0.3, MySQL 4.1.1) One of the fields it stores is msgid. The new msgid is a count of all...
1
by: Henry Stockbridge | last post by:
Hi, I am doing database documentation and run the procedure below to list the record count for each table in the database. The results in the immediate window only a partial listing of tables. ...
5
by: Arsen V. | last post by:
Hello, What is the best way to accomplish the following. 1) An ASP.NET program (consiting of one file somepage.aspx) receives about 25,000,000 requests pay day. 2) The requests come from a...
1
by: griemer | last post by:
I have a database like this id, field1,field2,field3,field4,field5 Database contains 100 rows, some rows have no fields filled, some 1field , some 2 fields etc. How would i count the...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
10
by: Phil Stanton | last post by:
I am trying to count the fields in a queryDef in an external database. If I run this in the actaal database I get Fields.count = 6 correctly Private Sub ObjectName_DblClick(Cancel As Integer) ...
3
by: meti | last post by:
Hello every one is there any body that could help me in the fillowing code. <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="vertrigo"; // Mysql password ...
1
by: danibecr | last post by:
I'm trying to make a table that will daily count the records imported and save them to a seperate table along with the date imported. But as of now after all the processing is complete I delete...
2
by: mfaisalwarraich | last post by:
Hi Everybody, I am using the following code to get the recordset of an external database. Dim dbPatients As Database Dim rsCountPatients As Recordset ' to count number of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.