I currently have a table called category in my database
category
catId categoy
- News
- HTML
- PHP
- CSS
Trying to pull back off rows from the database only brings back the 1 result using the following code
private function navigation(){
$url = BASE_URL;
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$dbc) {
trigger_error('Could not connect to MySQL:' .mysqli_error());
}
$query = "SELECT catId, category AS 'catName' FROM category ORDER BY catName DESC";
$result = mysqli_query($dbc, $query) or trigger_error("Query: $query\n<br>MySQL Error: ");
while($row = mysqli_fetch_array($result)){
$name = $row['catName'];
$catId = $row['catId'];
$this -> nav =<<<NAVIGATION
<li>$name</li>
<p>test</p>
NAVIGATION;
}
}
I have tried doing it outside a function and all rows are brought back without problem.
$querying = "SELECT catId, category AS 'catName' FROM category ORDER BY catName ASC";
$results = mysqli_query($dbc, $querying) or trigger_error("Query: $query\n<br>MySQL Error: ");
while($row = mysqli_fetch_array($results)){
$name = $row['catName'];
$catId = $row['catId'];
$page->body ("$name");
}
I was wondering if someone could guide me in where I am going wrong.
Thank you in advance.