While Loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neesley
Forum Commoner
Posts: 26
Joined: Tue Aug 31, 2010 3:22 am

While Loop

Post 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!
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: While Loop

Post by McInfo »

Add a WHERE clause to the query or design the table to use a full-text search.
User avatar
arrielmabale
Forum Newbie
Posts: 15
Joined: Fri Aug 13, 2010 3:57 pm
Location: Dubai

Re: While Loop

Post 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
Post Reply