
06-12-04, 05:23 PM
|
|
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.
|

06-12-04, 06:17 PM
|
 |
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]
|

06-12-04, 07:19 PM
|
|
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'> ");
$url = ("$row[url]");
echo("<a class='bluetu' href='$url'>$row[itemname]</a></td>");
echo("<td class='cntbxmid'>$row[str] </td>");
echo("<td class='cntbxmid'>$row[agi] </td>");
echo("<td class='cntbxmid'>$row[sta] </td>");
echo("<td class='cntbxmid'>$row[int] </td>");
echo("<td class='cntbxmid'>$row[wis] </td>");
echo("<td class='cntbxright'>$row[effect_one] ");
echo("</tr>");
}
//now this is the link..
echo "<tr><td><a href="itemsearch.php?startrow='.($SQL+10).'">Next</a></td></tr>";
?>
|

06-12-04, 07:48 PM
|
 |
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");
|

06-12-04, 10:58 PM
|
|
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'> ");
$url = ("$row[url]");
echo("<a class='bluetu' href='$url'>$row[itemname]</a></td>");
echo("<td class='cntbxmid'>$row[str] </td>");
echo("<td class='cntbxmid'>$row[agi] </td>");
echo("<td class='cntbxmid'>$row[sta] </td>");
echo("<td class='cntbxmid'>$row[int] </td>");
echo("<td class='cntbxmid'>$row[wis] </td>");
echo("<td class='cntbxright'>$row[effect_one] ");
echo("</tr>");
}
//now this is the link..
echo "<tr><td><a href='itemsearch.php?startrow='.($SQL+10).>Next</a></td></tr>";
?>
|

06-13-04, 03:24 AM
|
 |
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 ....
|

06-13-04, 04:47 AM
|
 |
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 :
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Last edited by NeverMind; 06-13-04 at 04:50 AM.
|

06-13-04, 10:07 AM
|
|
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
|

06-13-04, 10:11 AM
|
|
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
|

06-13-04, 10:30 AM
|
 |
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" !
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|