|
Posted by Jerry Stuckle on 05/12/07 02:28
Mike P2 wrote:
> 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
>
Mike,
Actually, he is using the OO mysqli code. But he has multiple problem,
including:
1) he never issued a SELECT statement.
2) $db is out of scope where it is used
3) he's trying to mix mysql commands and mysqli objects
And once he gets these problems fixed he'll have more. He needs a new
book...
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|