Dville Posted August 15, 2006 Share Posted August 15, 2006 Here is my code[code]// counting the offset$offset = ($pageNum - 1) * $rowsPerPage;$keywords = explode(" ", $search);$query = "SELECT * FROM articles " ."WHERE body LIKE '%".$keywords['0']."%'";for ($i=1; $i<count($keywords); $i++) {$query = $query." AND body LIKE '%".$keywords[$i]."%'";}$query = $query." ORDER BY id DESC LIMIT $offset, $rowsPerPage";$result2 = mysql_query($query) or die(mysql_error());?><form method="GET" action="search.php"><b>Search:</b> <input type="text" name="search" size="20" /><input type="submit" value="Search!" /></form><br><br><table width="50%" style="border:1px solid #000000;"><?php$keywords = explode(" ", $search);$query = "SELECT COUNT(id) AS numrows FROM articles " ."WHERE body LIKE '%".$keywords['0']."%'";for ($i=1; $i<count($keywords); $i++) {$query = $query." AND body LIKE '%".$keywords[$i]."%'";}$result = mysql_query($query) or die('Error, query failed');$row = mysql_fetch_array($result, MYSQL_ASSOC);$numrows = $row['numrows'];// how many pages we have when using paging?$maxPage = ceil($numrows/$rowsPerPage);[/code]But I would also like to search both 'body' and 'title'. Due to syntax issues, and not knowing which exact line to edit, I have failed at trying to get it to search both rows.Thanks in advanced to anyone who can help me with this. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 15, 2006 Share Posted August 15, 2006 Post the final value of the $query variable. Quote Link to comment Share on other sites More sharing options...
Dville Posted August 15, 2006 Author Share Posted August 15, 2006 Not sure what you're asking for, but here is all of my search.php pagehttp://phpfi.com/141089 Quote Link to comment Share on other sites More sharing options...
fenway Posted August 15, 2006 Share Posted August 15, 2006 I don't want your search page... I want you to echo the value of the query variable. Quote Link to comment Share on other sites More sharing options...
Dville Posted August 15, 2006 Author Share Posted August 15, 2006 says[code]SELECT COUNT(id) AS numrows FROM articles WHERE body LIKE '%ubuntu%'[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted August 16, 2006 Share Posted August 16, 2006 Well, then for some reason, your keywords array is empty, becuase you're never concatenating the other fields. Quote Link to comment Share on other sites More sharing options...
Dville Posted August 17, 2006 Author Share Posted August 17, 2006 [code]SELECT * FROM articles WHERE body LIKE '%ubuntu%'[/code]There is another query being ran. But in the code it's chopped up in an odd way i dont understand[code]$query = "SELECT * FROM articles " ."WHERE body LIKE '%".$keywords['0']."%'";[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted August 17, 2006 Share Posted August 17, 2006 Well, yes, there are two queries, but again, it'll make more sense if you see the final SQL query, not it's PHP equivalent. Quote Link to comment Share on other sites More sharing options...
Dville Posted August 17, 2006 Author Share Posted August 17, 2006 the first pasted code is an echo of the bottom query Quote Link to comment Share on other sites More sharing options...
fenway Posted August 18, 2006 Share Posted August 18, 2006 Then your keywords array is empty. Quote Link to comment Share on other sites More sharing options...
Dville Posted August 18, 2006 Author Share Posted August 18, 2006 I dunno what that means. wouldnt the keyword be 'ubuntu', which i see is in there Quote Link to comment Share on other sites More sharing options...
fenway Posted August 19, 2006 Share Posted August 19, 2006 Then I'm totally confused as to what you're having trouble with. Quote Link to comment Share on other sites More sharing options...
Dville Posted August 19, 2006 Author Share Posted August 19, 2006 right now it only searches for the 'body' row, i'd like it to search the body and title row, and return the article if either shows a match. i've tried adding it, but due to the php format, and it being chopped up like that, i can't get the syntax correct Quote Link to comment Share on other sites More sharing options...
fenway Posted August 19, 2006 Share Posted August 19, 2006 Right -- all I'm saying is that the following code is never being executed.[code]for ($i=1; $i<count($keywords); $i++) {$query = $query." AND body LIKE '%".$keywords[$i]."%'";}[/code] 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.