You are here: Re: Getting results from MySQL Database in PHP « PHP Programming Language « IT news, forums, messages
Re: Getting results from MySQL Database in PHP

Posted by Mike P2 on 05/11/07 21:56

On May 11, 5:39 pm, christopher_bo...@yahoo.co.uk wrote:
> for ($x = 0; $x < $db->m_numRows; $x++) {
> $row = $db->getRow();

The MySQL extension (the one you connect through) is not object-
oriented. You must have gotten the code I quoted above from an example
that uses MySQLi (improved), which was designed to connect to MySQL 5.
MySQLi is more fun to use, in my opinion, and should be easier to
learn. Actually, the example might have been using PDO MySQL, too.

Whether you are using MySQLi or not, you should not iterate through
returned rows using a for() loop like this because the row count MySQL
claims to have is not always accurate. Also, you didn't query the
database.

The code I quoted and everything after it should be replaced with
something like:

$results = mysql_query( 'SELECT * FROM `table_name_here`' );
while( $row = mysql_fetch_assoc( $results ) )
{
echo '<tr>';
foreach( $row as $item )
{
echo '<td>'.$item.'</td>';
}
echo '</tr>';
}
echo '</table>';
?>

....and you should fill in the name of the table you are getting data
from. All of the code after what I quoted got messy and didn't make
sense, so I changed it.

I think I should mention that you can just pass the strings right into
functions, you don't have to use
$host = ...
$username = ...
....
mysql_connect( $host, $username, ...

You can instead just put
mysql_connect( 'localhost', 'root', 'password' );

-Mike PII

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация