mysql-query

How to find a gap in a time ordered table where a given column does not have a certain value for a specified interval.

I have a large table (millions of rows) where I need to find groups of records based on the presence of a certain column value and where a specified 'timeout' has not occurred. I figure one approach would be to find across the entire table where these 'timeout' gaps have occurred. Example table: +----------------+------+ | time ...

How to see which queries has been executed. (mysql)

Hi, I run a site at localhost and i would like to see which queries are executed. I've seen that some pages execute a lot of queries (eg 107) and i would like to see which are all these,as i think they're a lot.. (i know how many queries are executed, as the queries are executed through a function which also stores at a global value the...

MySQL to PostgreSQL: GROUP BY issues.

So I decided to try out PostgreSQL instead of MySQL but I am having some slight conversion problems. This was a query of mine that samples data from four tables and spit them out all in on result. I am at a loss of how to convey this in PostgreSQL and specifically in Django but I am leaving that for another quesiton so bonus points if ...

Hide / show list in PHP

I have a list generated by MySQL. When I click one item of the list, it shows a new list related to the item in the same page. Edit: Here is the code how I get the list. <?php include("./conn/connect.php"); $query = "SELECT * FROM entreprise ORDER BY id"; $result = mysql_query($query) or die("result failed: ".mysql_error...

MySQL is SELECT with LIKE expensive?

The following question is regarding the speed between selecting an exact match (example: INT) vs a "LIKE" match with a varchar. Is there much difference? The main reason I'm asking this is because I'm trying to decide if it's a good idea to leave IDs out of my current project. For example Instead of: http://mysite.com/article/391239/t...

MySQL MAX shows wrong result for associated data

I am creating a query to pull results from a MySQL database using PHP, the results of the query are output to an Excel document. Here is the query: $sql = "SELECT node, port, MAX(utiltx), MAX(utilrx), time, hour(time), day(time), month(time) FROM intfstats WHERE node IN('$separated') AND year(time)=$year AND month(time)=$month AND por...

Re-runnable mysql upgrade script

Is there a way in mysql to write a re-runnable sql script? I tried the : 'IF EXISTS' syntax but that only seems to work for stored procedures. It doesn't seem the 'select if' syntax will do what I want. Ideally I would like to do something like: IF NOT EXISTS (select * from table where name='Name') Then insert into table values('Name')...

MySQL Accounts Aging Report

I'm trying to get a query working in MySQL 5.0.81 that will pull the amount due on invoices that havent been paid. I have three tables that look like so: CREATE TABLE `CLMS_invoices` ( `invoices_id` mediumint(8) NOT NULL auto_increment, `invoices_client_id` mediumint(8) NOT NULL default '0', `invoices_datetimestamp` varchar(50) c...

Observed something weird with MySQL... Query suddenly becomes super fast...

I have a column "name" in a table and there are at least 10 million records. I've added an index on this name column. Now, for the first initial few searches, it was taking more than 10 seconds to return a single answer (whether the name was present or not) but suddenly, it gives me the result in less than 0.1 seconds. Am I missing somet...

Store keywords into database

Hi All, I am having one form in which user will be entering keywords seperated by commas. i need to store this keywords into database mysql. each keyword should be in new row. For that keyword the row id is being extracted from parent table. ...

select count and other recors in one single query

i have the following query select main_cat_name,cat_url from mf_main order by main_cat_name this returns whole data of my table.Now i want to have count of the total rows of this table.I can do it using another query but how can i use them in one single query??? i want two data ONE :- the rows of the table TWO:- the count how can i ha...

Conditional columns in MySQL that need to do joins

I've researched related questions on the site but failed to find a solution. What I have is a user activity table in MySQL. It lists all kind of events of a user within a photo community site. Depending on the event that took place, I need to query certain data from other users. I'll explain it in a more practical way by using two examp...

Detect when MySQL tables are in readlock state (from PHP)

Hello, I need to get a PHP app to detect when it's MySQL database is in readlock, and throw an error message. Easy, but is there any MySQL command we can run to check current lock state, rather than just having the system get stuck, as the query is queued for the unlock? Cheers, Johnathon Edit: The database is being put in readlock b...

SQL ORDER by `no` with NULLs at the end

Hi! I have got a MySql query that orders me results by no column (int, can be null). Simple example: SELECT * FROM table ORDER BY no ASC I would like to get a resultset sorted like 1, 2, 3, 10, 52, 66, NULL, NULL, NULL but I get NULL, NULL, NULL, 1, 2, 3, 10, 52, 66 Is it possible with SQL query ? ...

MySQL UPDATE using IF condition

I'm not even sure if this is possible but I'm trying to do different UPDATE if a certain condition is met. user [id, start_date(NOT NULL), end_date(NULL), reason(NULL), .....] user_roles [id, role_id, user_id, start_date(NOT NULL), end_date(NULL)] What I have right now is this but this only works if a role exists for the user and it'...

Parse error help, PHP unexpected T_STRING (probably something simple)

It's probably something simple I am not seeing because I've stared at it too long. Any ideas? It's throwing on line 119, I've indicated it below Parse error: syntax error, unexpected T_STRING in /home6/cleanai4/public_html/act.php on line 119 I'm just trying to format a phone number. Thanks for the help in advance. if(isset($s...

Recusive function

Hi i have the below table datas id parent_id name 1 Machine 2 3 Ram 3 4 Cpu 4 Computer 5 6 food1 6 food2 My need is to select possible parents for example 1) if we select 'machine' all others can parents 2) if we select 'cpu' then '...

Create stored procedure in mysqladmin?

I am trying to create stored procedure in mysql admin. I am hosting a website in POWWEB.com. For this purpose i am trying to create stored procedure in mysqladmin. The Mysql version is 5.0.45. I am able to create a stored procedure with only 1 line of code. CREATE PROCEDURE TEST(input INT) INSERT INTO TEST(COL1) VALUES(input...

mysql+php to subtract two times and display the differrence

hi!! i've to display the differences between a column(reg_time) in mysql and the present time so that the final output (after some php to display in minutes or seconds or hours or days) be: Registered : 8 hours ago. is there any function to do that? thanks ...

php warning mysql_fetch_assoc

I am trying to access some information from mysql, but am getting the warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource for the second line of code below, any help would be much appreciated. $musicfiles=getmusicfiles($records['m_id']); $mus=mysql_fetch_assoc($musicfiles); for($j=0;$j<2;$j++) { if(fi...