I am trying to crosscheck a column in a table with 30 rows.

Example:

$value = "a";
$sql = "select * from characters";
$query = mysql_query($sql);
$fetch = mysql_fetch_array($query);

for ($i = 0; $i < 30; $i++) {
  if($value == $fetch['letters']) {
    $counter++;
  }
}
echo $counter;

The logic to my knowledge is the select statement is done on table characters and then a fetch array is processed based on that query.

Im confused now I cant think of the logic on how to check 30 repeated rows each time.

If statement checks if there is the same value of 'a' in both the variable and the cell if so, counter is increased by 1. Finally the counter variable is echoed out.

I am stuck at the for loop logic, please help.

Thankyou, Regards X

hello try this:

$sql = "select * from characters where letters like '%a%'";
$query = mysql_query($sql);
$count=mysql_num_rows($query);
echo $count;

Shanti my hero!

Nice that works but I what I require is a bit more complex like comparing $variable string vs. $cell content instead of just a.

Thanks, Regards X

Comments
Im female.....

see this:

$variable="a";
$sql = "select * from characters where letters like '%".$variable."%'";

Logic works but I need to tinker with it.

If someone can fix the for loop problem be much appericated else ill try work with shanti's example.

Thanks, Regards X

This question has already been answered. Start a new discussion instead.