How to check cells of a column

Thread Solved

Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

How to check cells of a column

 
0
  #1
Oct 15th, 2008
I am trying to crosscheck a column in a table with 30 rows.

Example:
  1. $value = "a";
  2. $sql = "select * from characters";
  3. $query = mysql_query($sql);
  4. $fetch = mysql_fetch_array($query);
  5.  
  6. for ($i = 0; $i < 30; $i++) {
  7. if($value == $fetch['letters']) {
  8. $counter++;
  9. }
  10. }
  11. 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.
  1. 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
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: How to check cells of a column

 
0
  #2
Oct 15th, 2008
hello try this:
  1. $sql = "select * from characters where letters like '%a%'";
  2. $query = mysql_query($sql);
  3. $count=mysql_num_rows($query);
  4. echo $count;
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: How to check cells of a column

 
1
  #3
Oct 15th, 2008
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
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: How to check cells of a column

 
0
  #4
Oct 15th, 2008
see this:
  1. $variable="a";
  2. $sql = "select * from characters where letters like '%".$variable."%'";
Last edited by Shanti Chepuru; Oct 15th, 2008 at 3:20 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: How to check cells of a column

 
0
  #5
Oct 15th, 2008
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
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: How to check cells of a column

 
0
  #6
Oct 15th, 2008
Figured out my problem, thanks for the help.
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC