i'm in process of designing web front-end menu, have created system add meals menu , need read user. need organize things categories (aka div's). wrote code (i think) should list of categories (distinct results in column), names , prices of each meal each category.
the issue is not displaying categories or meals.
here's db structure, id primary index
code looks this,
<?php mysqli_report(mysqli_report_all ^ mysqli_report_index); $db = new mysqli('localhost', 'username', 'password', 'db'); if($db->connect_errno > 0){ die('unable connect database [' . $db->connect_error . ']'); } $query = "select distinct `mealtype` `meals`"; if(!$result = $db->query($query)){ die('there error running query [' . $db->error . ']'); } else { $row = $result->fetch_assoc(); while($row = $result->fetch_assoc()){ $mealtype=$row['mealtype']; echo "<div class='pure-u-1-3'><h1>".strtoupper($mealtype)."</h1>"; $mealquery = "select * `meals` `mealtype` = '".$mealtype."'"; $mealresult = $db->query($mealquery); $mealrow = $result->fetch_assoc(); echo $db->error; while($mealrow = $mealresult->fetch_assoc()){ echo "<b>".$mealrow['name']."</b>".$mealrow['price'].'<br>'; } echo "</div>"; } } $db->close(); ?> i noted without mysqli_report(mysqli_report_all ^ mysqli_report_index); warning, understanding due use of distinct selector.
when error reporting activated returns
php fatal error: uncaught exception 'mysqli_sql_exception' message 'no index used in query/prepared statement select distinct `mealtype` `meals`' in (workingdir)/index.php:42 i'm @ complete loss why won't display everything, i'm sure it's double loop, when ask return table in menu manager works fine.
edit : issue turned out 1d13t error, should have payed more attention code.
you have $row = $result->fetch_assoc(); in code
while error, impressed with, irrelevant problem.
by way, best setting mysqli report is
mysqli_report(mysqli_report_error | mysqli_report_strict); i wish kind of questions legitimate , welcome, yet entitled deletion right after being solved.
Comments
Post a Comment