php - Mysqli_query works in one part of if-elseif statement, but not the other -


i working on event list page class taking. 1 of first time have worked php.

i want display filtered list of events depending on category chosen drop down list. want display complete list of events if 'all events' chosen ddl. have if-elseif statement change sql query depending on category value query string.

the specific error seeing list of events missing when 'all events' selected. echo statement of if-else work, , displaying correct values $category, $month, , $year. missing table containing list of events.

note: have tested query , have confirmed work pull list of events. have tried empty $category value no change.

this if statement work:

if(!empty($category)){  $catresult = mysqli_query($con," select cal_events.event_id,      cal_events.title,      date_format(cal_dates.date, '%m %d %y') formatted_date,      monthname('$month') nameofmonth     cal_events  left join cal_dates  on cal_events.event_id = cal_dates.event  cal_events.categories = '$category'  , year(date) = '$year'  , month(date) = '$month'  group cal_dates.date, cal_events.title, cal_events.event_id");  echo "<h2>$category</h2> <h3>events $monthname, $year</h3> <br /><br /> <table align='center'> <tr> <th>date</th> <th>event</th> <th></th> </tr>";  } 

this elseif statement not work:

elseif($category=='all'){       $catresult = mysqli_query($con," select cal_events.event_id,      cal_events.title,      date_format(cal_dates.date, '%m %d %y') formatted_date,      monthname('$month') nameofmonth cal_events  left join cal_dates  on cal_events.event_id = cal_dates.event  year(date) = '$year'  , month(date) = '$month'  group cal_dates.date, cal_events.title, cal_events.event_id");  echo "<h2>$category</h2> <h3>events $monthname, $year</h3> <br /><br /> <table align='center'> <tr> <th>date</th> <th>event</th> <th></th> </tr>";  } 

this while loop displaying list of events:

//displays list of events while($row = mysqli_fetch_array($catresult)) { echo "<tr>"; echo "<td>" . $row['formatted_date'] . "</td>"; echo "<td><a href='detail.php?id=".$row['event_id']."' target='_blank'>" .  $row['title'] . "</a></td>"; echo "</tr>"; } echo "</table>"; 

your if/elseif logic isn't mutually exclusive:

if(!empty($category)){   //... } elseif($category=='all'){   //... } 

if $category value 'all' first if block still execute. under no conditions elseif block ever execute.

you switch around conditions, or add additional check first one. like:

if(!empty($category) && $category!='all'){ 

but point if , elseif blocks have different subsets of total set of possibilities. if first block executes, second block definition won't.


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -