View Single Post
Old 10-02-2021, 02:35 PM  
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,125
Okay so I had a play around and now I'm getting even more errors.

The data that I want to display is showing what it needs to however, it isn't splitting the results across multiple pages of 10 like its supposed to.

These are the errors I'm getting, which I assumed are related to a misplaced mysqli_close statement somewhere (?) however, I don't see where that close statement can be causing an issue:

Quote:
Warning: mysqli_query() expects at least 2 parameters, 1 given in /blah/blah/domain.com/test/index.php on line 47

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /blah/blah/domain.com/test/index.php on line 48

Warning: mysqli_query() expects at least 2 parameters, 1 given in /blah/blah/domain.com/test/index.php on line 52

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /blah/blah/domain.com/test/index.php on line 53
This is the code I'm using for the pagination, it displays the navigation on the bottom of the page with no issue, but only has a single page showing, even if there are supposed to be 5 or 6:

Quote:
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 10;
$offset = ($pageno-1) * $no_of_records_per_page;

mysqli_connect("localhost","username","password"," database");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

$total_pages_sql = "SELECT COUNT(*) FROM Recipe";
$result = mysqli_query($total_pages_sql);
$total_rows = mysqli_fetch_array($result)[0];
$total_pages = ceil($total_rows / $no_of_records_per_page);

$sql = "SELECT * FROM Recipe LIMIT $offset, $no_of_records_per_page";
$res_data = mysqli_query($sql);
while($row = mysqli_fetch_array($res_data)){
//here goes the data
}
Below that I have this in the HTML in order to display the correct results, which it is doing:

Quote:
<?php

$con=mysqli_connect("localhost","databse","passwor d","username");
$result = mysqli_query($con,"SELECT * FROM Recipe WHERE Ingredients REGEXP 'salt';");

echo "<table border='0'>

<tr>

</tr>";

while($row = mysqli_fetch_array($result))

{

$link = "/test/recipes.php?id=".$row['RecipeID'];

echo "<tr>";

echo "<a href = ". $link . ">" . $row['Title'] . "</a><br>";

echo "</tr>";

}

echo "</table>";
?>
Any ideas what I should be looking for error wise? From what I'm seeing online it appears to be something relating to either the mysqli close statement or something to do with global $con, which I know nothing about

Initially I thought it may have been an issue with the variable naming but that does not seem to be the case.

I'm at a loss, any pointers in the right direction would be appreciated.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote