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

Recommended Answers

All 5 Replies

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

commented: Im female..... +2

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

Figured out my problem, thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.