|
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
[Back to original message]
|