Jump to content

Generating a numbered list from a database


kreut

Recommended Posts

Hello,

 

I'm generating a list of questions from a database, say $questions.  I'd like to number the questions AFTER I load them from the database (I know that I could enter a number associated with them in the database, but it could get tricky, as the questions will continually be updated and deleted).  My question, then, is how can a create a new array which associates each question with a number.

 

Thank you!

Thanks for the quick responses, but unfortunately I'm actually going to need to refer back to the questions at different times within the page, so I'd like to have some sort of more permanent association (at least while the given web page is active).  Any other suggestions would be appreciated.  Basically, when I need to print a specific question, say the 17th one, the number 17 should pop up, bearing in mind, that I then may need to refer to, say question 13.

 

 

 

 

Well, using the supplied code, I would.

 

$number = 0;
while($row = mysql_fetch_assoc($result)) {
$storage_array[++$number] = $row['id'];
}

foreach($storage_array as $number => $questionID) {
echo 'Question Number: ' . $number . ' is row ' . $questionID . ' in the database.<br />';
}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.