Current location: Hot Scripts Forums » Programming Languages » PHP » Next button


Next button

Reply
  #1 (permalink)  
Old 06-12-04, 05:23 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Next button

Hi, i have a small script that lets users search through a DB. It will display everything that is relevant. Could someone direct me on how i could have a next page button. Like this: Next - 1 - 2 - 3 - 4 - 5 -
The numbers being links to further pages. Thank you.
Reply With Quote
  #2 (permalink)  
Old 06-12-04, 06:17 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 06-12-04, 07:19 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Ok i tried what he said, although i am getting a parse error (starts at $SQL) , and i see none. Also, could someone scan this code, and determine if it will work (if i get the parse fixed). Here is my code:

<?php
$connect = @mysql_connect("localhost", "asdf", "asdf") or die("could not connect to server");

$db_select = @mysql_select_db("asdf") or die("could not select the database");

$SQL = "SELECT * FROM itemsearch WHERE itemname LIKE \"%$user_input%\" LIMIT $startrow, 10");

//check if this is the first page
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
//we give the value of the first row to 0
$startrow = 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)$_GET['startrow'];
}

$result = @mysql_query($SQL) or die("Could not run query");



while($row = mysql_fetch_array($result))
{
echo("<tr>");
echo("<td class='cntbxleft'> &nbsp;");
$url = ("$row[url]");
echo("<a class='bluetu' href='$url'>$row[itemname]</a></td>");
echo("<td class='cntbxmid'>$row[str] &nbsp;</td>");
echo("<td class='cntbxmid'>$row[agi] &nbsp;</td>");
echo("<td class='cntbxmid'>$row[sta] &nbsp;</td>");
echo("<td class='cntbxmid'>$row[int] &nbsp;</td>");
echo("<td class='cntbxmid'>$row[wis] &nbsp;</td>");
echo("<td class='cntbxright'>$row[effect_one] &nbsp;");
echo("</tr>");
}

//now this is the link..
echo "<tr><td><a href="itemsearch.php?startrow='.($SQL+10).'">Next</a></td></tr>";

?>
Reply With Quote
  #4 (permalink)  
Old 06-12-04, 07:48 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
You forgot the opening " ( " in your query.

$SQL = ("SELECT * FROM itemsearch WHERE itemname LIKE \"%$user_input%\" LIMIT $startrow, 10");
Reply With Quote
  #5 (permalink)  
Old 06-12-04, 10:58 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, now i get on my page - Could not run query.
Once again my code:

If anyone can find out why, could you possibly look at my code, and tell me what to fix so it will run proper. Thanks

<?php
$connect = @mysql_connect("localhost", "asdf", "asdf") or die("could not connect to server");

$db_select = @mysql_select_db("asdf") or die("could not select the database");

$SQL = ("SELECT * FROM itemsearch WHERE itemname LIKE \"%$user_input%\" LIMIT $startrow, 10");

$result = @mysql_query($SQL) or die("Could not run query");

//check if this is the first page
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
//we give the value of the first row to 0
$startrow = 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)$_GET['startrow'];
}


while($row = mysql_fetch_array($result))
{
echo("<tr>");
echo("<td class='cntbxleft'> &nbsp;");
$url = ("$row[url]");
echo("<a class='bluetu' href='$url'>$row[itemname]</a></td>");
echo("<td class='cntbxmid'>$row[str] &nbsp;</td>");
echo("<td class='cntbxmid'>$row[agi] &nbsp;</td>");
echo("<td class='cntbxmid'>$row[sta] &nbsp;</td>");
echo("<td class='cntbxmid'>$row[int] &nbsp;</td>");
echo("<td class='cntbxmid'>$row[wis] &nbsp;</td>");
echo("<td class='cntbxright'>$row[effect_one] &nbsp;");
echo("</tr>");
}

//now this is the link..
echo "<tr><td><a href='itemsearch.php?startrow='.($SQL+10).>Next</a></td></tr>";

?>
Reply With Quote
  #6 (permalink)  
Old 06-13-04, 03:24 AM
ArksI's Avatar
ArksI ArksI is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Bulgaria
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
try this one

$SQL = "SELECT * FROM itemsearch WHERE itemname LIKE \"%$user_input%\" LIMIT $startrow, 10";


ot try the simple thing:
if (!$dbres = mysql_query($SQL)) echo mysql_errno()."::".mysql_error();

this will return number of mistake and explanation if anything fales with the query ....
Reply With Quote
  #7 (permalink)  
Old 06-13-04, 04:47 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
you had some order problems, and in SQL queries always use single quotes to sorround the field values !

also, in the last link you used $SQL+10!! while you should use $startrow+10
there are other problems I fixed ,, try this one :
PHP Code:

<?php

$connect 
= @mysql_connect("localhost""asdf""asdf") or die("could not connect to server");

//check if this is the first page
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
//we give the value of the first row to 0
$startrow 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)$_GET['startrow'];
}

$db_select = @mysql_select_db("asdf") or die("could not select the database");

$SQL "SELECT * FROM itemsearch WHERE itemname LIKE '%$user_input%' LIMIT $startrow, 10";

$result = @mysql_query($SQL) or die("Could not run query");

while(
$row mysql_fetch_array($result))
{
echo(
"<tr>");
echo(
"<td class='cntbxleft'> &nbsp;");
$url = ("$row[url]");
echo(
"<a class='bluetu' href='$url'>$row[itemname]</a></td>");
echo(
"<td class='cntbxmid'>$row[str] &nbsp;</td>");
echo(
"<td class='cntbxmid'>$row[agi] &nbsp;</td>");
echo(
"<td class='cntbxmid'>$row[sta] &nbsp;</td>");
echo(
"<td class='cntbxmid'>$row[int] &nbsp;</td>");
echo(
"<td class='cntbxmid'>$row[wis] &nbsp;</td>");
echo(
"<td class='cntbxright'>$row[effect_one] &nbsp;");
echo(
"</tr>");
}

//now this is the link..
echo "<tr><td><a href='itemsearch.php?startrow=".$startrow+10."'>Next</a></td></tr>";

?>
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 06-13-04 at 04:50 AM.
Reply With Quote
  #8 (permalink)  
Old 06-13-04, 10:07 AM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, i did that and i have one last syntax error, i think. Right here:
echo "<tr><td class='cntbxleft'><a class='bluetu' href='itemsearch.php?startrow=\".$startrow+10.\"'> Next</a></td></tr>;

Notice i put \ to let the " be, but now i dont think its working... what exactly should i use around .$startrow+10.? ' ? Thanks
Reply With Quote
  #9 (permalink)  
Old 06-13-04, 10:11 AM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Ugh, im sorry for so many questions, but.. since this is for a search, like i search FACE, and all results display containing the word face, will this work with it? So i search FACE, click next, and 10 *more* results from my search (FACE) show up, and continue till there are no more. Thanks
Reply With Quote
  #10 (permalink)  
Old 06-13-04, 10:30 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Ok, i did that and i have one last syntax error, i think. Right here:
echo "<tr><td class='cntbxleft'><a class='bluetu' href='itemsearch.php?startrow=\".$startrow+10.\"'> Next</a></td></tr>;
why did you change the one I gave you? mine doesn't have errors !

Quote:
Ugh, im sorry for so many questions, but.. since this is for a search, like i search FACE, and all results display containing the word face, will this work with it? So i search FACE, click next, and 10 *more* results from my search (FACE) show up, and continue till there are no more. Thanks
this is another story!
you have to pass the term in the URL ,again !!
and pass it in the URL of "Next" !
PHP Code:

//now this is the link..

echo "<tr><td><a href='itemsearch.php?startrow=".$startrow+10."&term=$user_input'>Next</a></td></tr>"
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to disable browser's back button after logout shaky ASP 7 08-18-06 07:37 AM
POST without submit button AbelaJohnB PHP 5 01-22-04 07:56 AM
image submit button problems Pepe PHP 10 12-22-03 08:15 PM
Dynamic Button - Urgent kamlesh_nadar ASP.NET 1 11-08-03 12:26 AM
radio button selection TheLaughingBandit ASP 3 08-31-03 06:22 PM


All times are GMT -5. The time now is 05:02 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.