 |
| Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 9th, 2004, 01:02 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I need some help with paginating.
Hi. I need some help with paginating. I have tried solving this problem by myself. I think I know why I have received this error message:
"Notice: Undefined index: title_text in c:\program files\apache group\apache\htdocs\searchresult2.php on line 174
&nsbp;Sorry. You have not entered any keyword to search. Please retry search."
I cannot pass the variable $title_text to the next page...2,3,4, and so forth. I do not know how to solve this problem.
I hope someone can help me out with this problem.
Thanks.
Best regards,
Major
<html>
<head><title>Search Result</title></head>
<body bgcolor="#ffffff" link="#000066" alink="#cc0000" vlink="#666666" marginwidth="0" marginheight="0" leftmargin="5" rightmargin="5" topmargin="5">
<style>
<!--
A { text-decoration:none; }
A:link { color: #CD2626;}
A:active { color: #CD2626;}
A:visited { color: #CD2626;}
A:hover { color:#CD2626; text-decoration:underline; }
//--></style>
<link rel="stylesheet" href="newfontslib.css" type="text/css">
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699><tr>
<td width=65% bgcolor="#8FBC8F">
<center>
<img src="./picturefiles/company_logo.jpg" border=1 align=bottom> <br/>
<b>IKHTIAR</b>
<b>RESOURCES</b>
</center>
</td>
</table>
</td></tr>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=100% height=35>
<tr>
<td width=20 bgcolor=#EEE9BF></td>
<td bgcolor=#EEE9BF>
<center>
<form method=get action="searchresult2.php"><br/>
<b class="black5">Search</b>
<input type="text" name="title_text" size=45>
<input type="submit" value=" Submit "> <input type="reset" value=" Clear ">
<a href="searchtip.php">Search tip</a>
</form>
</center>
</td>
</tr>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=100% height=2>
<tr>
<td width=100% bgcolor=#000000></td>
</tr>
</table>
<p>
<table border=0 width=100% height=100 cellspacing=0 cellpadding=5>
<tr><td width=155 valign=top>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699>
<tr><td height=20> <b class="white3">Browse Site</b></td></tr>
<tr>
<td bgcolor=#ffffff>
<img src="./picturefiles/bb006.gif">
<a href="aboutus.php"><b class="red3">About Us</b></a>
</td>
</tr>
<tr>
<td bgcolor=#ffffff>
<img src="./picturefiles/bb006.gif">
<a href="emailus2.php"><b class="red3">Email Us</b></a>
</td>
</tr>
<tr>
<td bgcolor=#ffffff>
<img src="./picturefiles/bb006.gif">
<a href="sitemap.php"><b class="red3">Site Map</b></a>
</td>
</tr>
<tr>
<td bgcolor=#ffffff>
<img src="./picturefiles/bb006.gif">
<a href="faq2.php"><b class="red3">FAQ's</b></a><br/>
</td>
</tr>
</table>
</td></tr>
</table>
<p>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699>
<tr>
<td bgcolor=#ffffff><br/>
<b class="red3">Electronic Media</b><br>
<img src="./picturefiles/arrow.gif"> Gym Equipment
</td>
</tr>
<tr>
<td bgcolor=#ffffff><br/>
<b class="red3">Printed Media</b><br>
<img src="./picturefiles/arrow.gif"> <a href="books.php">Books</a>
<br/>
<img src="./picturefiles/arrow.gif"> Medical Charts
</td>
</tr>
<tr>
<td bgcolor=#ffffff><br/>
<b class="red3">Sports & Fitness</b><br>
<img src="./picturefiles/arrow.gif"> <a href="gymequipment2.php">Gym Equipment</a>
</td>
</tr>
<tr>
<td bgcolor=#ffffff><br/>
<b class="red3">Office & Furnishing</b><br>
<img src="./picturefiles/arrow.gif"> <a href="officeequipment2.php">Office Equipment</a>
<p>
</td>
</tr>
</table>
</td></tr>
</table>
<p>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=10 cellspacing=0 bgcolor=#666699>
<tr>
<td bgcolor=#ffffff><center><br>
<b class="black4">Download Acrobat Reader</b><br><br>
<a href="http://www.acrobat.com"><img src="./picturefiles/acrobatreader.jpg" border=0></a>
<br><br>
<b>Note:</b> The symbol <img src="./picturefiles/iconacrobat.jpg" align=bottom> throughout this website indicates that the document is a PDF formatted document. Please make sure that your local machine has Adobe® Acrobat Reader installed.<br><br>
</center>
</td>
</tr>
</table>
</td></tr>
</table>
</td>
<td width=10></td>
<td valign=top>
<?php
include("./exc/psal.inc");
$title_text = $HTTP_GET_VARS['title_text'];
$title_text == trim($title_text);
if (!$title_text) {
echo '&nsbp;Sorry. You have not entered any keyword to search. Please retry search.';
} // end of if statement
else {
$title_text = addslashes($title_text);
if (!isset($_GET['page'])) { $page = 1; }
else { $page = $_GET['page']; }
$max_results = 10;
$from = (($page * $max_results) - $max_results);
$query = "select * from books_categories where title like '%".$title_text."%' limit $from, $max_results";
$result = mysql_query($query) or die("Error in search text");
$num_result = mysql_num_rows($result);
if ($num_result == 0) {
echo '<br><br>Oops! No such record found in the database. Please try another keyword.';
} // end of if statement
else {
echo '<br>';
if ($num_result == 1) { echo 'Displaying '.$num_result.' record'; }
else { echo 'Displaying '.$num_result.' records'; }
echo '<br><br>';
while($row = mysql_fetch_object($result)) { ?>
<li><a href="bookdetails2.php?id=<? echo$row->isbn_category; ?>">
<? echo $row->title; ?>
</a><br/>
<? }
$total_results = mysql_result(mysql_query("select count(*) as num from books_categories"),0);
$total_pages = ceil($total_results / $max_results);
echo "Select a page";
if ($page > 1) {
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for ($i=1; $i<=$total_pages; $i++) {
if (($page) == $i) {
echo "$i ";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
if ($page < $total_pages) {
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
} // end of else statement
}
mysql_close($connection);
echo '</ul>';
?>
</td>
<td width=10></td>
<td width=140 valign=top>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699><tr>
<td width=70% bgcolor=#ffffff><center>
<img src="./picturefiles/shoppingcart.jpg" align=bottom>
Shopping cart value
<br><br></center>
</td>
</table>
</td></tr>
</table>
<p>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699><tr>
<td width=70% bgcolor=#ffffff><center><br>
Chat with our customer service agents <b>ONLINE</b>
<br><br>
<a href="http://chat.boldchat.com/chat/visitor.jsp?cdid=2150385581" target="_blank" onClick="this.newWindow = window.open('http://chat.boldchat.com/chat/visitor.jsp?cdid=2150385581&url=' + document.location, 'Chat', 'toolbar=0,scrollbars=1,location=0,statusbar=0,men ubar=0,resizable=1,width=640,height=480'); this.newWindow.focus(); this.newWindow.opener = window;return false;"><img alt="Live chat by Boldchat" src="http://www.boldchat.com/bh.ci/2150385581" width="133" height="34" border="0"></a>
<br/>
<a href="http://www.boldchat.com">Live help by Boldchat</a><br><br><br>
</center>
</td>
</table>
</td></tr>
</table>
<p>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699><tr>
<td width=70% bgcolor=#ffffff><center><br>
<b class="black2">Website proudly supported and designed with</b>
<p>
<a href="http://www.mysql.com" target="_blank"><img src="./picturefiles/poweredbymysql.jpg" border=0 alt="Click here to go to MySQL's website"></a>
<br>MySQL database
<p>
<a href="http://www.php.net" target="_blank"><img src="./picturefiles/poweredbyphp.jpg" border=0 alt="Click here to go to PHP's website"></a>
<br>PHP compiler
<p>
<a href="http://www.w3.org" target="_blank"><img src="./picturefiles/madewithcss.jpg" border=0 alt="Click here to go to World Wide Web Consortium's website"></a>
<br>Cascading Style Sheet
<p>
<a href="http://www.w3.org" target="_blank"><img src="./picturefiles/madewithhtml4.jpg" border=0 alt="Click here to go to World Wide Web Consortium's website"></a>
<br>HTML programming
<p>
</center>
</td>
</table>
</td></tr>
</table>
</td>
</table>
<p>
<center><br>
Copyright © Ikhtiar Resources Sdn. Bhd. <i>Updated on 25th February 2004</i><br><br>
<b class="black4">
ikhtiar_resources <img src="./picturefiles/email.jpg" align=top> time.net.my</b>
<br><br>
</center>
</body>
</html>
|
|

March 10th, 2004, 10:26 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
|
|
the best thing for accessing/operating on variables on many pages is to use $_SESSION array... check php.net for more about sessions..
peace out :D
the genuine genius
|
|

March 10th, 2004, 01:20 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
In case you were wondering which page session info is on...
http://php.net/session
Remeber to start every page that has sessions with session_start()!
----------
---Snib---
----------
|
|

March 10th, 2004, 11:16 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi. First and foremost, thanks for helping me out with this programming problem. I've tried using $_SESSIONS, but it didn't work. It still give me the same error message which I've posted here.
Regards,
Major
|
|

March 11th, 2004, 04:02 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
The page you have posted is expecting to get the title_text variable from the address bar, but it isnt set.
So, put all your PHP that reads the title_text variable in if() like this:
if(isset($_GET['title_text']))
{
//here is where you put all the PHP that reads title_text
}
else echo "the form that lets you set title_text";
Let me know if you need further explanations on this,
----------
---Snib---
----------
|
|

March 11th, 2004, 10:13 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi. Thanks for your reply. I think I really need to get an explanation on what the if(isset) statement does.
By the way, can you also tell me where I need to place the if() statement? Maybe you can show me the exact location. I am not an IT techie and I am learning php all by myself.
Thanks again.
Regards,
Major
|
|

March 11th, 2004, 10:46 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi. I've solved the problem by inserting the if(isset) statement.
Now, I have another problem. For example, I have a search result of 100 book titles. I managed to display the first 10 book titles on page 1.
The header on the browser is:
"http://localhost/searchresult2.php?title_text=a"
However, when I click page 2, I am unable to display the book titles on the second page. I am not sure why. I hope you can help me out with this problem.
The header on the browser is:
"http://localhost/searchresult2.php?page=2"
Thanks.
Regards,
Major
// Below is the corrected source code:
<html>
<head><title>Search Result</title></head>
<body bgcolor="#ffffff" link="#000066" alink="#cc0000" vlink="#666666" marginwidth="0" marginheight="0" leftmargin="5" rightmargin="5" topmargin="5">
<style>
<!--
A { text-decoration:none; }
A:link { color: #CD2626;}
A:active { color: #CD2626;}
A:visited { color: #CD2626;}
A:hover { color:#CD2626; text-decoration:underline; }
//--></style>
<link rel="stylesheet" href="newfontslib.css" type="text/css">
<table border=0 cellpadding=0 cellspacing=0 width=100% height=35>
<tr>
<td width=20 bgcolor=#EEE9BF></td>
<td bgcolor=#EEE9BF>
<center>
<form method=get action="<? $_SERVER['PHP_SELF'] ?>"><br/>
<b class="black5">Search</b>
<input type="text" name="title_text" size=45>
<input type="submit" value=" Submit "> <input type="reset" value=" Clear ">
<a href="searchtip.php">Search tip</a>
</form>
</center>
</td>
</tr>
</table>
<table border=0 cellpadding=0 cellspacing=0 width=100% height=2>
<tr>
<td width=100% bgcolor=#000000></td>
</tr>
</table>
<p>
<table border=0 width=100% height=100 cellspacing=0 cellpadding=5>
<tr><td width=155 valign=top>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699>
<tr><td height=20> <b class="white3">Browse Site</b></td></tr>
<tr>
<td bgcolor=#ffffff>
<img src="./picturefiles/bb006.gif">
<a href="aboutus.php"><b class="red3">About Us</b></a>
</td>
</tr>
<tr>
<td bgcolor=#ffffff>
<img src="./picturefiles/bb006.gif">
<a href="emailus2.php"><b class="red3">Email Us</b></a>
</td>
</tr>
<tr>
<td bgcolor=#ffffff>
<img src="./picturefiles/bb006.gif">
<a href="sitemap.php"><b class="red3">Site Map</b></a>
</td>
</tr>
<tr>
<td bgcolor=#ffffff>
<img src="./picturefiles/bb006.gif">
<a href="faq2.php"><b class="red3">FAQ's</b></a><br/>
</td>
</tr>
</table>
</td></tr>
</table>
<p>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699>
<tr>
<td bgcolor=#ffffff><br/>
<b class="red3">Electronic Media</b><br>
<img src="./picturefiles/arrow.gif"> Gym Equipment
</td>
</tr>
<tr>
<td bgcolor=#ffffff><br/>
<b class="red3">Printed Media</b><br>
<img src="./picturefiles/arrow.gif"> <a href="books.php">Books</a>
<br/>
<img src="./picturefiles/arrow.gif"> Medical Charts
</td>
</tr>
<tr>
<td bgcolor=#ffffff><br/>
<b class="red3">Sports & Fitness</b><br>
<img src="./picturefiles/arrow.gif"> <a href="gymequipment2.php">Gym Equipment</a>
</td>
</tr>
<tr>
<td bgcolor=#ffffff><br/>
<b class="red3">Office & Furnishing</b><br>
<img src="./picturefiles/arrow.gif"> <a href="officeequipment2.php">Office Equipment</a>
<p>
</td>
</tr>
</table>
</td></tr>
</table>
<p>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=10 cellspacing=0 bgcolor=#666699>
<tr>
<td bgcolor=#ffffff><center><br>
<b class="black4">Download Acrobat Reader</b><br><br>
<a href="http://www.acrobat.com"><img src="./picturefiles/acrobatreader.jpg" border=0></a>
<br><br>
<b>Note:</b> The symbol <img src="./picturefiles/iconacrobat.jpg" align=bottom> throughout this website indicates that the document is a PDF formatted document. Please make sure that your local machine has Adobe® Acrobat Reader installed.<br><br>
</center>
</td>
</tr>
</table>
</td></tr>
</table>
</td>
<td width=10></td>
<td valign=top>
<?php
include("./exc/psal.inc");
// if (!isset($_GET['title_text'])) {
// echo ' Sorry. You have not
// entered any keyword to search. Please retry search.';
// } // end of if statement
if (isset($_GET['title_text'])) {
$title_text = $HTTP_GET_VARS['title_text'];
$title_text = trim($title_text);
$title_text = addslashes($title_text);
if (!isset($_GET['page'])) { $page = 1; }
else { $page = $_GET['page']; }
$max_results = 10;
$from = (($page * $max_results) - $max_results);
$query = "select * from books_categories where title like '%".$_GET['title_text']."%' order by title limit $from, $max_results";
$result = mysql_query($query) or die("Error in search text");
$num_result = mysql_num_rows($result);
while($row = mysql_fetch_object($result)) {
echo '<li><a href="bookdetails2.php?id=<? echo $row->isbn_category; ?>">'.
$row->title
.'</a><br/>';
}
$total_results = mysql_result(mysql_query("select count(*) as num from books_categories where title like '%".$_GET['title_text']."%'"),0);
$total_pages = ceil($total_results / $max_results);
if ($page > 1) {
$prev = ($page-1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Previous</a> ";
}
for($i=1; $i<=$total_pages; $i++) {
if ($page==$i) {
echo "$i ";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
if ($page < $total_pages) {
$next = ($page+1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next</a>";
}
echo '<br><br><br>';
} // end of else
mysql_close($connection);
echo '</ul>';
?>
</td>
<td width=10></td>
<td width=140 valign=top>
<TABLE border=0 width=100% height=40 cellpadding=1 cellspacing=0 bgcolor=#666699><tr>
<td width=100%>
<TABLE width=100% height=100 border=0 cellpadding=4 cellspacing=0 bgcolor=#666699><tr>
<td width=70% bgcolor=#ffffff><center>
<img src="./picturefiles/shoppingcart.jpg" align=bottom>
Shopping cart value
<br><br></center>
</td>
</table>
</td></tr>
</table>
</body>
</html>
|
|

March 12th, 2004, 04:46 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Make sure you're passing ALL the appropriate variables you need. Your post was too long for me to read in detail, but I noticed that your first page had a GET parameter named title_text. This is missing from your page=2 link. You probably need a title_text=a&page=2 query string.
Take care,
Nik
http://www.bigaction.org/
|
|

March 15th, 2004, 03:07 AM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi, Nikolai. I need some explanation on your solution. How can I correct the error?
Thanks.
Regards,
Major
|
|

March 17th, 2004, 09:40 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, it's pretty straight forward. The way I like to do it is create an array that holds all my query param variables:
$queryparams = array("page=2", "title_text=a", "whatever=whoever");
Then, join all these params with an ampersand:
$query_string = join("&", $queryparams);
And append this query string to your URL:
$url = "http://.../some_file.php?{$query_string}";
Take care,
Nik
http://www.bigaction.org/
|
|
 |