john010117 Posted April 22, 2007 Share Posted April 22, 2007 Let me first show you the part of the code I'm having trouble with. if ($_GET['type'] == "title") { if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 10; $from = (($page * $max_results) - $max_results); $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$word' LIMIT $from, $max_results"); if(mysql_affected_rows()>0) { while ($row = mysql_fetch_assoc($result)) { extract($row); print "<p><table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"> <tr><td><img src=\"$image\"></td><td valign=\"center\"><a href=\"archive.php?id=$id\">$title</a><br /><font size=\"1\">Posted on: $date</font></td></tr></table></p>"; } $total_results_q = mysql_query("SELECT * FROM bnetupdates"); $total_results = mysql_affected_rows($total_results_q); $total_pages = ceil($total_results / $max_results); echo "<center>Select a Page<br />"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$prev\"><<Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$next\">Next>></a>"; } } else{ print "<p>The search failed to find the title of the Bungie Weekly Update story. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates <a href=\"archive.php\">here</a>.</p>"; } } It shows the first page of results just fine (without the page variable in the URL). But whenever I go to another page of results, it shows "The search failed to find..." error message. Can anyone help please? Quote Link to comment Share on other sites More sharing options...
shaymol Posted April 22, 2007 Share Posted April 22, 2007 Hi john in your code you are using mysql_affected_rows() after each select query . but accoriding to php manual mysql_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE. mysql_affected_rows() does not work with SELECT statements; only on statements which modify records. To retrieve the number of rows returned by a SELECT, use mysql_num_rows() Thanks ShaymoL Quote Link to comment Share on other sites More sharing options...
john010117 Posted April 22, 2007 Author Share Posted April 22, 2007 Ok, I changed that to this: if ($_GET['type'] == "title") { if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 10; $from = (($page * $max_results) - $max_results); $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$word' LIMIT $from, $max_results"); if(mysql_num_rows($result)>0) { while ($row = mysql_fetch_assoc($result)) { extract($row); print "<p><table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"> <tr><td><img src=\"$image\"></td><td valign=\"center\"><a href=\"archive.php?id=$id\">$title</a><br /><font size=\"1\">Posted on: $date</font></td></tr></table></p>"; } $total_results_q = mysql_query("SELECT * FROM bnetupdates"); $total_results = mysql_num_rows($total_results_q); $total_pages = ceil($total_results / $max_results); echo "<center>Select a Page<br />"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$prev\"><<Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$next\">Next>></a>"; } } else{ print "<p>The search failed to find the title of the Bungie Weekly Update story. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates <a href=\"archive.php\">here</a>.</p>"; } } ...but it still doesn't work. First page (w/o ?page=1 in the URL) shows up fine, but the next page doesn't show up. Can you see any additional problems with the code? Quote Link to comment Share on other sites More sharing options...
shaymol Posted April 23, 2007 Share Posted April 23, 2007 Hi john please check the following code that you wrote $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$word' LIMIT $from, $max_results"); here in your where clause you are trying to show those records whose title = '$word' but $word is a Super Global Variable . So you have to use $_GET['word'] in stead of $word. $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$_GET['word']' LIMIT $from, $max_results"); I think it would be work for you Thanks ShaymoL Quote Link to comment Share on other sites More sharing options...
john010117 Posted April 23, 2007 Author Share Posted April 23, 2007 Ok, I've changed that also. But the second page still shows the "not found" message. <?php if ($_GET['type'] == "title") { if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 10; $from = (($page * $max_results) - $max_results); $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$_GET[word]' LIMIT $from, $max_results"); if(mysql_num_rows($result)>0) { while ($row = mysql_fetch_assoc($result)) { extract($row); print "<p><table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"> <tr><td><img src=\"$image\"></td><td valign=\"center\"><a href=\"archive.php?id=$id\">$title</a><br /><font size=\"1\">Posted on: $date</font></td></tr></table></p>"; } $total_results_q = mysql_query("SELECT * FROM bnetupdates"); $total_results = mysql_num_rows($total_results_q); $total_pages = ceil($total_results / $max_results); echo "<center>Select a Page<br />"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$prev\"><<Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$word&type=title&page=$next\">Next>></a>"; } } else{ print "<p>The search failed to find the title of the Bungie Weekly Update story. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates <a href=\"archive.php\">here</a>.</p>"; } } ?> Any suggestions? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 change $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$_GET[word]' LIMIT $from, $max_results"); to $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '{$_GET[word]}' LIMIT $from, $max_results"); Quote Link to comment Share on other sites More sharing options...
john010117 Posted April 23, 2007 Author Share Posted April 23, 2007 Ok, I've changed that part also. But the error still occurs. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 what error exactly ? also your missing a } at the end of the script Quote Link to comment Share on other sites More sharing options...
john010117 Posted April 23, 2007 Author Share Posted April 23, 2007 I don't believe I'm missing a } at the end of the script (just ran it through Notepad 2). I'm getting the error that I have coded in: "The search failed to find the title of the Bungie Weekly Update story. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates here". Quote Link to comment Share on other sites More sharing options...
sanfly Posted April 23, 2007 Share Posted April 23, 2007 I think the problem is that $word is not defined (unless youre using register_globals on which by all accounts is a bad thing) Try putting the search term in your error message, eg: <? print "<p>The search failed to find the title <b>$word</b> in the Bungie Weekly Update story archive. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates <a href=\"archive.php\">here</a>.</p>"; ?> Heres how I would do it anyway <?php if ($_GET['type'] == "title") { $theWord = $_GET['word']; if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 10; $from = (($page * $max_results) - $max_results); $result = mysql_query ("SELECT * FROM bnetupdates WHERE title = '$theWord' LIMIT $from, $max_results"); if(mysql_num_rows($result)>0) { while ($row = mysql_fetch_assoc($result)) { extract($row); print "<p><table border=\"0\" cellspacing=\"5\" cellpadding=\"0\"> <tr><td><img src=\"$image\"></td><td valign=\"center\"><a href=\"archive.php?id=$id\">$title</a><br /><font size=\"1\">Posted on: $date</font></td></tr></table></p>"; } $total_results_q = mysql_query("SELECT * FROM bnetupdates"); $total_results = mysql_num_rows($total_results_q); $total_pages = ceil($total_results / $max_results); echo "<center>Select a Page<br />"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$theWord&type=title&page=$prev\"><<Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$theWord&type=title&page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?word=$theWord&type=title&page=$next\">Next>></a>"; } } else{ print "<p>The search failed to find the title <b>$theWord</b> in the Bungie Weekly Update story archive. Please make sure that the title is EXACT and the spelling is correct. Please try again or see the list of all the updates <a href=\"archive.php\">here</a>.</p>"; } } ?> Quote Link to comment Share on other sites More sharing options...
john010117 Posted April 24, 2007 Author Share Posted April 24, 2007 I think I have found the problem. When I put "$word" in the echo part, my common search term shows up like this: Bungie Weekly What\\\'s Update So it has to do with the comma's being replaced with "\". How would I fix that? Quote Link to comment Share on other sites More sharing options...
sanfly Posted April 24, 2007 Share Posted April 24, 2007 stripslashes() you may need to do it every time you retrieve the variable from a $_POST Quote Link to comment Share on other sites More sharing options...
john010117 Posted April 24, 2007 Author Share Posted April 24, 2007 Ok, stripslashes() worked! Thank you everyone for helping. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.