Jump to content

[SOLVED] Passing variables


unai

Recommended Posts

Hi Guys, I am having some in passing variables to another page. I think, maybe the variable is

passing empty, but I can't see why. Below is the code for the pages that variable has to go from

and to. Thanks!

 

From page

<?php

  require_once('../includes/functions.php');

      require_once('../includes/session.php');

      //require_once('../includes/user.php');

      require_once('../includes/pagination.php');

      require_once('../includes/lyrics.php');

 

 

 

    //1. the current page number ($current_page)

$page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;

//2. records per page ($per_page)

$per_page = 6;

//3. total record count ($total_count)

$total_count = Lyrics::count_all();

 

    // Find all lyrics

//use pagination instead

    //$lyrics = Lyrics::find_all();

    $pagination = new Pagination($page, $per_page, $total_count);

// Instead of finding all records, just find the records for this page

$sql = "SELECT * FROM lyrics ";

$sql .= "LIMIT {$per_page} ";

$sql .= "OFFSET {$pagination->offset()}";

$lyrics = Lyrics::find_by_sql($sql);

 

// Need to add ?page=$page to all links we want to

// maintain the current page (or store $page in $session)

  ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">

<head>

<link rel="stylesheet" type="text/css" href="../public/stylesheet/mystyle.css" />

<title>Capoeira Village - lyrics</title>

</head>

<html>

    <body>

    <?php include("../public/layouts/header.php"); ?> 

<div id="text">

        <div id="header">

        <h1 class="welcome">Capoeira Lyrics</h1>

    </div>

<div id= "lyrics_list">

    <ul>

                        <?php foreach($lyrics as $lyric): ?>                

            <li><a href="details.php?lyrics_name=<?php echo $lyric->lyrics_name; ?>  "><?php echo $lyric->lyrics_name; ?></a></li>                    

<?php endforeach; ?>

       

 

            </ul>

                </div>

       

               

            <div id="pages">

                        <ul>

                    <?php

                        if($pagination->total_pages() > 1) {

                    if($pagination->has_previous_page()) {

                    echo "<li><a href=\"index.php?page=";

                echo $pagination->previous_page();

                echo "\">« Previous</a></li> ";

                }

            for($i=1; $i <= $pagination->total_pages(); $i++) {

                if($i == $page) {

                echo " <span class=\"selected\">{$i}</span> ";

                } else{

                    echo " <li><a href=\"index.php?page={$i}\">{$i}</a></li> ";

                } 

            }

                if($pagination->has_next_page()) {

                echo "<li><a href=\"index.php?page=";

            echo $pagination->next_page();

            echo "\">Next »</a></li> ";

            }

                }

 

$page = $_GET['page'];

 

                    ?>

</ul>

        </div>

</div>

       

    </body>

</html>

 

 

to page

 

<?php

  require_once('../includes/functions.php');

      require_once('../includes/session.php');

      //require_once('../includes/user.php');

      require_once('../includes/pagination.php');

      require_once('../includes/lyrics.php');

      require_once('../includes/database.php');

 

 

//if (!$session->is_logged_in()){ redirect_to("login.php");}

 

 

$lyrics = Lyrics::find_by_name($sql = ($_GET['lyrics_name']));

 

$page = $_GET['page'];

 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">

    <head>

    <link rel="stylesheet" type="text/css" href="../public/stylesheet/mystyle.css" />

    <title><?php echo $lyrics->lyrics_name; ?></title>

    </head>

    <body>

        <?php include("../public/layouts/header.php"); ?>

        <div id="details">

    <div id="back">                     

        <a title="back to lyrics list page" href="index.php" >« Back</a>                     

    </div>

    <?php echo $pages; ?>

 

<div id="content_lyrics"><?php echo $lyrics->text; ?></div>

        </div>

    </body>

 

</html>

Thanks again!!!

Link to comment
https://forums.phpfreaks.com/topic/177779-solved-passing-variables/
Share on other sites

I didn't explained my problem before, sorry about that.

I am trying to pass the two variables to another page, um is the name of the song, $song_name,

the other is the page number, the original page is list of song names displayed using pagination,

I could do it when I wasn't using object oriented. I've tried passing it through the Url and with session but no joy. Again thanks!!

 

sessions are the way to go.....

 

page1.php

<?php
session_start(); // THIS IS THE MOST IMPORTANT PART

$_SESSION['item_1'] = 'This is the correct';
$_SESSION['item_2'] = 'way to use a session var';


?>

page2.php

 

<?php
session_start(); // GOT TO START IT AGAIN

echo $_SESSION['item_1'].' '.$_SESSION['item_2'];

?>

 

Should output

 

This is the correct way to use a session var

Thank you Chronister, but the problem, a think, is that the variable is not passing to the other page,

maybe the way the variable $page is being used in the code, $page is an attribute of the pagination

class and I am trying to use it twice in the same  page, it is confusing me some how. Thanks anyway. 

Hi Warz I echoed on the page I want to send the variable two, that's way I know the variable is going empty. The same variable is being used on the page for the pagination, check the code and you will see it, and it works, I send it through the Url and it works, thank you anyway!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.