Re: Efficiency

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



on 1/21/03 6:16 AM, Baumgartner Jeffrey at j.baumgartner@itp-europe.com
appended the following bits to my mbox:

> 1. If I am creating a web page with numerous PHP calls to an MySQL database
> is it more efficient to have lots of small blocks of php in an html page or
> is it better to have just one or two big blocks of PHP with the html code
> being delivered via echo statements?

This gets discussed very frequently here and in PHP-General.  Check the
archives for the discussions, but the general consensus is that it doesn't
matter much.

I tend more toward the echo statements (FYI: use commas rather than dots)
because for me, the code looks nicer with syntax highlighting.

If you don't hand code your HTML (i.e., use Dreamweaver, GoLive, etc), the
small php blocks might be easier to manage.

> 2. If I want to know how many rows there are in a MySQL table, I can either
> use the count function in MySQL (although I am having trouble figuring out
> how to capture that value in a variable) or I can do a general "select *
> from" from command in MySQL and then use the mysql_num_rows function in PHP
> to get a row count (which is dead easy). It SEEMS to me the former would be
> more efficient. Am I correct?

If you are doing a select on the data anyway, it is better to call
MySQL_num_rows on the result you obtained.  If you just want the total
number and won't be fetching the rows, do the query.  Example:

$dbh is your database connection
$q = 'SELECT COUNT(*) FROM tablename';
list($my_count) = MySQL_fetch_row(MySQL_query($q,$dbh));

The $my_count variable now has your number of rows.

Hope that helps.

Sincerely,

Paul Burney
<http://paulburney.com/>

Q: Tired of creating admin interfaces to your MySQL web applications?

A: Use MySTRI instead. <http://www.burney.ws/software/mystri/>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux