Jump to content

[SOLVED] Listing the 'categories'


tomhoad

Recommended Posts

<?php
//display the competitions
$query = "SELECT comp_name FROM comps";
$result = mysql_query($query) or die('Error : ' . mysql_error());
while ($row     = mysql_fetch_array($result, MYSQL_ASSOC)) { 

$comp_name   = $row['comp_name'];

?>


<p><?php echo $comp_name;?> - 
<a href="comp_view.php?comp_name=<?php echo(urlencode($comp_name))?>">View Entrants</a></p>


<?php
}

?>

 

This code works fine, it displays the comp_name. However, it does it for every record, e.g. if there were three records:

 

Great Competition - View Entrants

Great Competition - View Entrants

Great Competition - View Entrants

 

What I'd like to do is just list the different comp_names, e.g.

 

Great Competition - View Entrants

Brilliant Competition - View Entrants

 

Regardless of how many people have entered - that's on the next page (comp_view.php, which works fine).

 

Sorry if this isn't clear, I'm struggling to put into words what I want!

 

Thanks  ;D

Link to comment
Share on other sites

<?php
//display the competitions
$query = "SELECT comp_name FROM comps";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$comp_names = array();

while ($row     = mysql_fetch_array($result, MYSQL_ASSOC)) { 
     $comp_names[]   = $row['comp_name'];
}

$comp_names = array_unique($comp_names);

foreach($comp_names as $comp_name){
?>


<p><?php echo $comp_name;?> - 
<a href="comp_view.php?comp_name=<?php echo(urlencode($comp_name))?>">View Entrants</a></p>


<?php
}

?>

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.