Jump to content

Select all entries from database that include a phrase


csteff24

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);
}

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.