Quick Query Question...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Exodus00
Forum Newbie
Posts: 13
Joined: Mon Aug 05, 2002 11:46 pm
Location: Oregon
Contact:

Quick Query Question...

Post by Exodus00 »

Ok, I have a column in a mySQL table that is default blank.. nothing in it, and then some have the letter Y in the cell, I've been trying to make a script that tells me how many Y's I have filled in... I've been trying a foreach loop, but... it keeps giving me errors when trying to parse it.

like.. something like this...btw no problems whatsoever connecting to the database, or displaying stuff, works fine without this stuff...

Code: Select all

$total = 0;
$payed2 = "Y";
			
			foreach ($payed = $payed2) {
			$total + 1 = $total;
			 }
am I going about this the wrong way..(well obviously) but I mean is there something wrong with my sytax, or.. is there a query function I could setup to do this and give and total in integer form...?? thanx.. reply if you have anymore questions

Also $payed is the thing where it either is Y or it isn't, and earlier its taken from the database and made into a variable for an earlier thing of being put into an HTML table...

btw
Hebbs
Forum Commoner
Posts: 43
Joined: Mon Apr 22, 2002 9:34 pm
Location: Perth, Western Australia

Post by Hebbs »

Perhaps try the mysql_num_rows function to get a count of the rows with the value Y, something like this:

Code: Select all

$query = "SELECT * FROM tablea
	WHERE columna = 'Y'";

$result = mysql_db_query($DB, $$query);

$num_rows = mysql_num_rows($result);

echo "$num_rows";
Hebbs
Exodus00
Forum Newbie
Posts: 13
Joined: Mon Aug 05, 2002 11:46 pm
Location: Oregon
Contact:

Post by Exodus00 »

I was looking at that, found it in my book, but wasn't sure on how to set it up. I'm... still a noob I guess you could say, but.. making an attempt to learn is better than not learning at all :D

I'll try it, thanx for your reply.. I'll edit this post if it works :)
Exodus00
Forum Newbie
Posts: 13
Joined: Mon Aug 05, 2002 11:46 pm
Location: Oregon
Contact:

Post by Exodus00 »

Hey it worked, thanx man
Post Reply