mysql

Display rows from MySQL where a datetime is within the next hour

I always have trouble with complicated SQL queries. This is what I have $query = ' SELECT id, name, info, date_time FROM acms_events WHERE date_time = DATE_SUB(NOW(), INTERVAL 1 HOUR) AND active = 1 ORDER B...

MYSQL - Group by limit

Hello Is there a simple way to LIMIT the GROUP BY results to the top 2. The following query returns all the results. Using 'LIMIT 2' reduces the overall list to the top 2 entries only. select distinct(rating_name), id_markets, sum(rating_good) 'good', sum(rating_neutral)'neutral', sum(rating_bad) 'bad'...

How to renumber primary index.

I have got a simple MySQL table and primary index (id) is not numbered one by one (1, 31, 35, 100 etc.). I want them to be numbered like (1, 2, 3, 4). Please tell me how to do it. I would also like to point that I am aware of possible consequences of the operation, but I just want to tidy up the table. ...

TV Guide PHP script / Database structure

Hello, I was looking for PHP TV guide scripts with it's Database structure. Or at least the Database Structure by itself. Any help or infomration would be really appreciated, I just don't want to start from scratch. Thank you, ...

Zend/PHP: Problem uploading/downloading file to/from MySQL's BLOB field.

I am uploading file(pdf for now) like this: (It is uploading content of file in blob field of mysql) $organizationModel = new Model_Organization_Object( organizationId ); $myFile = file_get_contents( '../path/to/my/file/filename.ext' ); $organizationModel->setOrganizationProfile( $myFile ); $organizationModel->save(); Now I want to ge...

MySQL Query WHERE Including CASE or IF?

Strange problem. My Query looks like SELECT DISTINCT ID, `etcetc`, `if/elses over muliple joined tables` FROM table1 AS `t1` # some joins, eventually unrelated in that context WHERE # some standard where statements, they work/ CASE WHEN `t1`.`field` = "foo" THEN (`t1`.`anOtherField` != 123 AND `t1`.`anOtherField` != 456 A...

Get nested/hierarchical JSON from MySQL/PHP

I am using spacetree chart and I require JSON in hierarchical format. See sample required JSON format here. I have ID,ParentID,Name,Description fields in Mysql database table. Now How can I convert data in Hierarchical/nested JSON using PHP? I know json_encode($array). But, I require nested/Hierarchical php array for this. Let me know t...

How to find root cause for "too many connections" error in MySQL/PHP

I'm running a web service which runs algorithms that serve millions of calls daily and run some background processing as well. Every now and than I see "Too many connections" error in attempts to connect to the MySQL box" for a few seconds. However this is not necessarily attributed to high traffic times or anything I can put my finger o...

example of discount coupon generation and redemption in php

can someone please give me an example on the internet of how the system of discount coupon generation and redemption is implemented for a website where a purchase is made. Programming based on php. Any help appreciated. Regards SK ...

What are maintenance steps and performance steps for Mysql server/database ?

Like index maintenance we have index reorganize/rebuild, update stats, shrink database log files , database backup/restore in MS SQL server, What are maintenance steps and performance steps for Mysql server/database ? ...

Tuning MySQL to take advantage of a 4GB VPS

Hello, We're running a large site at the moment which has a dedicated VPS for it's database server which is running MySQL and nothing else. At the moment all four CPU cores are running at close to 100% all of the time but the memory usage sticks at around 268MB out of an available 4096MB. I'm wondering what we can do to better utilise t...

Finding date between start date and end date

Hi, I want to check whether a date is between start date and end date. i have added a where clause where datepaid between '2010-04-01' AND '2010-04-15' but the problem is that it excludes '2010-04-15'. It should include end date also how can i do this? Please help me on this Regards, pankaj ...

Mysql Joins - How to know which row is retrieved from which table...?

Hi everyone... Consider i am using join on three tables to get a desired result-set... Now in that result set, is there anyway that i can find out which row comes from which table...? Update : I see that i have phrased the question rather wrongly.... As pointed in one of the answers below, a result-set returned by join may will c...

Assigning Object to View, big MySQL resultset.

Hello (Sorry for my bad English) Is it bad practice to assign object to view and call its methods in there? I use smarty as my template engine. In my controller I could do like this 1# $this->view->assign("name", $this->model->getName); and in my view <p>{$name}</p> OR 2# $this->view->assign("Object", $this->model); and in m...

php function last_insert_id() is not working with REPLACE INTO query

I am using REPLACE INTO query to insert in to table but after executing query by using mysql_query() function and if I use last_insert_id() it is only giving me 0 value. why this is happening so? and how can I overcome this behavior. :Pankaj ...

How do I sort a varchar column using numeric ordering

I have the field receiptno, which is a varchar holding a numeric value, and want to sort this. Sorting as a string gives me the wrong ordering. I'd like to try sorting it as an integer. Is there anyway to converting to integer in the order by clause so I can sort by integer in the query itself. ...

selectLimit in JQgrid

Hallo, I have a problem. I'am trying to get some data from my database. But with a limit. So i use the selectLimit command. But when i load the grid my firebug gives the following error: "parsererror"?e:null},parse:function(d...d(a.fn.jqGrid,d);this.no_legacy_api|| When I go to the selectLimit in the jqgrid.php and print out what the ...

IE8 and below <input type="image"> value work around

Hi guys, I have a slight problem, I am trying to capture the input of two buttons, one yes, one no, into a database but for some reason the database doesn't always show the value of the button clicked, it just shows up blank. <form action="refer.php" method="post" id="formID" > <div class="prompt_container" style="float: left;"> ...

SQL RENAME TABLE command

Hello. I can run RENAME TABLE student TO student_new ; The command is same and easy to follow. Is there a methods to rename a lot of tables in simple command. Assume all the tables belog to the same DB name. I don't need write a lot of code as below? RENAME TABLE pre_access TO pre_new_access; RENAME TABLE pre_activities TO pre_new_ac...

Referencing outer query's tables in a subquery

Is it possible to reference an outer query in a subquery with MySQL? I know there are some cases where this is possible: SELECT * FROM table t1 WHERE t1.date = ( SELECT MAX(date) FROM table t2 WHERE t2.id = t1.id ); But I'm wondering if something like this could work: SELECT u.username, c._postCount FROM User u INNER JOIN...