Jump to content

HREF variables


claro

Recommended Posts

Hi there! I'm trying to put 2 variables using href.

Ive got it already, but when I tried to insert the page=1, which is the the variable for my paginated code.It doesn't work.

 

When I used the codes below, from other page (I don't used variable) it works

<a href='module_viewpaginated.php?page=1'

 

but when I used this code, I've got the variable $course and $program, but I don't know how to insert page for my pagination

<a href='module_viewpaginated.php?course=".$courseid."&program=".$program." '

 

 

I hope my problem is clear. I want to combine the two. Any help would be greatfull!!

Link to comment
Share on other sites

Below are my actual codes for pagination. I can echo the $course and $program already.

 

<?php

$course1 = $_GET['course']; //from selection box
$program = $_GET['program'];//from selection box

//my queries here
$courses = mysql_query ("SELECT * FROM tbl_course WHERE course_Id = '$course1'")
	or die (mysql_error());

        // connect to the database
        include('connect-db.php');
        
        // number of results to show per page
        $per_page = 1;
        
        // figure out the total pages in the database
	echo "<br></br>";
	echo "<td><b>  Course:       <i>".$course."</i></b></td><br/>";
	echo "<td><b>  Program:    <i>".$program." "."Class</b></i></td>";

if (mysql_num_rows($result)> 0 )
{ 
        $total_results = mysql_num_rows($result);
	$total_pages = ceil($total_results / $per_page);

        // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
        if (isset($_GET['page']) && is_numeric($_GET['page']))
        {
                $show_page = $_GET['page'];
                
                // make sure the $show_page value is valid
                if ($show_page > 0 && $show_page <= $total_pages)
                {
                        $start = ($show_page -1) * $per_page;
                        $end = $start + $per_page; 
                }
                else
                {
                        // error - show first set of results
                        $start = 0;
                        $end = $per_page; 
                }               
        }
        else
        {
                // if page isn't set, show first set of results
                $start = 0;
                $end = $per_page; 
        }
        
        // display pagination
       
        echo "<p><a href='module2.php'>View All</a> | <b>View Page:</b> ";
        for ($i = 1; $i <= $total_pages; $i++)
        {
                echo "<a href='view-paginated_admin.php?course=".$courseid."&program=".$program."'>$i</a> ";
        }
        echo "</p>";
                
        // display data in table
        echo "<table border='1' cellpadding='10'>";
	echo "<tr>";
	   echo "<td></td><td></td><td></td><td></td><th>Student's Name</th><th>Year</th><th>Cleared</th><th>Not Cleared</th>";
echo "</tr>";




    
    // loop through results of database query, displaying them in the table 
        for ($i = $start; $i < $end; $i++)
        {
                // make sure that PHP doesn't try to show results that don't exist
                if ($i == $total_results) { break; }
        
                // echo out the contents of each row into a table
			//data data


                echo "  <input type='submit' name = 'Submit' value='Submit'>";


	}
}
else
{

	echo "<br/><br/>no students enrolled";
	}




        // close table>
        echo "</table>"; 
        
        
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.