Best Way To Combine Results From 2 MySQL Searches, Into One Sorted List?
I have to search 2 mySQL tables, and show the user a single sorted list
that contains all the results from both mySQL queries.
My question is, how do you get all the resulting items from both
databases into one single, sorted list, to present to the user?
I guess one way would be, to use PHP to copy all the results from each
database, into a PHP array, and then sort it. Is that how this kind of
thing is usually done?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Previous And Next Records In Sorted Results
I have an address book db with a php front-end and want to have "previous" and "next" buttons available when viewing an address. When "next" is clicked I'd like it to go to the next record alphabetically. PHP Code:
If/then Within MySQL Results List
I want to list job opportunities for a facility. If there are jobs in the database, I can list them without a problem. But if there are no jobs, I'd like to echo a line something like: "No jobs right now, come back later." But I can't get that line to echo. PHP Code:
Sort A List Of COUNTED Results?
I have a database holding a list of customer`s orders, i thought it would be neat to show the top 5 selling products on our website. Now i have a recordset that counts each product sold which COUNTS by model_ID and GROUPS BY model_ID But heres the problem i wish to show the highest COUNT descending?? So the highest COUNT is at the top and show five records giving me the Top 5 Selling models? At the moment it lists them in model order as you would expect.. here is the rough Recordset:- SELECT *, COUNT(mode_ID) FROM order_item,products WHERE products.prod_ID=order_item.mode_ID GROUP BY mode_ID
Remembering How The User Sorted.
I'd like to be able to let a user sort a table of date by example "Last Name" and when the user goes back the page it'll remember to sort by "Last name".
Sort Order Of A Sorted Array
With the PHP command 'sort' I can sort an array. However, it doesn't exactly sort the array I'd like to: <html> <body> <?php $my_array[0] = array("AA", "11"); $my_array[1] = array("AA", "22"); $my_array[2] = array("aa", "22"); $my_array[3] = array("AB", "11"); $my_array[4] = array("ab", "11"); $my_array[5] = array("ab", "22"); $my_array[6] = array("äb", "11"); $my_array[7] = array("ab", "33"); $my_array[8] = array("bb", "11"); $my_array[9] = array("eb", "11"); $my_array[10] = array("éb", "11"); $my_array[11] = array("fa", "11"); sort($my_array); for ($i = 0; $i <= 11; $i++) { echo $my_array[$i][0] . " / " . $my_array[$i][1] . "<br>"; } ?> </body> </html>
Php And Searches?
I was looking at URL , and I was trying to create a search similar to what they did on their news search, althought I am not able to use mysql on my webserver(so I am told but can use php). Any info on how they did this or what steps to take to head in the right direction is more than appreciated. The source code is below but not sure what it is exactly doing and how to make it work for me. Code:
Conformation And Searches
A) is '%' the mathematical symbol for 'is divisible by' in php? Say, if I put, if(10 % 2){ }, would that mean 'if 10 is divisible by 2, do this'? B) MySQL searches. How are they done? I recall something like "SELECT * FROM `table` WHERE `field` = '%value%'"; is that right?
Question About Radius Searches
I'm trying to use the longitude and latitude to do a radius search but I'm getting some inaccurate results, below is the code and I was wondering if anyone knows weather or not I'm doing the calculations any feed back is much appreciated. Thanks Todd class RadiusAssistant { var $maxLat; var $minLat; var $maxLong; var $minLong; function RadiusAssistant($Latitude, $Longitude, $Miles) { global $maxLat,$minLat,$maxLong,$minLong; $EQUATOR_LAT_MILE = 69.172; $maxLat = $Latitude + $Miles / $EQUATOR_LAT_MILE; $minLat = $Latitude - ($maxLat - $Latitude); $maxLong = $Longitude + $Miles / (cos($minLat * M_PI / 180) * $EQUATOR_LAT_MILE); $minLong = $Longitude - ($maxLong - $Longitude); } function MaxLatitude() { return $GLOBALS["maxLat"]; } function MinLatitude() { return $GLOBALS["minLat"]; } function MaxLongitude() { return $GLOBALS["maxLong"]; } function MinLongitude() { return $GLOBALS["minLong"]; } }
Zip Code Proximity Searches?
Does anyone know of a free web service or way of taking in a zip code, and returning a list of zip codes nearby? I have a DB of addresses (including zip codes) and I need the user to enter in their target zip code and see which locations are in their area. This seems to be a frequent requirement so there should be ways out there..
Creating A Search Class That Searches Any Database
I've been requested by a client to implement a search engine on it's website. I told him that he does not need it, but he thundered on and well...Who cares, he' s gonna pay for it. I've made search methods for other sites, but I would like to implement a portable one. A Search Class that could work for any DataBase and with ease of configuration. Maybe de constructor could receive a database name in which to search. And the function search, could receive an array of tables in which to search on and a string to search for on those tables. The question is...how would u implement the way that the class returns results? Nowadays any pro site has the MVC controller. That means that almost all tables in the database have its corresponding model. Table clientes correspond to the Client Model. How would you implement the results return?
Slow Website Speed During Searches & Category Browsing
I have a modified oscommerce website which works fine during checkout, going to the contact page, returns page, etc..., however, when it comes to navigating through the product categories or performing searches the website is extremely slow. Here is some basic info about my website. The website is being hosted on a dedicated not a shared server; so there aren't any other websites being hosted on the server. I do have a lot of products around 60,000 in my "products" table in mysql; which is where I think my problem is with my category & search speed issues. I've had programmers work on the website to increase the category navigation & search speeds; which helped a little but never got as fast as websites like amazon, buy, etc... Some things they told me they did was create indexes, query optimizations, and query caches. I don't want to keep on spending money without getting the results I'm looking for when it comes to category navigation & search speeds. Is there anything else I can try doing to improve the performance of these 2 issues?? I will give anything a try because I know having a slow website is very annoying to customers.
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:
Combine Variables???
Alright, I have variables $service1, $service2, $service3, etc, up to $sub services (the number varies). Here's what I have: while ($sub > 0): $aa = fopen("../subs/".$sn."-".$sub.".txt","w"); fwrite($aa, $service.$sub); fclose($aa); $sub = $sub - 1; endwhile; my problem is in the fwrite line-- I want to add $sub to the end of the $service variable, so, for example, when $sub = 3, it will process it as: fwrite($aa, $service3);
Is It Possible To Combine Querys
I'd like to be able to combine 2 search querys. For instance search my database using a "X AND Y" search which is very specific, then a "X OR Y" search which is more general. Then I'd like to combine the two into one query so that I can use this one result set to show whats in my database. This way the first thing someone will see will be very specific results to what they entered. make sense?
Combine Html And Php
How I can combine html and php on one site? Can I do that? I have nice disign downloaded from templatemonster.com and it is Frontpage file. How I can transform it to the php? What software I have to use to disign simple php site? (I would like to insert whois script on site.)
Combine PDF Files
I don't have the PDFLibs installed on my hosting and it's all pretty basic so I can't install this or anything similar myself. I'm generating a PDF from html pages using a neet little tool called dompdf, which works great except i now need to attach a seperate PDF page to the end of the generated page and this isn't built in. I was hoping that there might be something out there that could combine page1.pdf with page2.pdf on the fly in php.Any ideas? PS. converting page2.pdf to an image would also solve this problem, however imagemagick doesn't like page2.pdf because it contains funky fonts that cause errors and I cannot get page2.pdf generated in any other way.
Combine Arrays?
I am experimenting a little with tags, and in the database, I have a row called "tags", so that I can set the tags I want into the news I want. I use a comma between each tag. I explode the "tags" row, and all the tags from one of my news gets into an array. I want to combine all the arrays into one. Lets say that I have one post with the tags "free, basic, cool", and an other one with "program, free, open source". How can I combine these two arrays into one? If it's possible, I also want to remove double tags.
Combine Queries
I was wondering how I would combine queries that are stored in an array? The reason is to be able to order the multiple queries from the same "ORDER BY" which will be obtained from an url parameter. Also, the reasons the queries are in an array is, because they use the "WHERE" clause to SELECT "WHERE year = '$year'", and there could be several years (the years are obtained from $_POST) and I don't think there is a way to do something like: WHERE year = '$year[0],$year[1]'.
Combine Two Arrays? Well, Sort Of...
I am a relative PHP newbie and I am trying to combine two arrays together, but I also need to keep the keys of one array intact. What I am doing is two SNMP walks against a Cisco router in which I expect the script to return the interface number along with a small description of the interface type, like this: Array ( [IF-MIB::ifDescr.1] =Serial0 [IF-MIB::ifDescr.2] =FastEthernet0 [IF-MIB::ifDescr.3] =Null0 [IF-MIB::ifDescr.4] =Loopback100 ) I also am doing another SNMP walk to gather the user-defined description of each interface (which is keyed off of the interface number). Here is the output I get from that: Array ( [OLD-CISCO-INTERFACES-MIB::locIfDescr.1] ="PPP T1 to Customer" [OLD-CISCO-INTERFACES-MIB::locIfDescr.2] ="Ethernet to LAN" [OLD-CISCO-INTERFACES-MIB::locIfDescr.3] ="" [OLD-CISCO-INTERFACES-MIB::locIfDescr.4] ="" ) I would like to combine the arrays, but I would like to preserve the keys and values from the first array, but also append the values of the second array (don't really care about the keys, they *should* line up). I looked into the array_combine function, but that takes the values from the first array and makes them the keys for a new array. My ultimate goal is to output this to an HTML table, but the data is not lining up as I expected since when I join/combine the arrays, I lose my keys.
How To Combine And Pass Data In One Page?
I didn't know what to use as a title for this. Here is the scenario: I have a op.reqedit.php page. This page a form where you input data. In this page I have split a MySQL field. It is called MachineTypeOfWork and is split into Replace, Adjusted, REbuild, Inspected and Repair. These all become check boxes for the user. The form submits to op.reqadd.php. In this page I first have a hidden box where I combine all of the above into Type (this works fine, I have unhidden the box to see it). Then I have $MachineTypeofWork = $_GET['Type']; $sql_query = mysql_query("UPDATE results SET (a bunch of fields) MachineTypeOfWork='$MachineTypeofWork' WHERE WorkOrder = '$wo'") or die (mysql_error()); My problem is that it updates all of the fields it should except the MachineTypeOfWork field in MySQL. It actually overwrites what is already there with nothing. What I do not know (I am new) is can I combine the field and pass it to the database in the same page or do I need another page in the background for this?
2 Drop Down List Using MYSQL
I have a model table with the following fields: MODEL_ID, MAKE_ID, NAME. And a make table with the following fields: MAKE_ID, NAME. The first drop down list (make) to select a make of a car i.e. Chevrolet, Ford. When a make is selected, then all the model for that paticular make appear in the second drop down list.
PHP And MYSQL Drop Down List
I need a script to create a drop down list which has vehicle makes. The vehicle make list should feed a vehicle model list so when I select a make all the models for the make appear in the model list. I have a make table which has MAKE_ID, make NAME and a model table which has MODEL_ID, MAKE_ID and model NAME. I tried using a script using javascript array but wherever I have a query that pulls the NAME from the database there's always a carriage return after the NAME which messes up the javascript array. I'd rather do it all with PHP if possible. If not please give me one that works and I don't have to spend hours troubleshooting.
Mailing List Using MySQL / PHP
I have written a database which uses PHP to run through each ID in the database and then generate a persons name and address to include into the rest of the PHP to send an email out. But as people have deleted or updated their details on this mailing list, I now have "holes" in database. Ordinarily not a problem, but the code I've written starts at ID 1 and after sending an email increments to the next ID. But when it encounters a now vacant ID, it sends an error email to me associated with that now blank ID row of data. How can I change my code that will increment through all the results in turn, but not give me these error emails when people have amended the database?
Mysql Field List
We would like to be able to get the column list of a mysql Table from PHP code. I know from the mysql prompt we can get it, but we want to generate PHP code that will retun an array of columns If there is a column descriptor containing name, size, etc, that would be great. Something that I could loop thropugh an array in PHP4 and get the names of all the columns in the table as well as perhaps other column parameters as well. I believe that can be done in CGI, but want to use PHP4.
How To List Information From A Mysql Row
am i going about listing data from a mysql row the right way this is what i have so far: <?php include("connect.php"); $tbl_name = "userdata"; $res = mysql_query("select userid from $tbl_name"); while($row = mysql_fetch_array($res, MYSQL_ASSOC)) { echo "Name :{$row['userid']} <br>" . } ?>
List Into MySQL Automatically?
I want to insert the names of these links into my MySQL database, and assign them an auto-incrementing id number. The auto-increment isn't a problem, I want to know if there is a way to insert the names of these school names, without having to type them in individually which would be a very painstaking process.
Select List/Menu Using PHP And MYSQL
Here is my code: <select name="country" class="sidelinks"> <?php do { ?> <option value="<?php echo $row_AllCountries['country_ID']." ";?>"<?php if ($row_AllCountries['country_ID'] = $acountry) { echo "selected"; }?> > <?php echo $row_AllCountries['countryname'];?></option> <?php } while ($row_AllCountries = mysql_fetch_assoc($AllCountries)); ?> </select> A few words to describe: -$row_AllCountries['country_ID'](get from MySQL) is a unique country ID number -$row_AllCountries['countryname'](get from MySQL) is the name of the country -$acountry is the country ID number that i want to be selected when the form loads I have all the values and country names named OK...the only problem is that when the form loads it selects the last country.
List Mysql Data Using Php With Sub Headings?
i've got a database table storing products for a hire company, the database is a copy of their brochure so i'm sorting by page sections so link to section 4 reads /product.php?page=4 Code:
MySQL Results Not Working So Hot
Ok. Here I am again....probably posing a question with a solution so easy that, after looking at it for an hour, I can't figure out. Ok. here's the deal. please review the code below. Looks simple enough, right?
Mysql Writing Results From 51 To 100
Can someone write me a mysql_query code which will get me results from 51 to 100 from $database? Don't suggest me working with indexes, because i'm also deleting some rows (for example #1 is filled #2 is not, #3 is...)
Show Next Results Of MySQL DB
How do I get it so that php reads in the first 10 results out of a MySQL database. Then when Next or something is hit it displays the next 10 results and so on.
MySQL Results To Return Only One Value
For example, I have a column that has three different values, 1, 2, & 3. In the database, there may be over 500+ entries with one of these values assigned to it. How can I get MySQL to return just 1, 2, & 3 only once rather than several hundred times.
Hyperlinked MySQL Results W/PHP
I was wondering how results to db querys have attached links to each individual result? I have a good grasp of basic PHP & MySQL, but don't understand how that works. For example, if you have a db of products, all with individual id #, how do you get one product from the query a <ahref>? Could someone explain?
Compiling MySQL Results
Does anyone know how to compare multiple results from a MySQL query? For example, I would like to query the database and collect all the results into a variable (perhaps $totalresults). Then, I would like to use a single statement to compare each of the results within $totalresults to the statement's conditions.
Getting Results From MySQL Database In PHP
I am trying to write a php page which connects to a MySQL Database which is supposed to get the results from a table within a database and display the results in a table. Below is the code that I am using:
Limit Mysql Results
I have a script which has a mysql query which returns 20 results - I want to add some validation so if my variable ($var) is empty, it only allows the user to select the first 5 results my code is: - $sql = mysql_query("SELECT * FROM greetingcards_cards WHERE category='$cat' LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ $image = $row['url']; $cardid = $row['cardid']; echo "<br><img src="$image" /><br><a href="?function=sendmessage&cardid=$cardid">Pick this card</a><br>";} I want it so that if the variable is empty, instead of displaying "Pick this card" it displays - "You must register to pick this card" and have a different hyperlink Is this type of validation possible? if so how is it done?
PHP MySQL Order Results
I'm using: $sql = "SELECT * from $myTable ORDER BY `points` DESC LIMIT 5"; in a whileloop to display the top five scorers but would like to put their position next to the results (eg, 1, 2, 3, 4 and 5) Is there an easy way to do this?
Convert MySQL Results To XML
I just got Dreamweaver CS3, and I love the built in SPRY framework. It allows you to create web applications that use a table listing, and details listing very quickly. Unfortunately the only data the SPRY framework can accept is XML. Is there a built in function to convert from a $row result from MySQL to XML? Code:
Mysql Results - Ordering Them.
i need an mysql query to rank the results, like SELECT field FROM table and to order them greatest to least by the value of a different field.
Mysql Results Pagination
I have a php code to split the results of a sql query over pages taht works great... But I need to add some feature, I need to add that if there are more than * pages it shows me "..." instead of the hole numbers of pages.. Code:
Sum All Of My MySQL Integer Results?
I have a bunch of rows, and for each row, the column "rating" has a number from 1-5. I need to add all of these together, so like if there were 3 rows with 5 for rating, it would return 15. If it's possible to do it with an SQL statement, I'll like it to average them.
Splitting MySQL Results
So I have a database, and I want to split the results into 2 columns. I don't want to alternate them, but have the first half in the left column, and the second half in the right column. How can I handle this so that it does it automatically no matter what number of entries (and so that if it's an odd number, the one overflow is on the left).
Dynamic List Populated By MySQL Table
I am building my first php page and I've ran into problems trying to create a dynamic drop down list for an INSERT page. My page is based on this example from mysql.com. I want to populate the list from a table in MySQL, but when I test the page the list only contains the first record. If anyone can help me out, or recommend an easy way to create dynamic menus/lists, I will be very grateful. This code appears above the FORM ACTION: $NearMajorCity = mysql_query("SELECT NearMajorCity_ID, NearMajorCity FROM NearMajorCity"); This code is within the FORM: <SELECT NAME="NearMajorCity" SIZE=1> <OPTION SELECTED VALUE="">Select One <OPTION VALUE="">--------- <?php while ($NearMajorCity = mysql_fetch_array($NearMajorCity)) { $NearMajorCity_ID = $NearMajorCity["NearMajorCity_ID"]; $NearMajorCity = $NearMajorCity["NearMajorCity"]; echo("<OPTION VALUE='$NearMajorCity_ID'>$NearMajorCity "); } ?> </SELECT> I want to be able to view the names of the Major Cities in the list, but I want the NearMajorCity_ID inserted into the table.
Multiple Drop Down List Problem And MySQL
I am trying to populate around 30 drop down lists via a single query to a mySQL database. The problem is how to make sure that each drop down list only display it's relevant data. for example the table is as follows:
|