mysql

MySQL: filling empty fields with zeroes when using GROUP BY

I've got MySQL table CREATE TABLE cms_webstat ( ID int NOT NULL auto_increment PRIMARY KEY, TIMESTAMP_X timestamp DEFAULT CURRENT_TIMESTAMP, # ... some other fields ... ) which contains statistics about site visitors. For getting visits per hour I use SELECT hour(TIMESTAMP_X) as HOUR , count(*) AS HOUR_STAT FROM c...

Doctrine issue - Different queries, same results but not with Doctrine

Hi, i'm having a little issue with doctrine using symfony 1.4 (I think it's using doctrine 1.2). I have 2 queries, using raw sql in the mysql console, they produce the same resultset. The queries can be generated using this code : $dates = Doctrine::getTable('Picture') ->createQuery('a') ->select('substr...

Using jQuery in MySQL php

I am new to using Jquery using mysql and PHP. I am using the following code to pull the data. But there is not data or error displayed. JQUERY: <html> <head> <script> function doAjaxPost() { // get the form values var field_a = $("#field_a").val(); $.ajax({ type: "POST", url: "serverscript.php",...

How can I employ "if exists" for creating or dropping an index in MySQL?

I was wondering if there's a way to check if an index exists before creating it or destroying it on MySQL. It appears that there was a feature request for this a few years back, but I can't find any documentation for a solution. This needs to be done in a PHP app using MDB2. ...

Change date format (in DB or output) to dd/mm/yyyy - PHP MySQL

MySQL stores the date in my database (by default) as 'YYYY-MM-DD' The field type for my date is 'DATE' (I do not need any time storage).. Is there a simple way to change it by default to DD/MM/YYYY ? I call up different dates in 2 different tables, and no where in any of my code do I have anything resembling a date variable or anything!...

How would I order this SELECT statement in MySQL?

cursor.execute("SELECT user_id FROM myapp_location WHERE\ GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(PointFromWKB(point(%s, %s)))))) < %s"\ ,(user_utm_easting, user_utm_northing, 500)); This query selects users which are within 500 feet of the current user. How would I order people by the distance? (the...

How do I get records from the database for a particular interval?

My table has records for every minute, now I want to fetch records with an interval of 5 minutes! For instance order date 1 12:01 2 12:02 .... 10 12:10 11 12:11 Expected result: Order 6 and 11 Can it be done at database level? I am using Django with MySQL ...

Submiting a Form without Refreshing the page with jQuery and Ajax Not updating MySQL database.

I'm a newbie to JQuery and have a problem, when I click submit button on the form everything says registration was successful but my MYSQL database was not updated everything worked fine until I tried to add the JQuery to the picture. Can someone help me fix this problem so my database is updated? Thanks Here is the JQuery code. $(...

SQL group by: using where-clause logic to filter results based on aggregate functions

I have a basic group by/avg statement: select url, avg(contentping+tcpping), count(*) from websites ws, ping pi where ws.idwebsite = pi.idwebsite and errortype is null group by url order by avg(contentping+tcpping) asc; What I want to do now is to drop any results which have a higher than average ping of 500. How can I do this...? ...

MySQL: averaging with nulls...

Is there a simple way I can exclude nulls from affecting the avg? They appear to count as 0, which is not what I want. I simply don't want to take their average into account, yet here is the catch, I can't drop them from the result set, as that record has data on it that I do need. Update: example: select avg(col1+col2), count(col3) f...

GROUP BY and SUM distinct date across 2 tables

I'm not sure if this is possible in one mysql query so I might just combine the results via php. I have 2 tables: 'users' and 'billing' I'm trying to group summed activity for every date that is available in these two tables. 'users' is not historical data but 'billing' contains a record for each transaction. In this example I am sho...

Entity Spaces connect to mySQL and Access in same website

Hi all, I have a website built that uses MySql for data management. Everything works great there, however, I am now trying to add our web statistics to it - we have a generic standard that we use. This requires a connection to an MS Access database for login - user name and password, checks acess to that specific site. The stats w...

PHP/MYSQL Year Month table for news archive

I am creating a news archive for my site and want to create an overview page from the following DB table id - Unique identifier newsDate - in a format XXXX-XX-XX title - News Item title details - News item photo - News Item Photo caption - News Item Photo caption update - Timestamp for record The news on the site is current but I hope...

MySQL: SELECT a Winner, returning their rank

Earlier I asked this question, which basically asked how to list 10 winners in a table with many winners, according to their points. This was answered. Now I'm looking to search for a given winner X in the table, and find out what position he is in, when the table is ordered by points. For example, if this is the table: Winners:...

mySQL query not returning correct results!

Hi! This query that I have is returning therapists whose 'therapistTable.activated' is equal to false as well as those set to true! so it's basically selecting all of the db, any advice would be appreciated! ` $query = "SELECT therapistTable.* FROM therapistTable ...

Is there any way to modify a column before it is ordered in MySQL?

I have a table with a field value which is a varchar(255). The contents of the field can be quite varied: $1.20 $2994 $56 + tax (This one can be ignored or truncated to $56 if necessary) I have a query constructed: SELECT value FROM unnamed_table ORDER BY value However, this of course uses ASCII string comparison to order the resu...

mysql full text search

I want to do full text search efficiently in MYSQL using match against. Specially I need to use binary operators(eg. match some text but not other text). However I also need efficient transaction support. But full text search is only supported on MYISAM, not Innodb. What to do? ...

mysql like performance boost

is there anyway to speed up mysql like operator performance if wild card is involved? eg. like '%test%' ...

Re-Convert timestamp DATE back to original format (when editing) PHP MySQL

Ok so I have managed to get the format of the date presented in HTML (upon display) to how I want (dd/mm/yyy)...However, the user also can change the date via a form. So this is how it's setup as present. Firstly, the conversion from YYYY-MM-DD to DD/MM/YYYY and then display in HTML: $timestamp = strtotime($duedate); echo da...

MySql Query lag time / deadlock?

When there are multiple PHP scripts running in parallel, each making an UPDATE query to the same record in the same table repeatedly, is it possible for there to be a 'lag time' before the table is updated with each query? I have basically 5-6 instances of a PHP script running in parallel, having been launched via cron. Each script gets...