mysql

[MySQL, InnoDb] Rating place

I'm trying to generate rating place table using following receipt http://stackoverflow.com/questions/1776821/assign-places-in-the-rating-mysql-php but my database is high loaded. I tried not to create table, but use MEMORY TABLE and update it using following SQL query insert into tops (uid) select uid from users order by exp desc; ...

Insert date and time into Mysql

Hi..guys I am trying to insert date and time into mysql datetime field. When a user select a date and time, it will generate two POST variables. I have searched internet but still not sure how to do it. My code. //date value is 05/25/2010 //time value is 10:00 $date=$_POST['date']; $time=$_POST['time']; $datetime=$date.$time If...

help for a query

Hi, i've a problem for a table update. follow table structure: Table1 tableid ... ... productID_1 productID_2 productID_3 Table2 productID Total I've to totalize each product in table2. For example: SELECT COUNT(*) as tot, ProductID_1 FROM Table1 GROUP Table1 then the UPDATE table2 SET total =..??? (how can...

1054 - Unknown column 'apa_calda' in 'where clause'

I keep getting the error 1054 - Unknown column 'apa_calda' in 'where clause' in MySQL. Here is the query: SELECT user_id FROM `detalii_contor` WHERE tip_contor=apa_calda I want to use this query in a PHP file but it doesn't give any results. So I tried to write it in the SQL command prompt. Here is what I tried in the PHP file: $Q = ...

mysql replace into alternative

i'm currently using a replace into statement, I have a unique field which will cause it to UPDATE rather than INSERT if it finds a duplicate... Problem is if it finds a duplicate i can't get to update on a few columns, it just wipes the lot. Is there a similar "one statement" method where I can just UPDATE what I want? I've found mer...

trouble selecting FROM WHERE ?

Hi guys, I have this code, but strangely it always echos out "yes!", even if there is no such value as '555' in FLD2 or even if there's no FLD2 at all. $testresult = mysqli_query($database, "SELECT * FROM imei359327039828680 WHERE FLD2 = '555'"); if ( $testresult ) { echo('yes!'); } else { echo('no!'); } Any idea, thanks! ...

Are the ususal database performance-tuning tips invalide for a third-party app like Drupal

When you have a slow database app, the first suggestions that people make is to: Track the slow queries Add appropriate indexes In the case you are building your own application this is very logical, but when you use a CMS like Drupal, that are people have developed and tuned, is this approach valid? I mean, aren't Drupal tables alr...

MYSQL COUNT and only show results above X

Hey All Is it possible to count all reservations for users and only get results where users have had more than X reservations. Here is my code to just count all user's reservations SELECT u.firstname, u.lastname u.email, COUNT(r.reservation_id) as orders FROM users AS u LEFT OUTER JOIN reservation AS r USING (user_id) GRO...

How to write this loop prettier?

I've just read this topic http://stackoverflow.com/questions/2930533/highlight-search-keywords-on-hover and actually I use pretty the same structure, but it looks awful. So can you give me an advice, how to write this loop prettier in one php file, I mean php and html at the same time? <table class="result"> <?php while ($row= mysq...

SQL hidden techniques?

Possible Duplicate: Hidden Features of SQL Server What are those pro/subtle techniques that SQL provides and not many know about which also cut code and improve performance? eg: I have just learned how to use CASE statements inside aggregate functions and it totally changed my approach on things. Are there others? UPDATE: ...

Drupal: Many fields/content-types equal *many* tables and after a point make MySQL very slow

As I create more and more fields and content-types, I see that Drupal creates a huge numbers of tables (>1k) in MySQL and after a point my system becomes very slow. I have tried several MySQL performance tuning tips, but nothing has improved the performance significantly. Enabling caching makes for good speed in the front-end, but if I...

json encodes aray

Okay I have been struggling with this for hours. What I am doing is creating array of what I call objects that can be moved around on a calendar. Below is my code $year = date('Y'); $month = date('m'); echo json_encode(array( array( 'id' => 111, 'title' => "Event3", 'start' => "$year-$month-10", '...

Is it necessary to have an ID column if a table has a unique column in Mysql?

I have two tables A,B. Both tables will have more than 1 million records. A has two columns - id, photo_id. id is the primary key and photo_id is unique. A needs to be referenced in B. 3 questions: Can I ignore A's id and use photo_id to link the two tables? Is there any benefit of using the primary column as opposed to using a ...

Do MyISAM holes get filled in automatically?

When you run a delete on a MyISAM table, it leaves a hole in the table until the table is optimized. This affects concurrent inserts. On the default setting, concurrent_inserts only work for tables without holes. However, in the documentation for MyISAM, under the concurrent_insert section it says: Enables concurrent inserts for a...

How can I use SQL to select duplicate records, along with counts of related items?

I know the title of this question is a bit confusing, so bear with me. :) I have a (MySQL) database with a Person record. A Person also has a slug field. Unfortunately, slug fields are not unique. There are a number of duplicate records, i.e., the records have different IDs but the same first name, last name, and slug. A Person may also...

Recursive MySQL function call eats up too much memory and dies.

I have the following recursive function which works... up until a point. Then the script asks for more memory once the queries exceed about 100, and when I add more memory, the script typically just dies (I end up with a white screen on my browser). public function returnPArray($parent=0,$depth=0,$orderBy = 'showOrder ASC'){ $que...

how do i use workbench to connect to a mysql DB?

i am trying to connect to my local db using workbench but i do not see any way to connect. how do i do it? i already have this connection saved and succesfully tested. ...

index 'enabled' fields good idea?

Content of a website is stored in a MySQL database. 99% of the content will be enabled, but some (users, posts etc.) will be disabled. Most of the queries end as WHERE (...) AND enabled Is it a good idea to create an index on the field 'enabled'? ...

MySQL query paralyzes site

Once in a while, at random intervals, our website gets completely paralyzed. Looking at SHOW FULL PROCESSLIST;, I've noticed that when this happens, there is a specific query that is "Copying to tmp table" for a loooong time (sometimes 350 seconds), and almost all the other queries are "Locked". The part I don't understand is that 90% ...

Storing SQL in MySQL: Insert as Text?

Hey all, Working in a team environment, each one of us has put together our own list of SQL statements that we use to help with our day to day job functions. As the case often is, there may be some redundancy with this, and we are often in need of each other's statements. To circumvent this, I'm looking to put together a small app tha...