Error Need to fix it

}
function getFAQ() {
$sql = "SELECT * FROM blog1";

// getting parameters required for pagination
$currentPage = 1;
if(isset($_GET['pageNumber'])){
$currentPage = $_GET['pageNumber'];
}
$startPage = ($currentPage-1)*PERPAGE_LIMIT;
if($startPage < 0) $startPage = 0;
$href = "/php_samples/perpage.php?";

//adding limits to select query
$query =  $sql . " limit " . $startPage . "," . PERPAGE_LIMIT; 
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {
$questions[] = $row;
}

if(is_array($questions)){
$questions["page_links"] = paginateResults($sql,$href);
return $questions;
}
}

//function creates page links
function pagination($count, $href) {
$output = '';
if(!isset($_REQUEST["pageNumber"])) $_REQUEST["pageNumber"] = 1;
if(PERPAGE_LIMIT != 0)
$pages  = ceil($count/PERPAGE_LIMIT);

//if pages exists after loop's lower limit
if($pages>1) {
if(($_REQUEST["pageNumber"]-3)>0) {
$output = $output . '<a href="' . $href . 'pageNumber=1" class="page">1</a>';
}
if(($_REQUEST["pageNumber"]-3)>1) {
$output = $output . '...';
}

//Loop for provides links for 2 pages before and after current page
for($i=($_REQUEST["pageNumber"]-2); $i<=($_REQUEST["pageNumber"]+2); $i++)	{
if($i<1) continue;
if($i>$pages) break;
if($_REQUEST["pageNumber"] == $i)
$output = $output . '<span id='.$i.' class="current">'.$i.'</span>';
else				
$output = $output . '<a href="' . $href . "pageNumber=".$i . '" class="page">'.$i.'</a>';
}

//if pages exists after loop's upper limit
if(($pages-($_REQUEST["pageNumber"]+2))>1) {
$output = $output . '...';
}
if(($pages-($_REQUEST["pageNumber"]+2))>0) {
if($_REQUEST["pageNumber"] == $pages)
$output = $output . '<span id=' . ($pages) .' class="current">' . ($pages) .'</span>';
else				
$output = $output . '<a href="' . $href .  "pageNumber=" .($pages) .'" class="page">' . ($pages) .'</a>';
}

}
return $output;
}

//function calculate total records count and trigger pagination function	
function paginateResults($sql, $href) {
$result  = mysql_query($sql);
$count   = mysql_num_rows($result);
$page_links = pagination($count, $href);
return $page_links;
}

Notice : Undefined variable: questions

Need to fix it.

you havent defined $questions at this point, so it doesnt know what to attach this to.

Predefine $questions as an empty array:

$questions = []; or
$questions = array();

and then check the array length of questions instead of if it is an array.

1 Like

still has an error

You need to define / declare variable $questions before this line (out of the while loop:

.

Why are you still using mysql_* functions?

5 Likes

Is it the same error, or a different one? What line does it occur on?

If you used PDO, instead of this block

while($row=mysql_fetch_array($result)) {
$questions[] = $row;
}

you could just use a single line

$questions = $db->fetchAll();

$questions = $row; moved here row
while($row=mysql_fetch_array($result)) {

}

$href
replaceed with $name
no errors but no numbers of the pagination

$questions = $row; moved here row

  • you are assigning $row to $questions but $row hasn’t been declared or defined yet.

Is $row defined before that line?
It needs to be.

Just do that. Don’t assign $row to $questions[] before while.

I am telling you what to do with that specific piece of code, Čapljina.
And why it was wrong.

To debug your entire page is a bit out of scope.

1 Like

Did change that but no numbers havent in jet ,just first row

I usually use this to debug my php code, not sure if you’ll be able to set it up

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.