Jump to content

Recommended Posts

I have a database of clubs - one of the categories is meeting time and place

I would like to have a page that looks something like this:

 

Monday:

club1

club2

club3

 

Tuesday:

club1

club2

club3

 

etc.

and each club is linked to the "showitem.php" page I have set up

 

I've been able to get it to work for one day, but not so that it lists all of the days and their clubs.

The data includes the place as well as the day where the meeting is held, so I have to use something like SELECT * FROM clubs WHERE meet LIKE "%monday%"

 

Can anyone help out?

Thanks!

 

  • 3 weeks later...

I've never used a loop before... haha how would i do that?

 

<?php
$mysqli = mysqli_connect ("97.74.218.110","csteffen","Summer09","csteffen");

$display_block = "<h1>Monday</h1>";

$get_mon_sql = "SELECT id, name FROM clubs WHERE meet LIKE '%monday%' ORDER BY name";
$get_mon_res = mysqli_query($mysqli,$get_mon_sql)
or die(mysqli_error($mysqli));


while ($mon = mysqli_fetch_array($get_mon_res)) {
$id = $mon['id'];
$name = ucwords(strtolower(stripslashes($mon['name'])));

$display_block .= "<div style=\"text-align: center;\"><a href=\"showitem.php?
id=".$id."\">".$name."</a>
</div>";
}

mysqli_free_result($get_mon_res);
mysqli_close($mysqli);
?>
<html>
<head>
<link href="css.css" rel="stylesheet" type="text/css"> 
<title>Clubs</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>


try something like this:

 

$days = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday','saturday', 'sunday');
$display_block = '';
foreach ($days as $dow) {
  $display_block .= "<h1>$dow</h1>";

  $get_mon_sql = "SELECT id, name FROM clubs WHERE meet LIKE '%$dow%' ORDER BY name";
  $get_mon_res = mysqli_query($mysqli,$get_mon_sql)
  or die(mysqli_error($mysqli));

  while ($mon = mysqli_fetch_array($get_mon_res)) {
    $id = $mon['id'];
    $name = ucwords(strtolower(stripslashes($mon['name'])));

    $display_block .= "<div style=\"text-align: center;\"><a href=\"showitem.php?
id=".$id."\">".$name."</a>
</div>";
  }

  mysqli_free_result($get_mon_res);
}

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.