php - Data Only Returned For 1st DB Call -
i populating 4 selects same query 1st select gets populated , sub-sequent ones not. matter of fact once reaches second select page_load() stops.
questions:
1) causing page_load stop?
2) there way re-use code not have make multiple db calls return same data?
here syntax:
<div id="orderinfo" runat="server"> <table id="orderinginfo"> <tr> <td> <label for="labelselect">choose item</label> <select> <option value="null" selected="selected"></option> <?php include 'phpquery.php'; $sql = "select item items"; echo get_items($sql); ?> </select> </td> </tr> <tr> <td> <label for="labelselect1">choose item:</label> <select> <option value="null" selected="selected"></option> <?php include 'phpquery.php'; $sql = "select item items"; echo get_items($sql); ?> </select> </td> </tr> </table> </div> <?php function get_items($sql) { $servername = "localhost"; $username = "user"; $password = "pass"; $dbname = "database"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "<option value=".$row['item'].">".$row['item']."</option><br>"; } } else echo "<option value='null'>default</option>"; $conn->close(); } ?>
you re-defining function or class in phpquery.php
. php aborts when try redefine such function or class. consider including file phpquery.php
once , run function get_items
. can use include_once
or require_once
.
require_once()
, include_once()
statement can used include php file in one, when may need include called file more once. if found file has been included, calling script going ignore further inclusions.
Comments
Post a Comment