Page 1 of 1

Quick Query Question...

Posted: Mon Aug 12, 2002 7:52 pm
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

Posted: Mon Aug 12, 2002 8:19 pm
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

Posted: Mon Aug 12, 2002 8:27 pm
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 :)

Posted: Mon Aug 12, 2002 8:34 pm
by Exodus00
Hey it worked, thanx man