Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Search Results ($num_rows) Does Not Match $search Results (PHP,MySQL)?


For example, when I do a database search for a term I get 2 results but the $num_rows says there are 3 results.

I suspect it's because there are similar keywords within different search fields of the SQL statement. But I am stumped as to how I can change this. Any Suggestions? the code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Search Brings Back Different Results Or Sometimes No Results
The problem Iv got is that when searching the site - it brings back different results or sometimes no results. For example: "i026", "i 026" and "026" do not bring back results for "I-026" which is the correct model number. Any ideas on how to make it search more variations or of a "Did you mean... I-026" script?

Caching MySQL Search Query & Results
I'm developing a site that may eventually have a very large database of
users (hopefully, but who knows). It will be a community website where
users can search each other (think Friendster, Classmates, every dating site
out there, etc.).

Often there will be queries with multiple joins and sometimes may include a
few fulltext searches. Each page of results will have a limited number of
results displayed (obviously). As I understand it, MySQL caches only exact
queries, so doing a LIMIT (x,y) on each query to get results for the
specific page will cause MySQL to run the entire query again, instead of
pulling from the cache. I will limit the results to 1000, but what's the
best way to limit results per page?

I was thinking that I could run the SELECT and LIMIT to 1000, then do a
mysql_data_seek to jump to the starting row for the page and fetch a certain
number of rows for the page. For each page, the exact same SELECT would be
used and therefore the results would be cached.

Also, how should I save the search query? The users will be searching with
any number of search terms, way too many to do use GET variables. I don't
want to create a hidden form with each search term as hidden inputs (for
one, that's kind of lame). I was thinking of saving the search query to the
database, I guess I could implode the POST array into a string and then save
it in the db.

How To Pass Mysql Search Results From One Page To Another
I am creating a website that uses PHP to query a MySql database. upon supplying the PHP script with a given search string and search term, a list of scientific documents with attributes such as author, date, url and revision are returned. Each document also has a unique id number within the database. What I would like to do is create a system whereby user of the site can leave reviews for each particular document, much like the product review system employed at jungle.com. I have got to the stage where the php script outputs a list of results each separated by a horizontal rule and what i would like is to be able to place a button on each record marked submit review, which would then take the user to a form where he or she could leave a review which would placed into a reviews table in the database.

However my problem is that i do not understand how to pass the paper id automatically to the form such that the user does not have the inconvenience of having to type into the form. Does anyone have any ideas on how I could solve this problem?

Highlighting Of A Search Term In Search Results
I am writing this simple MySQL and PHP search and what I want to do is to highlight the search term in the results when they are displayed on the screen.  I am able to get it to work. but the seach term will only be highlighted(Make it Bold) only if it matches exactly to what was typed in the search box. 

Is there a way where the search term doesn't have to exactly match in order for it to be highlighted?  Below is the code where I change the the search term into bold to be displayed on the screen.

<?php
$result_manufact = str_replace($splitstr, "<span style="color: red; font-weight: bold;">$splitstr</span>", $manufact);
?>

Is This Possible With Search Results
Is it possible that when someone does a search on your database, that the results are downloaded as a text file?

Is Anyone Else Able To See My Search Results?
Here is the thing. When you go to this page:

http://www.accumulist.com/index.php...llFields%5D=api

I've put in some HR tags in the HTML to separate the 3 different
queries. After those 3 queries you'll see results at the bottom. For
me, those results look like this:

api (4), darren (1), xml (12), battlepanda (1), war+on+drugs (6),
stupid (1), moron (1), nightmare (1), hell (1), mijkuynbvfsds (1),
police (1), Pitchfork+Media (1),

There are two problems here. Do you get this when you go to this page?
I'm concerned that I'm only getting back the things that I have
personally searched for, and not the things that others have searched
for. Let me know, please, if this works for you.

The goal of this script is to be able to say to the person who is
searching "People who searched for this item, also searched for these
other things."

It is suppose to be a little like on Amazon.com, where when you buy one
thing, it says "Customers who bought this item also bought these other
items:".

I'm sorry I didn't give the table structures earlier. The visitor id of
searchHistory is the id of visitors. machineId is a unique value
generated and set by a cookie.

#
# Table structure for table `searchHistory`
#

CREATE TABLE `searchHistory` (
`id` int(11) NOT NULL auto_increment,
`query` text NOT NULL,
`visitorId` int(11) NOT NULL default &#390;',
`domain` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=88 ;

#
# Table structure for table `visitors`
#

CREATE TABLE `visitors` (
`id` int(11) NOT NULL auto_increment,
`date` int(11) NOT NULL default &#390;',
`ipAddress` varchar(15) NOT NULL default '',
`hostname` varchar(255) NOT NULL default '',
`machineId` varchar(255) NOT NULL default '',
`referrals` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=8236 ;

Search Results
whenever i do a $result-$row query and try to list the results with a while statement, it always cuts off the first result. how do i fix this?

Links From Search Results
Hi i was wondering if anybody could tell me how to make url links to an item in my site from a list of search results. Here is a piece of my code:

<?php
$Name = $HTTP_POST_VARS["query2"];
$Eventtype = $HTTP_POST_VARS["query2"];
$EventStart = $HTTP_POST_VARS["query2"];
$EventEnd = $HTTP_POST_VARS["query2"];
$VenueName = $HTTP_POST_VARS["query2"];
if($Name or $Eventtype or $EventStart or $EventEnd or $VenueName)
{

$conn=@mysql_connect("mysql", "u0rr")
or die("Sorry can't connect to database");

$rs = @mysql_select_db("u0rr", $conn)
or die("Sorry can't connect to database");

$sql="select * from event left join venue on
(event.VenueID = venue.VenueID)
where (Name like '%$Name%'
or VenueName like '%$VenueName%')
AND Eventtype = 'Comedy' ";
$result=mysql_query($sql,$conn);

while( $row = mysql_fetch_array($result) )
{
echo("<b>"." Event Name: "."</b>".$row["Name"]."<br>");
echo("<b>"." Event Type: "."</b>".$row["Eventtype"]."<br>");
echo("<b>"." Venue Name: "."</b>".$row["VenueName"]."<br>");
echo("<b>"." Event Start: "."</b>".$row["EventStart"]."<br>");
echo("<b>"." Event End: "."</b>".$row["EventEnd"]."<br>");
echo("<b>"." Availability: "."</b>".$row["Availability"]."<br>");
echo("<b>"." Description: "."</b>".$row["Description"]."<br><hr>");
}
}
?>
For example if i enter an event type as 'comedy', a list of search results will come up from the form input displaying comedy events. Now from these results i would like to be able to click on Venue Name and this would link to that page in another part of my site.

I hope this explanation is o.k, if not post a thread & i'll try and explain a bit better. Thanks for any help

How Do I Underline My Search Results?
This is a PHP/MySQL question.

I have a search engine that finds matches of a word in artist names, and their album titles. How do I underline the word that is matched when I display the results? I've seen this on Yahoo! and was wondering how to do it.

Multiple Search Results
I have a php script which searches a mysql database and returns and lists the results 25 records per page. I am using the offset to do this. It works well. But I am outputing the search results 1 record per line, 25 records per page, with links to the previous and next pages, etc.

What I really want is to list the results in a 5 X 5 table. ie the first 5 records on table row 1, the next 5 on table row 2, etc.

Obviously for the last page there may not be 25 records, but anything from 1 to 25.

How can I automatically output html to produce the table and populate each cell with a record from the search result?

Links From Search Results
i was wondering if anybody can tell me how to make a url link to another part of my site from a completed search result. here is a section of my code i would like to link from.

echo("<b>"." Name: "."</b>".$row["Name"]."<br>");

Printing Search Results
How would I go about printing a list of search results? I have my query down fine:

<?php
$query = "SELECT data1, data2 FROM table WHERE name = '%$var%' ";
$result = mysql_query($query);
?>

I need to know what to do after this so that all results are printed in a table that includes 'data1' and 'data2'. I'd imagine this is done using 'while()' loops but I've never worked with one before and especially not in this context.

Search Results Substring
I have been searching for some clues as to how to show a substring from a
database search.

$pagetitle = "Page Title";
$pagetext = "This is <b>a typical</b> string that would be stored<br>in the
database.";

Search for "that" results would look like

1. Page Title
...string that would...
2. Another page
...computers that can...
3. Further Page
...languages that are...

At the moment the search results just show the page title. The idea is that
in the set of results I can show the user the context of each result, a bit
like a search engine does. Ideall I would like up to 10 words either side
of the search keyword.

Counting Search Results
I would like to know if anyone can show me how to count search results in a MySQL database for a keyword ($keyword).

Posting Search Results
i am a bit stuck on this part of coding, when people search ALL categories i leave the option value as: <option value="0"> so if 0 is passed to the GET all categories should be searched instead of just category 1,2 or 3 etc Code:

Search Results Pagination
I have problem with results pagination. When search is applied browser is showing me first 10 results, and links to other pages, but there is a problem with these links (passing variables i think). When i press on one of the links browser is showing me info that search input must be longer then 2 char. (so it clear that search input has not been passed thru the link. Code:

Limiting Search Results
I have written a search script for my database but now I want to limit the results to ten a page and then make it possible to see the next (or previous) page. All my attempts so far have failed. Code:

Going Back To Search Results
I'm trying to work out how to go back to the search results page from an individual product page. I've tried to use the following code:

if (isset($HTTP_REFERER)) {
echo "<a href='$HTTP_REFERER' class='text'>Back to search results</a>";
} else {
echo "<a href='javascript:history.back()' class='text'>Back to search results</a>";
}
but the problem is that it just sends the user back to the last page, so isn't reliable enough.

I have a product page which contains one or more images, each image requires the page to re-load, so I want to re-direct the user to the search page from any of these iterations.

Could someone suggest how to do this? Is there a way of writing search variables into a session identifier that I can easily reference?

I know of several ways to do it using if statements and writing lots more sessions but I'm sure there's a cleaner way...

Search Results And Pagination
i'm having a wee bit of trouble with my search results and pagination i'm using the same pagination script i usually do with most pages, but this is proving to be a bit more difficult Code:

Database Search Results
i have a paid to read website,im hosting it off my own pc..as a member you can search offers and complete them, heres where i need some help..when a member clicks submit and the offer goes to an offerdone table i need the offer to hide from them so they cant do it again,also that same offer needs to hide in the search results as well...is there somthing like onclick hide and for the results something like if duplicate hide from search or if offer found in this table hide from results...

there are 2 tables one will all my offers the other with offer they have done,also this needs to apply for each member account.i am new to all this and have made it this far to have my site up and going but im looking for those extra catchs i could really use,so that a member cant repeat an offer they have already done,

Splitting Search Results
I have a search page and try to split the result, as it is nicer to see, insted of 100 result to get it by 25 each.

The code is doing everything it have to do, but every time i go to the next page, it starts indexing them again from 1 insted of 26,27,etcetera...

I am a little tired of looking and at this moment i don't see the problem. Any suggestions. Code:

Search Results Of Directory Parse
I am using the following directory parser to list the files out of the main public html directory:

Highlighting Search Term Results
I've seen previous threads but I still need help in highlighting
search terms like google does on their search result page.

I know I need, ob_start();
Then I process to highlight the search term hits, then I flush the
buffer to render the page.

I'm comfortable with PHP coding but what I need is simple step by step
help, with a simple search form example. The explanations I see are either way to lofty or too small a piece of the "puzzle".

Exporting Search Results To A CSV File
I am about to start programming up a database, where the client requies the data exported to a CSV file for use in mail merge documents etc.

What I would like to know is, if they run a query on the database, and only export five of the 10 fields in the table to the list, how would I go about reatining the field names on the first line of the CSV file?

Search Form And Results Page
I have a table called "lista" into my mysql database.This table has 5 text columns : "TRANSLATEDTITLE" "ORIGINALTITLE" "ACTORS" "DIRECTOR" "YEAR" , and 1 image column called "COVER".

I want to create a page with a form to search entries into this table (ex. with Title, Actors, Director, Year), and anotger php page with the search results shown inside, everyone with a link that opens a pop window (ex. 400X320). Code:

Search & Display PEAR DB Results
I'm only a novice in PHP & PEAR DB, and currently stuck in an attempt to create a "search & display query PEAR DB results" page. Here's my pseudocode:

1) Display page with a searchbox and a search button.

2) Upon hitting the search button, run sql query ... Select all fields from TableA and selected fields from TableB where field1 like "searchbox" order by field1

3) If searchbox is blank
-> prompt user to enter search value
Elseif search result NOT found
-> alert user >> Record NOT found
Else
-> display results in a table (with alternating colours for each row)

4) Able to paginate the results in something like display 10, 20, 30, etc records on the same page .... the amount of records to be displayed can be manually selected by the user (via a dropdown box) ... with Previous Page, Next Page links as well.

>> How would I do that entirely in code from scratch? I've found other tutorials on doing it but it is tailored for MySQL ... but I'm using PEAR DB... the syntax is different.

>> Since I am querying two tables based on the same search value, how am i able to concatenate both the tables search results and display it inline in the display results page?

Error In Syntax For Search Results
echo "<p><strong>".($i+1).". Login: ";

I get the following error returned when doing a syntax check

PHP Parse error: parse error, unexpected '>' in c:wayne
esults.php on
line 37

I am using the SAMS PHP and Mysql Web Development book's example on
page 231

Display Search Results In Pages
im doing a query on a table that searches articles from the database, and i was wondering how i could display the results as groups of ten, so the next ten search matches are displayed when the user presses a page number.

How Do I Search Two-dimiensional Results Set Array
Here's the pertinent code to get the SQL results. It is generated by
dreamweaver adn I'm trying to learn to code php so I don't depend on DW to
do it for me.

$query_rsSummary = "SELECT sid, Count(wid) FROM plotting GROUP BY sid";
$rsSummary = mysql_query($query_rsSummary, $tableG) or die(mysql_error());
$row_rsSummary = mysql_fetch_assoc($rsSummary);


How do I search the array to see if a certain "sid" has an entry in the
array?

Return Search Results On Same Page
I'm struggling with this much longer than I think I need to,

How do I make the results of a search display on the same page as the
search, sort of beneath the 'submit' button? Thanks for helping out.


Inserting Search Results Into Rows
inquired on another forum about showing search results from mysql in rows, for example: the first 4 results on one row, the next four on the one after etc. etc. to a maximum of 16 before the user has to move on to the "next page to display any remaining results. i was given this code:

Page Navigation From Search Results
I have created a search form that searchs for results from my database matching the criteria to what ever the user inputs. I have done this using 2 php pages the first page points to the second, where the data is sanitised and cleaned accordingly. The results are displayed on the 2nd page. Code:

Limit Search Results To 75 Characters?
I am working on a small search engine to put into my site to search the text on my pages. Right now all my page's text are being held in my database and displayed on my actual pages using php.

Anyways, I have so far limited my search results to the first 75 characters, then given the user a link to the page that the keyword they searched for resides on. The problem is that some of the keyowrds occur after the 75th character. Is there a way to display 75 characters with the keyword being in the middle of those 75 characters? Code:

Search Form To Results To Details
I have created a Search form in html that is processed by a php script via the POST method. All this works pretty well and lists results from my DB. Now i want to be able to click on 1 particular result to bring up a details page. I would like to create this via php so I don't have to create heaps of pages but just a template that uploads data from the DB.

Is this possible, and if so, where do i go from here???

Displaying Search Results In Pages
I am implementing search functionality in a website. ( internal search).
In that I am taking a keyword as input and searching all the pages and storing
results in an array. I want to display 10 results per page. I wrote below logic for that. Code:

Cache Post Method With Php (search Results)
when you're searching and you click away from the resulting hits page and want to come back, you might get this messae:
data has expired from post method .. blah-blah ..

could be annoying, because if the pages use sessions the soulution that U'd think of doesn't seem to work, but instead U got2 use this line:

session_cache_limiter('private, must-revalidate');

(cuortesy (borrowed it from) of php.net, users contributed section at headers) that person sais the "must revalidate" part is crucial .

Advanced Search - Listing Multiple Results
I created a seach function to search a database and retrieve the information based on the input. However only the first matching result is shown.

The code is working fine but i want to show every matching result, one after another. Therefore, for example, if the user types into "country" the word "USA" every event will be shown. I have included the code i have used so far. Code:

Similar Search Results - FULLTEXT Or Algorithm
first of all I'm sure that what I want to do isn't going to be easy...

I'd like to be able to take user input and query the database to return
exact and similar results. I have added a FULLTEXT index of the column I
want to search to the table. Then taking user input and break it apart into
separate words and use something like:

MATCH (table) AGAINST ('*word1*' '*word2*' IN BOOLEAN MODE) AS Score

in my SELECT and then ORDER BY Score DESC and that works pretty good, but
I'd like to factor in misspellings, abbreviations, etc. I have searched to
see if I could find code for an existing algorithm that I could try, but all
I have found are articles talking about different algorithms and no actual
code.

Search Results Showing An Include Page
I have a page index.php which includes different templates based on a passed URL variable through the include() function. My problem is that I have the files saved as temp.inc.php files. Search engines are returning the include page as a result and then the user is directed to a new window with just the include page displayed. Any ideas on how to get around this?

Highlight Search Terms In Results Pages
I am trying to find a script or code that will highlight search terms output from my MySql db. I have posted a portion of my pagination page below. The pagination script provides ten records at a time.

For example, I need code, a script, or a funtion to grab the search term coming from the user and generate highlighted keywords when the keywords are entered by the user in the html forms search box.

In the code below, I have inserted sample code so you can see how the display appears. In actual practice, the $Source, $Topic, $Subtopic, and $References values come from the while(list($Source, $Topic,$Subtopic,$References)= mysql_fetch_row($result2)) { code line. Code:

Displaying Select Information From XML Search Results
I am new to both php and xml. I have a school assignment to update an existing php-based website where I have to display search results from an online library. I can use a url search which returns an XML file that includes tags such as position, title, url, description, date, etc.

I only want to display the title, url (preferably the title should be a link to the url), and description for all of the results on my website's search results (different template as well).

What classes/functions are available to help me do this? I would appreciate any guidance as well as links to online tutorials etc. that would point me in the right direction. I have read about the general aspects of php, and I have experience with Java and C; but I don't know about xml at all.

By the way, the website is running on the school server and has php version 4. I don't think I'll be able to install php 5 but I can probably upload some helper files or something.

Multi Word Search Yeilds Some Duplicate Results
i wrote a search function and it works pretty well except it does one odd thing. if i enter "big mac" into the search form and the words "big" and "mac" appear in the same article.... i will get TWO cases of that article returned to me in my results.

Now if i enter "big mac" and i find onlt ONE word or the other in an article it will be returned ONCE. also if i find multiple instances of ONE of the words in a single article i will only return it ONCE so the top case is the problem and the next two are just for clarification purposes. obviously i want only once instance to be returned in any case. PHP Code:

Download Database Search Results As Text File?
Can someone please tell me how to query a database and then download results as a text file.

Making The Results Of A Search Engine Show As A Link
I made a simple PHP search engine for my web site. the problem I'm having is that the results show as regular text rather then a link to the page found. I need to know how you use A HREF with a variable. below is the section of my code that I figure I need to modify.

$row = mysql_fetch_array($result);
echo ($i+1).'<strong> URL: '
echo stripslashes($row['url']).'</strong>'
echo '<br />'

PHP Urls With Variable Data In Search Engine Results
I've been given conflicting answers about search engines picking up
urls like: http://mysite.com/index.php?var1=1&var2=2&var3=3
Do search engines pick up these urls?
I've been considering converting a site of mine to PHP-Nuke, but if
the individual modules aren't picked up in search engines I'm not
going to do it.

Sort Search Results - Query Made From Form Variables
I have created a search engine with multiple search fields, the results.php page shows the results.
My question is, how can I allow the user to sort the results (name, description, price etc), simply by clicking on the column title. This wouldn't be a problem if the SELECT query was constant - just add a $var at the end where ORDER BY should be, but how can I do this when the SELECT statement is made up of $_POST VARS? Surely if I reload the page with the sort command, it will have forgotten the $_POST vars that made up the query?
I have searched EVERYWHERE for help on this PHP Code:

Counting Preg Match Results
i was wondering if there was a way to count how many preg match results you get back
my code is: $matchesfound = preg_match('/subject="/', $nsubject, $matchfound);

Search Database - MATCH() AGAINST() Or LIKE
I have a fairly basic database that holds articles that visitors of my web site can search based on content of the articles and the author. Simplified the tables look like this...

articles
+-----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| doc_id | varchar(8) | | PRI | | |
| title | varchar(255) | YES | MUL | NULL | |
| date | date | YES | | NULL | |
| source | text | YES | | NULL | |
| abstract | text | YES | MUL | NULL | |
| body | mediumtext | YES | | NULL | |
+-----------------+--------------+------+-----+---------+-------+

authors
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| author_id | int(11) | | PRI | NULL | auto_increment |
| doc_id | varchar(8) | YES | | NULL | |
| author | varchar(100) | YES | MUL | NULL | |
+---------------+--------------+------+-----+---------+----------------+

The Authors name is kept in the form of first initial, middle initial (if known) and last name (ie J. Bloggs).

Basically users have two fields they can complete for searching. One is the keywords (ie words in the body of the article) and the other is for the author of the article. Currently I perform a full text search to find authors that match the author they enter but I'm not sure this is the best method as authors with short last names (ie. Li or Cho) can't be found.

This is the code I am using to generate a query to search the database. PHP Code:

Search Authors Without Using MATCH AGAINST
I have a website that holds journal articles. Details for each articles are kept in a database. People can search for articles based on the contents of the articles or the author. Author names are kept in the form of "J. R. Bloggs".

Currently when a user searches by author I use the MySQL feature MATCH AGAINST. The problem with this is that fulltext indexes only indexes words that have 4 or more characters and a lot of authors in my database have surnames like Li, Wui, Lui, Lea and so on.

I'm looking for an alternative that will improve the results of the search. Using the MySQL LIKE feature isn't a very good alternative as it returns anything that contains the string of 2 or 3 characters. Does anyone know any clever tricks to get more useful results?

I was thinking I might be able to return a MySQL LIKE query results into an array then use the php function similar_text() to calculate the percentage similar each of the authors are then return only the authors that are 80% similar. I haven't tried this yet as I wanted to see what others might say plus with a few thousand articles in the database this may be extremely slow?


Copyright © 2005-08 www.BigResource.com, All rights reserved