jeudi 23 juin 2016

Counter in PHP/MySQL

so I'm quite new to PHP and I want to implement a counter. My scenario is for example, if I type the word "dog" in the search bar of the site I'm developing, it will display the list of all dogs in my database and on top of the list, it will display how many matches are there, say "Number of dogs: ".. Here is an excerpt of the code so far. Apart from listing the matches (from another working function I made), it doesn't do anything. function countStores($conn, $match) { $columns = "FieldResearcher, Mall, NameOfStore, Floor, Building, AMEX"; $table = "final"; $conditions = "NameOfStore LIKE '%$match%' "; $query = "SELECT count(NameOfStore) FROM $table where $conditions"; $result = mysqli_query($conn, $query); if ($result == FALSE) { echo "Invalid query: " . $conn->error; echo "<br/>"; return; } echo "Number of Stores: " . $query; $actionStr = $_SERVER['PHP_SELF']; // TODO while ( $row = mysqli_fetch_row($result) ) { echo "<tr>"; for ($i = 0; $i < count($row); $i++) { echo "<td>" . $row[$i] . "</td>"; } echo "<td>"; // TODO echo "<form method="POST" action="$actionStr">"; // TODO echo "<input type="hidden" name="code" value="$row[0]">"; //echo "<input type="submit" value="BUY!">"; // TODO echo "</form>"; // TODO echo "</td>"; // TODO echo "</tr>"; } echo "</tbody>"; echo "</table>"; }

Aucun commentaire:

Enregistrer un commentaire