Jump to content

multiple loops under several headings


SF23103

Recommended Posts

I am trying to display entries from a database.  I would like to categorize the entries into specific headings when they print to the page.

 

For instance:

ID 1

Question:  What is your favorite color

Answer: Blue

Category: Favorites

 

ID 2

Question:  What is two plus two?

Answer:  Four

Category:  Math

 

 

I would like to display all "Favorites" under the heading "Favorites", and all "Math" under heading "Math".  There will be multiple entries for each.  I figure I need to do a loop for each category?  How do I do this without having to connect to the database multiple times?

 

<?php
$username="username";
$password="pass";
$database="database";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM ft_form_17 WHERE Include='Include'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"question"); //Question
$f2=mysql_result($result,$i,"answer"); //Answer
$f3=mysql_result($result,$i,"submission_id"); //submission
$f4=mysql_result($result,$i,"category"); //category

?>

<strong><a name="<?php echo $f3; ?>"><?php echo $f1; ?></a></strong>
<?php echo $f2; ?>


<?php
$i++;
}
?>

Link to comment
Share on other sites

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.