1

I have the following code which selects information from one random row.

$query = mysql_query("SELECT * FROM lines_angles_shapes ORDER BY RAND() LIMIT 1 ");

while($rows = mysql_fetch_array($query))
{
    $question = $rows['question'];
    $hint = $rows['hint'];
    $level = $rows['level'];
    $keyword = $rows['keyword'];
    $showme = $rows['showme'];
    $picture_path = $rows['picture_path'];

}

This works well for me but I now I need to be able to select two more DIFFERENT pictures from the picture_path column and assign them to variables. Again, all three rows need to be different.

Any tips for a newbie on how to do this?

4
  • try to change limit number Commented Nov 4, 2014 at 4:47
  • yes, I thought about doing that, but how would I be able to accurately differentiate between the three rows? In my program one row has the picture path for correct answer in my project, the other two are just random but different pictures selected to be used as incorrect answer choices. Commented Nov 4, 2014 at 4:50
  • If you're selecting at random, how do you know which one is 'correct' anyway? Just use the first result as the 'correct' one. Commented Nov 4, 2014 at 4:53
  • Please improve your question then only you can get very accurate answer Commented Nov 4, 2014 at 4:57

3 Answers 3

2

Just change your query as follows:

$query = mysql_query("SELECT * FROM lines_angles_shapes ORDER BY RAND() LIMIT 3");
Sign up to request clarification or add additional context in comments.

Comments

0

You are ordering by ORD() so it will give you different records.

No, new modification, just change the limit to 3 (whatever your need).

$query = mysql_query("SELECT * FROM lines_angles_shapes ORDER BY RAND() LIMIT 3");

Comments

0

As your are already getting random values with order by clause it will always return different values so you just need to edit your limit value and you are done!

$query = mysql_query("SELECT * FROM lines_angles_shapes ORDER BY RAND() LIMIT 3");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.