csteff24 Posted November 16, 2009 Share Posted November 16, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/181676-select-all-entries-from-database-that-include-a-phrase/ Share on other sites More sharing options...
csteff24 Posted December 3, 2009 Author Share Posted December 3, 2009 Does my question make sense? Quote Link to comment https://forums.phpfreaks.com/topic/181676-select-all-entries-from-database-that-include-a-phrase/#findComment-970242 Share on other sites More sharing options...
mikesta707 Posted December 3, 2009 Share Posted December 3, 2009 what code do you have that tries to display all the days? surely you can use a loop to do this Quote Link to comment https://forums.phpfreaks.com/topic/181676-select-all-entries-from-database-that-include-a-phrase/#findComment-970254 Share on other sites More sharing options...
csteff24 Posted December 3, 2009 Author Share Posted December 3, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/181676-select-all-entries-from-database-that-include-a-phrase/#findComment-970456 Share on other sites More sharing options...
csteff24 Posted December 4, 2009 Author Share Posted December 4, 2009 I think I kind of understand how I would loop it, but I have no idea how to get it to go through the loop for the days "monday", "tuesday", "wednesday", etc... Quote Link to comment https://forums.phpfreaks.com/topic/181676-select-all-entries-from-database-that-include-a-phrase/#findComment-970980 Share on other sites More sharing options...
DavidAM Posted December 4, 2009 Share Posted December 4, 2009 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); } Quote Link to comment https://forums.phpfreaks.com/topic/181676-select-all-entries-from-database-that-include-a-phrase/#findComment-970999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.