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.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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:
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:
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?
Exploding Results Of Mysql Query
I have a table with times and dates listed like this: 0000-00-00 00:00:00 2003-09-20 20:26:22 etc etc What I want is to query the DB for the field (matchdate) and then get it to explode the ' ' to give jsut the date for me and then put it into a dropdown in a loop. this may sound easy but i too sleepy to work it out and searching aint good.
MySQL Query Not Returning All Results
I have a user table in the DB, for example: +---------+----------------+-------------------+ | uid | username | firstname | |----------+----------------+------------------+ | 1 | cobby | Andrew | | 2 | admini | test-account | +---------+-----------------+------------------+ If, in phpMyAdmin, I query: SELECT `username` FROM `users`; It will return results correctly (cobby and admini, respectively). But if I make a simple PHP script, such as: <?php mysql_connect('localhost', 'cobby', 'dbpass'); mysql_select_db('testdb'); $query = mysql_query('SELECT `username` FROM `users`'); print_r(mysql_fetch_assoc($query)); ?> It only returns: Array ( [username] => admini ) Why does it only return the second result? I have a feeling I'm doing something really silly, but I looked over this test script and its got me stumped.
Using Arrays With Mysql Query Results
im currently in the process of making a piece of code that will firstly take all the data from a table in mysql and then assign it to an array. This data will consist of several different rows of data each with different infomation for each field in the table. i want to be able to use an array in a loop so that depending on which number of the loop is on will change the infomation that is assigned to a certain array. Code:
Mysql Doesnt Return All Results Of A Query
I have an sql query like this: SELECT column FROM table WHERE column1="3" AND column2="1" This query works perfectly if i run it in the command line, to be exactly it return two results. But if i run it from php i just get the first of the two results. Any ideas? Mysql 4.1.8 php 5.0.3 I have a second problem. But its more of a question. if i run the foreach loop on an array like this array("id" => "78"), then it splits 78 up in 7 and 8. Now you say its stupid to use a foreach for this array. But in the function there i use it the array could also be two dimensional. Is this behavior normal? I looked in the php manual but found nothing.
Show Mysql Query Results On Pages
Does anyone have a script that will show mysql query results as paged results? This is what I have at the moment and it does not pass the results to the second page. Code:
Mysql Search Query
Is there a way to search for a word in any of the fields of a row using simple sql for my sql? I have a rather complex search function on my site and right now, I dump all the text of all fields (that are text fields) in a special field. The search function then searches this "keyword" field. Is there a smarter way of doing this. To recoup I have an mysql database with about 500 records, each containing over 20 text fields (address, name, etc.... etc....). I want the user to be able to search for a particular word (e.g. fishing or rock climbing) in all records and all fields and I would like Mysql to return the IDs of the fields that match. Along the lines of SELECT ID FROM TABLE WHERE * LIKE "%test%";
Results Of Same Field Names But Different Tables In MySQL Query.
I have a SQL string with a couple of JOINs that works perfectly in command prompt. I get results for all the fields selected just fine. But when I put it into a PHP page, I can't make variables(?) out of fields that have the same field name from different tables. Here's the SQL statement: $sql = "SELECT orders.companyid,orders.ordernum,orders.address,tb l_ih_accounts.company,tbl_ih_accounts.address FROM orderstatus ". "LEFT JOIN orders ON (orderstatus.ordernum = orders.ordernum) ". "LEFT JOIN tbl_ih_accounts ON (tbl_ih_accounts.id = ihid) ". "WHERE submitted <> 'yes' ORDER BY orders.ordernum ASC"; Then in the "WHILE" clause after the database is queried: $o_address = $row[orders.address]; $ih_address = $row[tbl_ih_accounts.address]; I've tried it without the table names in the $row statements, but then I'll just get the results for tbl_ih_accounts.address. I'm thinking there must be some way to uniquely "name" the results of a particular field up in the SQL statement, and then just use that unique name in the WHILE. But I have no clue, and can't find anything about anything like that.
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?
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); ?>
MySQL Caching / PHP Input Suggestion
I'm making a Search Suggestor that every time someone searches something, it adds it to a database. If its already in there, it increments the value by 1. I'm building it in Flash using AMFPHP to connect to the database so its normal PHP Queries and results etc.. How should I go about handling the database queries if there were say 5,000+ people using it at once? I'm going to have it query per second rather than per keystroke (only if the input has changed from one second to the next so its not querying the same thing over and over).
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 Ɔ', `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 Ɔ', `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:
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:
Getting Too Many Results From A Query!
This is very peculiar -- for some reason, I'm getting 6-8 results from each of these queries, although only one listing matches. I have a pair of forms on one page: <FORM> Search for lastname: ____________ [Submit] </FORM> <FORM> Search for email: ________________ [Submit] </FORM> This goes to a searchresults.php page: if ($searchname !== "") { $query="SELECT artistID,firstname,lastname,email,city,state,count ry from artists WHERE lastname='$searchname'"; $result=mysql_query($query) or die(mysql_error("Could not execute query.")); while($row = mysql_fetch_array($result)) { $alt_artistID = $row['artistID']; $alt_firstname = $row['firstname']; $alt_lastname= $row['lastname']; $alt_email = $row['email']; $alt_city = $row['city']; $alt_state = $row['state']; $alt_country = $row['country']; echo "<CENTER><HR>".$alt_artistID."<BR>" .$alt_firstname." ".$alt_lastname."</A><BR>" .$alt_email."<BR>" .$alt_city.", ".$alt_state." ".$alt_country."<BR> <A HREF=delete.php?aritstID=".$alt_artistID.">DELETE THIS LISTING?</A><BR></CENTER>"; } } The second section is identical except for: if ($searchemail !== "") { $query="SELECT artistID,firstname,lastname,email,city,state,count ry from artists WHERE email='$searchemail'"; etc... } I don't understand why I would get 6-8 records when you can look at them and see that all but one clearly do not match...?
Using Query Results
Can you use a queries results only once? In this script I'm looping through a query and saving some values in an array. A little further through the script I need to use the same query for output. When I loop through nothing is echo'd to the browser. When I output a row count it shows that the correct number of records, so they must still be there.
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:
|