mysql

How to merge two nested set structures with on mysql query

Hey MySql Pros hope you can get me a hint, I've a problem with my NestedSets Structure. I have two NestedSets Structures, the first Structure(MainNestedSets) holds my nested sets information and a ReferenceCID to another NestedSets Structure(OtherNestedSets) see below. Now I want to receive the Result set seen in ResultAfterQuery, how...

Store Duration in MySQL

What's the best method of storing the duration of an activity in a MySQL Table if there are 3 possibilities: Activity lasts the full day Activity lasts only half a day User specifies the length in Hours:Minutes The UI has a combobox with (Full Day/Half Day/Manual -> here a hour:minute selector shows up). I am thinking of storing the d...

MySQL Query Join and Count Query

Hi, I'm trying to pull values from a database for a web app where a moderator can add companies to a list of specified industries. This request needs to pull each industry's name along with a count of attached active companies, as an overview to the moderator. These are my tables: companies ____________________________________ | id ...

the fastest way to insert multiple rows in mysql with a fixed value for a column

I'm looking for the fastest way to insert multiple rows in a MySql table with two columns. One column has a constant value (1 for example) while the other always changes. I am using php and i have a large string with email addresses (thousands), i want to put it in a table with the columns: email_cat_id and email_address. The email_cat_...

PHP to MySQL SSL Connections

I have successfully setup an SSL enabled install of MySQL on one server on one network and can connect to it using SSL with the Linux command line mysql client on a different server on a different network, however every time I try to connect (using PHP 5.3.3) I keep getting: Warning: mysqli_real_connect(): (HY000/2026): SSL connection ...

How to access Mysql::Result in ActiveRecord?

Example: result = ActiveRecord::Base.connection.execute("select 'ABC'") How can I get the 'ABC' value from result? Tried result.first without success. Thanks p.s. Gems: activerecord (2.3.9) mysql (2.8.1) ...

Multiple count functions in a SELECT query

I have a select query like this select count(distinct id)*100/totalcount as freq, count (distinct id) from <few joins, conditions, gorup by here> ..... Will this result in 2 calculations of count under MySql 5.0? I can calculate the frequency in my appliation as well if this is a problem. I am aware of the solutions presented in htt...

I want to create a menu editor for my website using PHP and AJAX

I created menu.php which loads the menu items from a MySQL database, parses them through a function which creates the code for the menu items which are then displayed in order in an HTML list (tell me if this is confusing and I can post the code). What I would like to make is an admin page the would allow the user to reorder the menu ite...

mysql : temporary, filesort with 2 little tables : how can i improve my query ?

CREATE TABLE tableA ( `key` int(11) NOT NULL, `value` int(11) NOT NULL, UNIQUE KEY Akeyvalue (`key`,`value`), KEY Avalue (`value`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE tableB ( `key` int(11) NOT NULL, `value` int(11) NOT NULL, UNIQUE KEY Bkeyvalue (`key`,`value`), KEY Bvalue (`value`) ) ENGINE=InnoDB DEFAULT CHARSET=l...

Phpmyadmin - import new column to existing records

Hi, I already have a table in phpmyadmin that contains users records. Each user has a unique admission number. I now want to add a new column to this table and was wondering how I can import data for this new column using just the admission number and new data. Is this possible? I have a CSV but can't work out the best way to import th...

PHP Print only select rows for SQL Enquiry Results.

In PHP I am having difficulty trying to extract row data from one SQL Query results. The service information I require is stored in an array called $SelectedItems. The Code below works as it should but Prints the Entire table with all rows. How would I get it to simply print the 1 row. $sql ="select blah blah" //Output result ...

Feasibility: Auto-tweet on Update of a page

On my company's website we have a display of 40 100px X 100px images that represent the projects that we have been involved in. We have more like 150 projects, but only 40 are displayed on the homepage and the selection of the 40 is random. See Example Here. We also have an Update page which sorts these 40 projects by the date they were...

speeding up mysql queries / mysql views in django

I use the following code to select popular news entries (by date) from the database: popular = Entry.objects.filter(type='A', is_public=True).extra(select = {'dpub': 'date(dt_published)'}).order_by('-dpub', '-views', '-dt_written', 'headline')[0:5] To compare the execution speeds of a normal query and this one I ran the following mysq...

When to add what indexes in a table in Rails

I have a question about Rails database. Should I add "index" to all the foreign keys like "xxx_id"? Should I add "index" to the automatically created "id" column? Should I add "index(unique)" to the automatically created "id" column? If I add index to two foreign keys at once (add_index (:users, [:category, :state_id]), what happens? H...

Bulk insert with sqlAlchemy ORM

Is there any way to get sqlalchemy to do a bulk insert rather than inserting each individual object. i.e., doing: INSERT INTO `foo` (`bar`) VALUES (1), (2), (3) rather than: INSERT INTO `foo` (`bar`) VALUES (1) INSERT INTO `foo` (`bar`) VALUES (2) INSERT INTO `foo` (`bar`) VALUES (3) I've just converted some code to use sqlalchemy...

Master Log Position not moving in MySQL Replication

I have two MySQL servers configured in a Master-Slave relationship. Master -> my.cnf: server-id=1283522287 log-bin = /var/log/mysql/binary.log // There are write permissions here. binlog_do_db= foo,bar Slave -> my.cnf: server-id = 1283706035 master-host = {master internal IP} master-port = 3306 master-user = {master slave user} m...

Mysql: converting date fro 'dd/mm/yyyy' to 'yyyymmdd'

Im working on a database that store dates in a varchar(10) mysql field (so sad). I can not alter the database structure (im building a small plug-in), but i have to query the database finding rows where this data field is between the next 10 days. Example: | fid | fdate | | 1 | 10/09/2010 | | 2 | 17/09/2010 | | 3 | 19/09/20...

How to sync two database tables with each other in mysql PHP

I have two tables called clients, they are exactly the same but within two different db's. Now the master always needs to update with the secondary one. And all data should always be the same, the script runs once per day. What would be the best to accomplish this. I had the following solution but I think maybe theres a better way to do...

Migrate data from MySQL to Google App Engine (Python) Data Store

Hey, I have a legacy website created in PHP and MySQL. I wish to migrate this onto Google App Engine (Python). Has anybody done this before? Any examples, tips, resources, tools you'd like to share? I believe I will have to use "bulkloader" introduced in the GAE docs. Still haven't figured out how to get started. I have two tasks: ...

Mysql join for thread and its replies

Ok, I am willing to create a simple forum for my website. So, let's begin. I guess thread table is going to be smth like this: t_id, thread_name, who_created, when_created And replies table is going to be smth like this: r_id, t_id, who_wrote, what_wrote, when_wrote And when somebody wants to view thread with replies, he clicks bu...