mysql

Search query is automatically executed on each load, without clicking the search button

I want my code to execute a query based on the values in the search keyword text boxes. But the current code executes the default query each time at the time of loading, Help. Any help will be appreciated. Plz help rentals_search.template.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DT...

Maintaining order in MySQL "IN" query

I have the following table DROP TABLE IF EXISTS `test`.`foo`; CREATE TABLE `test`.`foo` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(45) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Then I try to get records based on the primary key SELECT * FROM foo f where f.id IN (2, 3, 1); I th...

MySQL - DB Design for "has many" issue across tables vs stored lists

Trying to figure out the best way to set up collection "lists" for users given the following data (pseudo code): user table = id, name, email cars table = id, make, model user_cars table = user_id, car_id, rating collections table = id, user_id, name Facts: Users can have many cars Users can have many collections Individual cars ...

How do you install MySQL 5.1 on Ubuntu 8.10?

According to various blogs and forums, you should be able to do simply "sudo apt-get install mysql-server-5.1". But I tried and it doesn't work (package not found by this name). What am I missing? ...

PHP, MySQL: Duplicate series of rows, but change 1 column?

I have a table called scheduler_sched which has several columns, including a column called schedule_id. I need a function where I can pass 2 ids (copy_from_id, copy_to_id) as parameters. And what I need to do is take every row where schedule_id = copy_from_id AND duplicate it but change the copy_from_id to the copy_to_id So basically ...

Is BIGINT(8) the largest integer mysql can store?

I've got some numbers that is now larger than INT can handle. This is a bit embarassing, but I honestly don't know exactly what the BIGINT(8) means. Is the 8 in that the max bit value or the max length? So BIGINT(1) can only be one digit? Or is BIGINT(1) something else? I think tinyint(1) max is 127, how does that work out? What is th...

Should I be concerned about mysql message "Suspicious setup: User "mysql" maps to user: _mysql" ?

Running MySQL Ver 14.14 Distrib 5.1.37 on Mac OS X 10.5. Logs contain the following message Suspicious setup: User "mysql" maps to user: _mysql Should I be concerned? ...

CFQUERYPARAM breaking with "+" in URL

I have a query: SELECT id FROM table WHERE field1=<cfqueryparam value="#URL.field1#" cfsqltype="cf_sql_varchar"> AND field2=<cfqueryparam value="#URL.field2#" cfsqltype="cf_sql_varchar"> AND field3=<cfqueryparam value="#URL.field3#" cfsqltype="cf_sql_varchar">; Id is an INTEGER in MySQL, but the above query return...

What is the difference (when being applied to my code) between INT(10) and INT(12)?

If I use INT(12) vs INT(10) or INT(8) what will this actually do in terms of me using in code? (This is a spin off of a previous question) I read through the manuals and I think I understand what they're saying, but I don't actually know how it would apply to my php/mysql coding. Can someone provide an example of where this would actu...

Duplicate a record in MySQL

I have a table and I want to duplicate specific rows in the table. I know this is not the best way to do things but we are looking for a quick solution. Here's something harder than I initially thought, all I need to do is copy an entire record to a new record in an auto-increment table in MySql without the need to specify each field. T...

How to arbitrariarly sort MySQL result set

Possible Duplicate: Maintaining order in MySQL IN query Considering this statement: SELECT * FROM `items` WHERE `item_id` IN(9, 2, 4, 5); is there a way to have the results returned in the order of the IN clause? e.g. 9 2 4 5 ...

Mysql GROUP BY and COUNT for multiple WHERE clauses

Simplified Table structure: CREATE TABLE IF NOT EXISTS `hpa` ( `id` bigint(15) NOT NULL auto_increment, `core` varchar(50) NOT NULL, `hostname` varchar(50) NOT NULL, `status` varchar(255) NOT NULL, `entered_date` int(11) NOT NULL, `active_date` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `hostname` (`hostname`), KEY `st...

How to get the greatest of two columns values in MySQL?

I'm trying to do something like this: SELECT MAX( ADDDATE(expirationdate, INTERVAL 1 YEAR), ADDDATE(now(), INTERVAL 1 YEAR) ) That is, get "a year from now", or "a year from the expiration date stored in the table", whichever is greater (i'm renewing people's subscriptions). This obviously doesn't work, since MAX() is for aggrega...

How to preserve hyperlink when submitting via php form into MySQL

Hi All, I've created a form that stores free text fields into a MySQL database. All works fine and the data is displayed back as intended when viewed. Except for one niggle. In an attempt to prevent malicious attacks I have used mysql_real_escape_string to remove any unwanted code from the input. However, I need to be able to preserv...

Select and group rows in summary by hour

I have a table containing view/click records. The time is stored in a unix timestamp and I need to be able to pull out all of them within the specific month/day (based off of timestamps), but more importantly and the part I don't know how to do is group them by hour. I need to be able to do this in a single query rather than looping thr...

MySQL - Query to move part of 1 field's contents to a new field

I have a table called cartypes which currently has 2 fields: id & type. I am adding subtype and I want to move the contents after the dash - from the field called type and put those contents into subtype. Disposing of the dash (any extra whitespace too for that matter). What's the best SQL query for this? before: id type ...

Multiple column foreign keys / associations in ActiveRecord/Rails

I have badges (sorta like StackOverflow). Some of them can be attached to badgeable things (e.g. a badge for >X comments on a post is attached to the post). Almost all come in multiple levels (e.g. >20, >100, >200), and you can only have one level per badgeable x badge type (= badgeset_id). To make it easier to enforce the one-level-p...

Searching multiple tables with Subquery

Hello, What I need to do is searching from companies and tags table and listing companies. My table structure is as follows; tags (tag_ID, tag) tag_relation (tag_ID, company_ID) companies (company_ID, company_name, company_description) The query should be able to search both company info (name, description) and tags. If tag searched,...

Is there a way to use a wildcard in a "where" statment for MySQL?

I have a query that uses a where clause. At times, this may be used and at others, I may want to omit it completely to get back all results. I can certainly write two different queries but I would like to cut down on any code that I can for simplistic reasons. Is there a way to do this in mysql? Take a query like: SELECT * FROM my_tabl...

Select closest numerical value with MySQL query

This is probably easier than I am making it, but basically what I need to do is select the row that has the closest number in a column as a specified value. For example: List of values in database for 3 rows in a specified column: 10, 15, 16 If I specify that I want the row that is closest to 14, it would pick the row with 15. Also, ...