I have PHP code (below) which reads data from a MySQL format database. The
problem I am having is trying to find out when the last ID entry was made.
When the script is executed, the $gbID is supposed to be read and display
the last entered ID number ($How_many_entr ies) - the ID number is entered /
updated automatically in another PHP script which deals with data entry to
the database.
But instead of displaying the result of the query, it displays the ID
number ($How_many_entr ies) as "Resource id #4", and looking around the
search engines, no page makes particular sense as to what I've done wrong.
Does anyone know how to get the $gbID number from the database and into
$How_many_entri es so I can perform some math work on it?
Thanks.
Dariusz
<?
$DatabaseName = "Guestbook" ;
$table_to_look_ for = "entries";
$connection = @mysql_connect( "localhost" ) or die("<B>Could not connect to
MySQL: </B>".mysql_error ());
mysql_select_db ($DatabaseName) ;
// get all tables in the database
$result = @mysql_list_tab les ("DatabaseName" );
// Display database entries in reverse order (remove 'DESC' to have forward
display of results)
$sql = "SELECT gbID, gbDate, gbIP, gbURL, gbName, gbComment FROM
$table_to_look_ for ORDER BY gbid DESC";
$result = @mysql_query($s ql, $connection) or die("<B>Problem reading from
database: </B>".mysql_error ());
while ($row = mysql_fetch_arr ay($result))
{
$gbID = $row['gbID'];
$gbDate = gmstrftime('%A %d %B %Y at $T',strtotime($ row['gbDate']));
$gbURL = $row['gbURL'];
$gbName = $row['gbName'];
$gbComment = nl2br($row['gbComment']);
$display_entry .= "$gbID:<BR><B>P osted on: </B>$gbDate <B>IP:
</B>Logged<BR><B> Posted by: </B>$gbName<BR><B >Personal website:
</B>$gbURL<BR><B> Comment: </B>$gbComment<BR ><BR>";
}
$sql = "SELECT last_insert_id( $gbID) FROM $table_to_look_ for";
$How_many_entri es = @mysql_query($s ql, $connection);
// $How_many_entri es = $How_many_entri es / 5;
echo "Entries: $How_many_entri es<BR>";
etc....
problem I am having is trying to find out when the last ID entry was made.
When the script is executed, the $gbID is supposed to be read and display
the last entered ID number ($How_many_entr ies) - the ID number is entered /
updated automatically in another PHP script which deals with data entry to
the database.
But instead of displaying the result of the query, it displays the ID
number ($How_many_entr ies) as "Resource id #4", and looking around the
search engines, no page makes particular sense as to what I've done wrong.
Does anyone know how to get the $gbID number from the database and into
$How_many_entri es so I can perform some math work on it?
Thanks.
Dariusz
<?
$DatabaseName = "Guestbook" ;
$table_to_look_ for = "entries";
$connection = @mysql_connect( "localhost" ) or die("<B>Could not connect to
MySQL: </B>".mysql_error ());
mysql_select_db ($DatabaseName) ;
// get all tables in the database
$result = @mysql_list_tab les ("DatabaseName" );
// Display database entries in reverse order (remove 'DESC' to have forward
display of results)
$sql = "SELECT gbID, gbDate, gbIP, gbURL, gbName, gbComment FROM
$table_to_look_ for ORDER BY gbid DESC";
$result = @mysql_query($s ql, $connection) or die("<B>Problem reading from
database: </B>".mysql_error ());
while ($row = mysql_fetch_arr ay($result))
{
$gbID = $row['gbID'];
$gbDate = gmstrftime('%A %d %B %Y at $T',strtotime($ row['gbDate']));
$gbURL = $row['gbURL'];
$gbName = $row['gbName'];
$gbComment = nl2br($row['gbComment']);
$display_entry .= "$gbID:<BR><B>P osted on: </B>$gbDate <B>IP:
</B>Logged<BR><B> Posted by: </B>$gbName<BR><B >Personal website:
</B>$gbURL<BR><B> Comment: </B>$gbComment<BR ><BR>";
}
$sql = "SELECT last_insert_id( $gbID) FROM $table_to_look_ for";
$How_many_entri es = @mysql_query($s ql, $connection);
// $How_many_entri es = $How_many_entri es / 5;
echo "Entries: $How_many_entri es<BR>";
etc....
Comment