Jump to content

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 />';
}

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.