I'm working on a project which I use a database to store some books information. At the first step, I put all the book ID from a database into an array, and use the array to create a image list. Here's my program to generate the variables $previous_index & $next_index from an array $book_list, where $book_list store all the ID of the books in the whole database:
while($row = mysqli_fetch_array($sql)) {
$current_index = find_array_index($current_id,$book_list);
$next_index = $current_index + 1;
$previous_index = $current_index - 1;
// previous key / returns false if result found at first key
if ($previous_index >= 0) {
$previous_id = $book_list[$previous_index];
}
else {
$previous_id = 'Null';
}
// previous key / returns false if result found at first key
if ($next_index <= sizeof($book_list)) {
$next_id = $g_list[$next_index];
}
else {
$next_id = 'Null';
}
When the user click the image list, they will be guided to another page, say detail page, which will shows all the details of the book, say price, author...... And also, I've designed two buttons, previous and next, so that users can move to next book without going back to the main list. I tried to pass the array $book_list to the detail page using serialize method:
// pass global array between pages
$global_array = urlencode(serialize($book_list));
$link = 'book_detail.php?id=' . $current_id . '&array=' . $global_array ;
and get content of the array in the detail page:
print_r(unserialize(urldecode(stripslashes($_GET['array']))));
However, it shows nothing in the print_r function.
Is there something wrong with my program ? And is there an alternative way to fulfil my requirement, without passing array between several php pages ?
Grateful if someone can give me hints.