943,699 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 673
  • PHP RSS
Oct 15th, 2008
0

How to check cells of a column

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

Example:
php Syntax (Toggle Plain Text)
  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.
PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Oct 15th, 2008
0

Re: How to check cells of a column

hello try this:
PHP Syntax (Toggle Plain Text)
  1. $sql = "select * from characters where letters like '%a%'";
  2. $query = mysql_query($sql);
  3. $count=mysql_num_rows($query);
  4. echo $count;
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Oct 15th, 2008
1

Re: How to check cells of a column

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
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Oct 15th, 2008
0

Re: How to check cells of a column

see this:
PHP Syntax (Toggle Plain Text)
  1. $variable="a";
  2. $sql = "select * from characters where letters like '%".$variable."%'";
Last edited by Shanti C; Oct 15th, 2008 at 3:20 am.
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Oct 15th, 2008
0

Re: How to check cells of a column

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
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Oct 15th, 2008
0

Re: How to check cells of a column

Figured out my problem, thanks for the help.
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Multiple Existing DB Entries
Next Thread in PHP Forum Timeline: T_VARIABLE error!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC