Hi, I am new to php/mysql, and am trying to output some data from a table using PHP. In the table, each row has an ID, and a category. I have the following query: SELECT * FROM questions where sectionId = ".$sectionid." Code (markup): $sectionid = 1, or whatever value specified. I then have another bit of PHP code that generates a random number. I want to count down the number of rows specified, and return the values from that row. For example, I will echo the question, and later check the answer given against the correct answer. It is for a quiz that will have multiple categories. I hope that it is clear enough what I want - does anyone know how to do that? Regards, TAJ EDIT: I am using PHP/MYSQL, so maybe there is a better way of making the SQL query to do so - I don't mind how it's achieved as long as I understand it! I really want to keep all the questions from all the categories in one table though
That sounds pretty straightforward and you appear to be on the right track. Which bits are causing problems?
The problem I was having was trying to "count down" to a certain row (e.g. row 3 from the results) and output the data. I've just come up with what I think is working, however. It's a completely different way, as follows: 1) Get the id of all rows matching the criteria (mysqli_fetch_array) 2) shuffle the array (shuffle($array)) 3) take the first ids from the array, up to the number I need. It seems to be working thus far, and a lot easier than what I was trying (I don't know if it is possible to count down the results?)