Toon posts:

[mysql] laatst toegevoegde record vinden

Pagina: 1
Acties:

Verwijderd

Topicstarter
Om nog even terug te komen op:[topic=428801/1/25]
LIMIT werkt niet (volgens mij) omdat het om een laatste record gaat die niet hetzelfde blijft.(er wordt steeds weer een nieuw record ingevoegd) Dus zal er geen nummer achter LIMIT op kunnen worden gegeven.

Op http://www.mysql.com/doc/S/E/SELECT.htmlwordt dat nl. als volgt aangegeven:
LIMIT takes one or two numeric arguments. If two arguments are given, the first specifies the offset of the first row to return, the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
mysql> select * from table LIMIT 5,10; # Retrieve rows 6-15

If one argument is given, it indicates the maximum number of rows to return:
mysql> select * from table LIMIT 5; # Retrieve first 5 rows

In other words, LIMIT n is equivalent to LIMIT 0,n.
Het gebruik van LIKE (voor strings)werkt volgens mij ook niet.

Is er dus geen andere optie om de laatste record (string/char) van een tabel in phpmyadmin terug te geven in een form.

Als dit weer gezien wordt als een scriptrequest, zou je dan misschien wel een laatste tip kunnen geven, want ik kom zo ook niet verder...

  • chem
  • Registratie: Oktober 2000
  • Laatst online: 27-08 13:53

chem

Reist de wereld rond

SELECT * FROM table ORDER BY "primary key" DESC LIMIT 1

Klaar voor een nieuwe uitdaging.


Verwijderd

Op maandag 04 maart 2002 11:54 schreef chem het volgende:
SELECT * FROM table ORDER BY "primary key" DESC LIMIT 1
Jij doet tenimnste niet zo moeilijk :D 8-)

  • paultjeb
  • Registratie: Augustus 2001
  • Niet online

paultjeb

Man, wat 'n boudel!

Heee wat lees ik op http://www.phpbuilder.com/columns/tim20000705.php3?page=4 ...

One other limitation may bug a lot of PHP users - Postgres has no equivalent to MySQL's mysql_insertid() function call. That is, if you insert a row into a MySQL database, MySQL will hand you back the primary key ID for that row. There is an extremely round-about way of doing this in Postgres, but it's a headache and is probably slow if used a lot.

  • Grum
  • Registratie: Juni 2001
  • Niet online
edit:
even overdenken wat ik hier stond :P

Verwijderd

Topicstarter
Na een aantal vruchteloze pogingen met bv.
PHP:
1
<?MYSQL_CONNECT("site.nl","naamdb","passw") oR DIE("");MYSQL_SELECT_DB("naamdb") or die("");$query = "SELECT veldnaam1 FROM tabel ORDER BY veldnaam1 DESC LIMIT 1";$result = mysql_query($query);print("<input type=\"hidden\" value=\"veldnaam1\">$result");?>

heb ik eerst maar ff wat id's aangemaakt voor de tabellen.
Met autoincrement wil het namelijk wel :(

Ooit zal ik PHP/MYSQL volledig begrijpen...

Verwijderd

of zoiets was het anders...

mysql_query("Select * from table");
mysql_query("Select Max(id) as maxid from table");
mysql_query("Select Min(id) as minid from table");

succes!

Verwijderd

voeg dan een autoincrement kolom toe, als je mazzel hebt nummert mysql ze op volgorde ;) anders..... tja had je toch de FM moeten lezen he 8-)

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 12-09 21:31

Janoz

Moderator Devschuur®

!litemod

Op maandag 04 maart 2002 15:44 schreef hardscarf het volgende:

Ooit zal ik PHP/MYSQL volledig begrijpen...
Het zal iig helpen als je eerst je result ff 'fetched'. (met mysql_fetch_*())

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • spine
  • Registratie: Juni 2001
  • Niet online

spine

VISHUDDHI

Op maandag 04 maart 2002 15:44 schreef hardscarf het volgende:
Na een aantal vruchteloze pogingen met bv.
[code]
Ooit zal ik PHP/MYSQL volledig begrijpen...
ORDER BY veldnaam1

is dat wel je primairy key ?

[edit]
er mist ook het 1 en ander

[BSDFreaks.nl] [www.Dark-Future.org] [Alizarin.nl]


Verwijderd

Wat ook wel eens wil helpen is sorteren op een timestamp (DESC). Als je dat erin hebt zitten is dat verreweg de makkelijkste manier van records onderhouden. (Hoogste timestamp is laatste record)
Pagina: 1