RE: [PHP] Getting the last record in a mysql table FINALLY!!

2002-01-18 Thread Chris Schneck

Also, PHP has a built in function for finding the ID of the last insert 
query. ill show some brief code.

$query = (insert into tbl_blah (fld_blargh) values ('$roar'));
$result = mysql_query($query) or die (mysql_error());

$last_id = mysql_insert_id();

echo $last_id;

this should print out whatever the primary key # of the last insert query 
performed.

This help at all?

From: Niklas Lampén [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
To: Php-General [EMAIL PROTECTED]
Subject: RE: [PHP] Getting the last record in a mysql table FINALLY!!
Date: Fri, 18 Jan 2002 10:05:35 +0200

Well, ofcourse you have to have the table + field names right. ;)


Niklas

-Original Message-
From: hugh danaher [mailto:[EMAIL PROTECTED]]
Sent: 18. tammikuuta 2002 9:38
To: [EMAIL PROTECTED]
Cc: Php-General
Subject: Re: [PHP] Getting the last record in a mysql table FINALLY!!



Niklas,
I needed to change the statement slightly, but it did put me on the
right track. Thanks again, Hugh

$result=mysql_query(SELECT id FROM my_table ORDER BY id DESC, id limit
1); $id=mysql_result($result,0);

- Original Message -
From: Niklas Lampén [EMAIL PROTECTED]
To: Php-General [EMAIL PROTECTED]
Sent: Thursday, January 17, 2002 10:29 PM
Subject: RE: [PHP] Getting the last record in a mysql table


  If you have ID that is a incrementing number, you could just query
  like
  this:
  'SELECT ID FROM MY_TABLE ORDER BY ID DESC, LIMIT 1'
 
  And there you have just one result, the last (biggest) ID number.
 
 
  Niklas
 
 
  -Original Message-
  From: hugh danaher [mailto:[EMAIL PROTECTED]]
  Sent: 18. tammikuuta 2002 7:37
  To: Php-General
  Subject: [PHP] Getting the last record in a mysql table
 
 
  Help!
  I thought this would be easy but it ain't.  What I want is the id
  number of the last record in a table.  I've tried a number of
  variations to the following but am getting no where!  Any help will be

  greatly appreciated. Hugh
 
 
  $results=mysql_query( SELECT last_insert_id() FROM MY_TABLE );
  $row=mysql_fetch_assoc($results);  while
  ($row=mysql_fetch_row($results))
{
print tr;
foreach($row as $field)
 {
 if ($field==)
  {
  $field=nbsp;;
  }
 print td align=centerh5.$field./h5/td;
 }
print /tr;
}
   print /table/td/tr/table;
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED] To
  contact the list administrators, e-mail: [EMAIL PROTECTED]
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To
contact the list administrators, e-mail: [EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]





_
Chat with friends online, try MSN Messenger: http://messenger.msn.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Getting the last record in a mysql table FINALLY!!

2002-01-17 Thread hugh danaher


Niklas,
I needed to change the statement slightly, but it did put me on the right
track.
Thanks again,
Hugh

$result=mysql_query(SELECT id FROM my_table ORDER BY id DESC, id limit 1);
$id=mysql_result($result,0);

- Original Message -
From: Niklas Lampén [EMAIL PROTECTED]
To: Php-General [EMAIL PROTECTED]
Sent: Thursday, January 17, 2002 10:29 PM
Subject: RE: [PHP] Getting the last record in a mysql table


 If you have ID that is a incrementing number, you could just query like
 this:
 'SELECT ID FROM MY_TABLE ORDER BY ID DESC, LIMIT 1'

 And there you have just one result, the last (biggest) ID number.


 Niklas


 -Original Message-
 From: hugh danaher [mailto:[EMAIL PROTECTED]]
 Sent: 18. tammikuuta 2002 7:37
 To: Php-General
 Subject: [PHP] Getting the last record in a mysql table


 Help!
 I thought this would be easy but it ain't.  What I want is the id number
 of the last record in a table.  I've tried a number of variations to the
 following but am getting no where!  Any help will be greatly
 appreciated. Hugh


 $results=mysql_query( SELECT last_insert_id() FROM MY_TABLE );
 $row=mysql_fetch_assoc($results);  while
 ($row=mysql_fetch_row($results))
   {
   print tr;
   foreach($row as $field)
{
if ($field==)
 {
 $field=nbsp;;
 }
print td align=centerh5.$field./h5/td;
}
   print /tr;
   }
  print /table/td/tr/table;


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Getting the last record in a mysql table FINALLY!!

2002-01-17 Thread Niklas Lampén

Well, ofcourse you have to have the table + field names right. ;)


Niklas

-Original Message-
From: hugh danaher [mailto:[EMAIL PROTECTED]] 
Sent: 18. tammikuuta 2002 9:38
To: [EMAIL PROTECTED]
Cc: Php-General
Subject: Re: [PHP] Getting the last record in a mysql table FINALLY!!



Niklas,
I needed to change the statement slightly, but it did put me on the
right track. Thanks again, Hugh

$result=mysql_query(SELECT id FROM my_table ORDER BY id DESC, id limit
1); $id=mysql_result($result,0);

- Original Message -
From: Niklas Lampén [EMAIL PROTECTED]
To: Php-General [EMAIL PROTECTED]
Sent: Thursday, January 17, 2002 10:29 PM
Subject: RE: [PHP] Getting the last record in a mysql table


 If you have ID that is a incrementing number, you could just query 
 like
 this:
 'SELECT ID FROM MY_TABLE ORDER BY ID DESC, LIMIT 1'

 And there you have just one result, the last (biggest) ID number.


 Niklas


 -Original Message-
 From: hugh danaher [mailto:[EMAIL PROTECTED]]
 Sent: 18. tammikuuta 2002 7:37
 To: Php-General
 Subject: [PHP] Getting the last record in a mysql table


 Help!
 I thought this would be easy but it ain't.  What I want is the id 
 number of the last record in a table.  I've tried a number of 
 variations to the following but am getting no where!  Any help will be

 greatly appreciated. Hugh


 $results=mysql_query( SELECT last_insert_id() FROM MY_TABLE ); 
 $row=mysql_fetch_assoc($results);  while
 ($row=mysql_fetch_row($results))
   {
   print tr;
   foreach($row as $field)
{
if ($field==)
 {
 $field=nbsp;;
 }
print td align=centerh5.$field./h5/td;
}
   print /tr;
   }
  print /table/td/tr/table;


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED] To 
 contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To
contact the list administrators, e-mail: [EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]