pagination problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cylleezz
Forum Newbie
Posts: 3
Joined: Wed Feb 16, 2005 11:46 am

pagination problem

Post by cylleezz »

I have problem in displaying the data that have more than one pages. While accessing to the second page to view the data it will display the error :

Notice: Undefined index: selectMajor in C:\Program Files\Apache Group\Apache2\htdocs\8_ jan\finding_ groupmate\groupmate_result.php on line 4

Notice: Undefined index: selectGender in C:\Program Files\Apache Group\Apache2\htdocs\8_ jan\finding_ groupmate\groupmate_result.php on line 5

Notice: Undefined index: selectRace in C:\Program Files\Apache Group\Apache2\htdocs\8_ jan\finding_ groupmate\groupmate_result.php on line 6


These selectMajor,selectGender and selectRace are take from the previous page that post to this pages.
Below is the scripts:

Code: Select all

<?php 


$major=$_POST&#1111;'selectMajor'];
$gender=$_POST&#1111;'selectGender'];
$race=$_POST&#1111;'selectRace'];



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/pre_home.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link href="../style.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../slideshow.js"></script>
<script language="javascript" src="../mainlink.js"></script>

</head>

<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" onLoad="MM_preloadImages('../images/link/on_announcement.gif','../images/link/on_groupmate.gif','../images/link/on_archive.gif','../images/link/on_resource.gif','../images/link/on_guideline.gif','../images/link/on_forum.gif')">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="996"><div id="globalNav">
<div id="globalNav">
<div align="right">
<a href="index.html">Home</a> | 
<a href="pre_login.html">Login</a> | 
<a href="../main/aboutus.html">About Us</a> | 
<a href="../main/sitemap.html">Sitemap</a> | 
<a href="../sub/feedback.html">Feedback</a> &nbsp; 
</div>
</div></td>
</tr>
<tr>
<td><img src="../images/banner.gif" width="100%" height="80"></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#000000">
<td width="69%">
<img src="../images/link/linkspace.gif">
<a href="announcement.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image2','','../images/link/on_announcement.gif',1)">
<img src="../images/link/off_announcement.gif" name="Image2" width="119" height="18" border="0"></a>
<a href="groupmate.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','../images/link/on_groupmate.gif',1)">
<img src="../images/link/off_groupmate.gif" name="Image3" width="93" height="18" border="0"></a>
<a href="archive.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image4','','../images/link/on_archive.gif',1)">
<img src="../images/link/off_archive.gif" name="Image4" width="69" height="18" border="0"></a>
<a href="resource.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','../images/link/on_resource.gif',1)">
<img src="../images/link/off_resource.gif" name="Image5" width="85" height="18" border="0"></a>
<a href="guideline.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image6','','../images/link/on_guideline.gif',1)">
<img src="../images/link/off_guideline.gif" name="Image6" width="82" height="18" border="0"></a>
<a href="forum.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image7','','../images/link/on_forum.gif',1)">
<img src="../images/link/off_forum.gif" name="Image7" width="60" height="18" border="0"></a>
</td>
<td width="31%">
<div align="right" class="forCopyright style1"> 
<script language=JavaScript 
src="../date.js"></script></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="157" valign="top"><table width="90%" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><br>
<!-- InstanceBeginEditable name="sublink" -->
<p><span class="nav">GROUPMATE</span><br>
<span class="sublinkSelected"><br>
&nbsp; <img src="../images/blue_dot.gif" width="5" height="5" align="absmiddle">&nbsp; <a href="groupmate.html">List all records</a> <br>
&nbsp; <img src="../images/blue_dot.gif" width="5" height="5" align="absmiddle">&nbsp; <a href="groupmate_post.html">Post a message</a><br>
&nbsp; <img src="../images/blue_dot.gif" width="5" height="5" align="absmiddle">&nbsp; <a href="groupmate_search.html">Search groupmate<br>
</a></span><br>
</p>
<p>&nbsp;</p>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table></td>
<td width="12">&nbsp;</td>
<td width="742" valign="top"><table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<th scope="col" valign="top"><!-- InstanceBeginEditable name="header" -->
<div align="left" class="sub-header"><br>
Groupmate Search </div>

<!-- InstanceEndEditable --></th>
</tr>
<tr>
<td class="tableContentes" valign="top"><!-- InstanceBeginEditable name="contents" --><span class="tableContentes">&nbsp;Search result</span><br>
//start display
<br>
<?php 

define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'temp_database');


@mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("ERROR--CAN'T CONNECT TO SERVER"); 
@mysql_select_db(DB_NAME) or die("ERROR--CAN'T CONNECT TO DB"); 


// Number of records to show per page:
$display = 2;

// Determine how many pages there are. 
if (isset($_GET&#1111;'np'])) &#123; // Already been determined.
$num_pages = $_GET&#1111;'np'];
&#125; else &#123; // Need to determine.

$query="SELECT * FROM groupmate WHERE gm_major='$major' AND gm_gender='$gender' AND gm_race='$race'"; 
$query_result = mysql_query ($query);
$num_records = @mysql_num_rows ($query_result);

if ($num_records > $display) &#123; // More than 1 page.
$num_pages = ceil ($num_records/$display);
&#125; else &#123;
$num_pages = 1;
&#125;
&#125;

// Determine where in the database to start returning results.
if (isset($_GET&#1111;'s'])) &#123; // Already been determined.
$start = $_GET&#1111;'s'];
&#125; else &#123;
$start = 0;
&#125;


// Make the query.
$query="SELECT * FROM groupmate WHERE gm_major='$major' AND gm_gender='$gender' AND gm_race='$race' LIMIT $start, $display";
$result = @mysql_query ($query); // Run the query.
$num = mysql_num_rows ($result); // How many users are there?

if ($num > 0) &#123; // If it ran OK, display the records.

// Table header.
echo"<p style="font-weight: bold">Search Result</p>";

//navigation status bar

$navigation_query="SELECT * FROM groupmate WHERE gm_major='$major' AND gm_gender='$gender' AND gm_race='$race'";
$navigation_query_result = mysql_query ($navigation_query);
$navigation_num_records = @mysql_num_rows ($navigation_query_result);

echo'<p align="right">';
echo "<span style=" font-size:13; font-family: Arial, Helvetica, sans-serif">Results </span>";
echo "<span style="font-weight: bold; font-size:13; font-family: Arial, Helvetica, sans-serif">". ($start + 1)."</span>"; 
echo ' - '; 
echo "<span style="font-weight: bold; font-size:13; font-family: Arial, Helvetica, sans-serif">". min($start + $display, $navigation_num_records)."</span>";
echo ' of '; 
echo "<span style="font-weight: bold; font-size:13; font-family: Arial, Helvetica, sans-serif">". $navigation_num_records."</span>";
echo'</p>';

// end of navigation bar

echo'<table width="100%" border="0" cellspacing="3" cellpadding="3">';

static $nrow;
$nrow = $start + 1; 

while($row=mysql_fetch_array($result,MYSQL_NUM))&#123;
echo" <tr>";
echo"<td width="7%" height="24"><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">". $nrow++ ."</span></td>";
echo"<td width="19%"><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Group ID</span></td>
<td width="4%"><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td width="70%"><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;0]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Name</span></td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;1]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Email</span></td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;2]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Contact</span></td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;3]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Major</span></td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;4]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Gender</span></td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;5]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Race</span></td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;6]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Interest</span></td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;7]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">Remark</span></td>
<td><span style="font-weight: bold; font-family: Arial, Helvetica, sans-serif">:</span></td>
<td><span style="font-family: Arial, Helvetica, sans-serif">$row&#1111;8]</span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><span style="font-family: Arial, Helvetica, sans-serif"><a href="download_file.php?uid=&#123;$row&#1111;'0']&#125;">Download</a></span></td>
</tr>";
echo"
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>";
&#125;

echo'</table>';&#125;

// Make the links to other pages, if necessary.
if ($num_pages > 1) &#123;

//echo '<p>';
echo '<div align="center">';
// Determine what page the script is on. 
$current_page = ($start/$display) + 1;

// If it's not the first page, make a Previous button.
if ($current_page != 1) &#123;
echo '<a href="groupmate_result.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> ';
&#125;

// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) &#123;
if ($i != $current_page) &#123;
echo '<a href="groupmate_result.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> ';
&#125; else &#123;
echo $i . ' ';
&#125;
&#125;

// If it's not the last page, make a Next button.
if ($current_page != $num_pages) &#123;
echo '<a href="groupmate_result.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>';
&#125;

echo'</div>';
echo '</p><br />';

&#125; // End of links section.


mysql_free_result ($result); // Free up the resources 
mysql_close(); // Close the database connection.


?>
<br>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td class="tableContentes" valign="top"><!-- InstanceBeginEditable name="navigator" -->&nbsp;
<div align="center"></div>
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
<td width="89">&nbsp;</td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
Can anyone help me to solve the problem.Thank you!
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

You are mixing metaphors here. In one part of the code you use $_GET and in another part you use $_POST. You can only do one or the other but not both.

Using the $_POST variables implies that the information got there from a form. $_GET typically implies that the page was viewed by clicking a link or typing a URL.

If you are expecting a GET but try to reference a POST, the data won't exist and that gives you the type of error that you are seeing.

You need to add this type of code to each place you access $_GET or $_POST. Changing the variable name and $_GET and $_POST as needed.

Code: Select all

if (isset($_POST&#1111;'selectedMajor'])) &#123;
  $major = $_POST&#1111;'selectedMajor'];
&#125; else &#123;
  $major = '';
&#125;
You may also want to verify the form action to make sure it is doing a post.
Last edited by smpdawg on Wed Mar 02, 2005 8:41 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

looks like your previous page is not passing the POST data to this page. you can try keeping data in session variables for that matter
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

If you may want to use GET or POST use $_REQUEST. Make sure you validate what is passed in though. Common trick to use is floor($_REQUEST['param'] if expecting a numeric value.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

smpdawg wrote:

Code: Select all

if (isset($_POST&#1111;'selectedMajor'])) &#123;
  $major = $_POST&#1111;'selectedMajor'];
&#125; else &#123;
  $major = '';
&#125;
You may also want to verify the form action to make sure it is doing a post.
an easier way to do that is

Code: Select all

$major = (isset($_POST&#1111;'selectedMajor']) ? $_POST&#1111;'selectedMajor'] : '');
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

I posted that in another one of my examples and then decided that I didn't want to explain ternary operators too. ;)
Post Reply