Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

bestimmte anzahl datensätze zufällig auswählen?

Empfohlene Antworten

Veröffentlicht

mit

$abfrage = "SELECT * FROM tricks ORDER BY id DESC LIMIT 0, 5";

$ergebnis = mysql_query($abfrage);

kann ich 5 datensätze auslesen. wie kann ich 5 zufällige auswählen (also nicht order by sondern irgendwie rnd oder so... ?!)

versuch's mal so:

SELECT * FROM tricks ORDER BY rand() LIMIT 0,5

Ich glaube da bleibt dir nichts anderes übrig, als alle Datensätze auszulesen und dann einfach mit einer rand funktion nur 5 zufällig zu benutzen...


<?php
$abfrage = "SELECT * FROM tricks ORDER BY id DESC LIMIT 0, 5";
$ergebnis = mysql_query($abfrage);
$rows=mysql_num_rows($ergebnis);

srand ((double)microtime()*1000000);
echo mysql_result($ergebnis,rand(0,$rows),"<<des was du auslesen willst >>")

?>
[/PHP]

mysql bietet doch eine eigene random funtion, also warum den vergleichsweise langsamen weg über php gehen, wenn man's direkt im sql query machen kann.

thanx

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.