| | |
PHP Statement ?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2006
Posts: 5
Reputation:
Solved Threads: 0
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;
but it always going to first statement whatever $total is. I echo the $total. It gives 8.
What is wrong?
I want to do : ıf number of rows from query is bigger than x do something if small do another thing. Namely;
php Syntax (Toggle Plain Text)
$qry = mysql_query("SELECT * FROM data_table WHERE page='$page'",$dbh); $total = mysql_num_rows($qry); if($total>7) { something... } else{ another thing; }
but it always going to first statement whatever $total is. I echo the $total. It gives 8.
What is wrong?
The is equates to
So when total=8 it will select the first one.
php Syntax (Toggle Plain Text)
if ($total is greater than 7) { something... } else { another thing }
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.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: Jul 2006
Posts: 5
Reputation:
Solved Threads: 0
PHP Syntax (Toggle Plain Text)
if ($total is greater than 7) { something... } else { another thing }
I am when total is 1 or 8 whatever is; it is going to same statement. Why?
Try:
php Syntax (Toggle Plain Text)
if (mysql_num_rows($qry) > 7 ) { something... } else { another thing }
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.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: Jul 2004
Posts: 234
Reputation:
Solved Threads: 8
Why don't you use COUNT in sql statement instead?
php Syntax (Toggle Plain Text)
$qry = mysql_query("SELECT COUNT(*) FROM data_table WHERE page='$page'",$dbh);
yes , try PoA way like:
php Syntax (Toggle Plain Text)
$seq="select count(*) as cnt fromdata_table WHERE page='$page'"; $sres=mysql_query($seq); $srow=mysql_fetch_assoc($sres); if($srow['cnt']>7) { //do something} else if($srow['cnt']<=7) { //do another thing }
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
php Syntax (Toggle Plain Text)
$qry = mysql_query("SELECT * FROM data_table WHERE page='$page'",$dbh); [COLOR="Red"]while($info = mysql_fetch_array( $qry )) { $total++; }[/COLOR] if($total>7) { something... } else{ another thing; }
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]
![]() |
Similar Threads
- PHP Select Statement (PHP)
- PHP-Nuke Tutorial #1: Altering the Header Tags (PHP)
- PHP Beginner Here (PHP)
- Update entire Mysql DataBase with PhP (PHP)
- PHP vs. Pearl (PHP)
- php wont submit data into the database (PHP)
- We've Gone PHP! (DaniWeb Community Feedback)
Other Threads in the PHP Forum
- Previous Thread: Parse error: parse error, unexpected '['
- Next Thread: isp auto-detect
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary broken cakephp checkbox class cms code codingproblem combobox cron curl database date display domain dynamic echo email error file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla js limit link load login mail malfunctioning menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset up-to-date update upload url validation validator variable video web webapplications websitecontactform youtube






