Page 1 of 1

While Loop

Posted: Sun Sep 05, 2010 9:23 pm
by neesley
My aim here is to take values from one table column, then identify how times that value appears in a 2nd table. I've figured out how to find how many instances of a hard-coded value are present. But how would make this value into an array then check?

Here's what I got so far:

Code: Select all

<?php

$con = mysql_connect("h50mysql101.secureserver.net","xxxx","xxxx");

mysql_select_db("neesleysqltest", $con);

$schedule = mysql_query("SELECT * FROM schedule");

$i = 0;

while($row = mysql_fetch_array($schedule))
	{
		if (($row['jakes'])=="Neesley")
				{
				$i++;
				}
		if (($row['gin'])=="Neesley")
				{
				$i++;
				}
		if (($row['wagon'])=="Neesley")
				{
				$i++;
				}
		if (($row['hatch'])=="Neesley")
				{
				$i++;
				}
		if (($row['stumble'])=="Neesley")
				{
				$i++;
				}
		if (($row['step'])=="Neesley")
				{
				$i++;
				}
		if (($row['sheets'])=="Neesley")
				{
				$i++;
				}
				
	}

echo $i;

mysql_close($con);

?>
Thanks!

Re: While Loop

Posted: Sun Sep 05, 2010 10:25 pm
by McInfo
Add a WHERE clause to the query or design the table to use a full-text search.

Re: While Loop

Posted: Mon Sep 06, 2010 3:16 am
by arrielmabale
Yes you should use where clause and also use left join for your aim to identify how times that value appears in a 2nd table