Kleines Problem mit ORDER BY RAND()

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von Knekke.

    Kleines Problem mit ORDER BY RAND()

    hallo Leute

    ich mir mir einen Capatcha geschrieben allerdings nicht mit Texteingabe sondern eine Bild abfrage. es werden 6 Bilder da gestellt. Unter dem Bild steht dann wo man draufklicken soll. Die Bilder sind in einer db aufgelistet. Ich will das dann ein zufälliges Bild das richtige ist.

    das ist mein Code:

    PHP-Quellcode

    1. <?php
    2. session_start();
    3. include('config/database.config.php');
    4. $img = imagecreatetruecolor(384, 256);
    5. imagealphablending($img, false);
    6. imagesavealpha($img, true);
    7. $connection = mysql_connect(dbHost, dbUser, dbPassword) or die ($lang["dbConnectionError"]);
    8. $sql = "SELECT * FROM `" . dbName . "`.`captcha` ORDER BY RAND() LIMIT 6";
    9. $query = mysql_query($sql);
    10. $count = 1;
    11. $correct = rand(1,6);
    12. while ($row = mysql_fetch_object($query)){
    13. if($count == 1){
    14. $start_x = 0;
    15. $start_y = 0;
    16. }
    17. if($count == 2){
    18. $start_x = 128;
    19. $start_y = 0;
    20. }
    21. if($count == 3){
    22. $start_x = 256;
    23. $start_y = 0;
    24. }
    25. if($count == 4){
    26. $start_x = 0;
    27. $start_y = 128;
    28. }
    29. if($count == 5){
    30. $start_x = 128;
    31. $start_y = 128;
    32. }
    33. if($count == 6){
    34. $start_x = 256;
    35. $start_y = 128;
    36. }
    37. if($count == $correct){
    38. $_SESSION['captcha_x'] = $start_x;
    39. $_SESSION['captcha_y'] = $start_y;
    40. $_SESSION['captcha_width'] = 128;
    41. $_SESSION['captcha_height'] = 128;
    42. $_SESSION['captcha_code_en'] = $row->code_en;
    43. $_SESSION['captcha_code_de'] = $row->code_de;
    44. $_SESSION['captcha_count'] = $count;
    45. }
    46. $imgAdd = imagecreatefrompng('images/cpatcha/' . $row->image . '.png');
    47. imagecopy($img, $imgAdd, $start_x, $start_y, 0, 0, 128, 128);
    48. $count += 1;
    49. }
    50. header('Content-Type: image/png');
    51. imagepng($img);
    52. imagedestroy($img);
    53. imagedestroy($imgAdd);
    54. ?>


    das Script liefert mir auch ein richtiges Bild nur eine Sache stimmt nicht. sagen wir mal $correct ist 3 dann wird nicht der Name in $_SESSION['captcha_code_de'] gespeichert.

    ein Screenshot zum beispiel:


    wie man sieht ist an der Position 6 ist eine Stecknadel und kein Handy.

    wenn ich das ORDER BY RAND() raus nehme werden mir die ersten 6 Symbole angezeigt dafür stimmt der Name mit der Position



    so jetzt meine frage:
    was mache ich falsch???

    mfg JeyBe