PHP Statement ?

Reply

Join Date: Jul 2006
Posts: 5
Reputation: gandil is an unknown quantity at this point 
Solved Threads: 0
gandil gandil is offline Offline
Newbie Poster

PHP Statement ?

 
0
  #1
Oct 13th, 2008
I have a db query, which show datas from mysql database.
I want to do : ıf number of rows from query is bigger than x do something if small do another thing. Namely;
  1. $qry = mysql_query("SELECT * FROM data_table WHERE page='$page'",$dbh);
  2. $total = mysql_num_rows($qry);
  3.  
  4. if($total>7)
  5. {
  6. something...
  7. }
  8.  
  9. else{
  10. another thing;
  11. }

but it always going to first statement whatever $total is. I echo the $total. It gives 8.
What is wrong?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: PHP Statement ?

 
0
  #2
Oct 13th, 2008
The is equates to
  1. if ($total is greater than 7) {
  2. something...
  3. } else {
  4. another thing
  5. }

So when total=8 it will select the first one.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 5
Reputation: gandil is an unknown quantity at this point 
Solved Threads: 0
gandil gandil is offline Offline
Newbie Poster

Re: PHP Statement ?

 
0
  #3
Oct 13th, 2008
  1. if ($total is greater than 7)
  2. {
  3. something...
  4. }
  5. else
  6. {
  7. another thing
  8. }

I am when total is 1 or 8 whatever is; it is going to same statement. Why?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: PHP Statement ?

 
0
  #4
Oct 13th, 2008
Try:
  1. if (mysql_num_rows($qry) > 7 ) {
  2. something...
  3. } else {
  4. another thing
  5. }
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 234
Reputation: PoA is an unknown quantity at this point 
Solved Threads: 8
PoA PoA is offline Offline
Posting Whiz in Training

Re: PHP Statement ?

 
0
  #5
Oct 13th, 2008
Why don't you use COUNT in sql statement instead?
  1. $qry = mysql_query("SELECT COUNT(*) FROM data_table WHERE page='$page'",$dbh);
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: PHP Statement ?

 
0
  #6
Oct 14th, 2008
yes , try PoA way like:
  1. $seq="select count(*) as cnt fromdata_table WHERE page='$page'";
  2. $sres=mysql_query($seq);
  3. $srow=mysql_fetch_assoc($sres);
  4.  
  5. if($srow['cnt']>7) {
  6.  
  7. //do something}
  8. else if($srow['cnt']<=7)
  9. {
  10. //do another thing
  11. }
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: Apr 2008
Posts: 75
Reputation: danishbacker is an unknown quantity at this point 
Solved Threads: 5
danishbacker's Avatar
danishbacker danishbacker is offline Offline
Junior Poster in Training

Re: PHP Statement ?

 
0
  #7
Oct 22nd, 2008
  1. $qry = mysql_query("SELECT * FROM data_table WHERE page='$page'",$dbh);
  2. [COLOR="Red"]while($info = mysql_fetch_array( $qry )) {
  3. $total++;
  4. }[/COLOR]
  5.  
  6. if($total>7)
  7. {
  8. something...
  9. }
  10.  
  11. else{
  12. another thing;
  13. }
Try this.
i think mysql_num_rows(); will counting all the rows in the table.


but it always going to first statement whatever $total is. I echo the $total. It gives 8.
What is wrong?[/QUOTE]
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 19
Reputation: jt1 is an unknown quantity at this point 
Solved Threads: 3
jt1's Avatar
jt1 jt1 is offline Offline
Newbie Poster

Re: PHP Statement ?

 
0
  #8
Oct 22nd, 2008
Using the COUNT(*) query by PoA or mysql_num_rows on your query will return the same value.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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