mysql

Get query back from PDO prepared statement

Is there a way to retrieve the query that was used to generate a PDO Prepared statement object? ...

Mysql optimization, muliple select to single select

hi, I have table where I need to select MAX(SUM(total)) of a periods total. SELECT SUM(P.amount) as total FROM bank P WHERE P.ReceivedDate >= '2008-07-28' AND P.ReceivedDate <= '2008-08-31'; SELECT SUM(P.amount) as total FROM bank P WHERE P.ReceivedDate >= '2008-09-01' AND P.ReceivedDate <= '2008-09-28'; SELECT SUM(P.amount) as total...

PHP and MySQL Project Pay

Someone asked me to design a database and implement it using MySQL. Additionally, I am also asked to write PHP scripts so that one can do some "simple" data analysis with the data inside MySQL. It is not very complicated. It is like a school database and I will have to write programs that will retrieve all the classes that a student has ...

Export mysql dump file, such that statments are in the order of dependency

I need to create a dump file such that when i execute it, i have no depency issues tables run before queries parent tables before child tables etc no failed insert due to foreign key failures ...

mySQL help in codeigniter

Hello, I am running a query to populate a dropdown menu, however the column I am using a list of company names, this means that the company name is often repeated, is there way to only get each repeated value only once? So for instance if I have in the table something like, Company 1 Company 1 Company 2 Company 3 Company 4 Company 4 ...

Data truncated for column 'xxxx' at row 1

hi I have just moved a php site to a new server. One of my queries is failing with Data truncated for column 'xxx' ar row 1 message. I checked that this field is float (10,6) type. And the values I provided white updating are not of exactly float(10,6) format and they vary .. like sometimes I put 0 only, or 54.56666 only .. so any idea ...

Php / Ajax / Jquery data submission approach

I have a table/grid system with a 7 days along the top and the various types of data down the side, now for each type of data against a particular day there's a plus and minus sign so the user can increase or decrease the data occurrences. Now given that there's plenty of data types as well as 7 (for each day) values for each type, what'...

PHP Regex - text into link

What I'm trying to do is, replacing symbols that would be changed start the string then the last symbol that would close the string - changing both of them into a link then it will be stored into the database, it's something like Wikipedia. I want to have something like this when someone types in the textarea: "This woman was killed by...

Updating fIle path in MySQL through PHP does not work

I am storing network share paths in my table in MySQL. but some entries got corrupted, i.e they dont have any backslashes in between. Path is like a big word. I wrote a small script in PHP to update these paths to try and add slashes. It does not give me any error when I run it but the results are not getting updated in the table. Curr...

Storing global site preferences [PHP/MySQL]

Can anyone recommend the best practice for storing general site preferences? For example, the default page title if the script doesn't set one, or the number of featured items to display in a content box, or a list of thumbnail sizes that the system should make when a picture is uploaded. Centralizing these values has the obvious benefit...

Variable within function accessible to outside world.

I'd like to have access to $lastID when calling raw Is there a way to do this? public static $lastID; public function raw($sql){ if(!$result = mysql_query($sql)){ throw new Exception("Could not perform query: " .mysql_error()); } self::$lastID = mysql_insert_id(); return($result); } Edit: it is a class mem...

something similar to MAX in a mysql sql where clause

I'm trying to write a sql function to do something like: SELECT person.id, person.phonenumber FROM person INNER JOIN activity ON person.id = activity.personid WHERE MAX(activity.activitydate) < DATE_SUB(CURDATE(), INTERAVAL 180 DAY); Each time a person is contacted, we create an activity record for them with notes and...

Why does MySQL ENCRYPT() give the same value?

Part of the code I'm using is: $password = MD5($password); $account_created = date("Y-m-d H-i-s"); db_insert("users","user_id,username,password,account_created,registration_ip","ENCRYPT('$_POST[username] $account_created'),'$_POST[username]',MD5('$_POST[password]'),'$account_created','$_SERVER[REMOTE_ADDR]'"); ...

Loop through $_POST

Hello! I have a for loop which actually displays a product name and several buttons like: Edit, Update , Cancel For each product i am displaying , it will have its own set of Edir, Update, and Cancel button as below. Paint Edit Update Cancel I want to loop through the buttons so that for each category, I can perform a d...

mysql create view only if it doesn't already exist

How do I create a view only if it doesn't exist. If it does exist, I want to drop the view and redefine it. I also want no warnings or errors. ...

Order resultset based on WHERE IN clause data

Considering this MySQL query: SELECT someColumns FROM someTable WHERE someColumn IN ( value1, value2, value3 ) ... how can I guarantee that the rowset comes out ordered in the exact order of the values given to the IN () clause? I presume this is not guaranteed without giving it an ORDER BY clause, is it? PS.: The values to the...

Alternative MySQL fulltext search syntax

If you want the relevance and also the results to be sorted by relevance the common format of a FULLTEXT query is: SELECT name, MATCH(name) AGAINST('Bob') AS relevance FROM users WHERE MATCH(name) AGAINST('Bob') As a developer I always like to make my code DRY(don't repeat yourself). Is there any reason not to write the query as: SEL...

Mysql Count(*) as Total WHERE Total ??

SELECT Id, QId, UName, Ans, Date, COUNT(*) * 10 as Total FROM question WHERE COUNT(*) DESC GROUP BY UName doesn't work :( ...

how to create an ajax pop pulling a data from db ?

Hi, can someone tell me how to create a nice small tooltip like ajax pop-up ? the situation is like this, I am pulling the $row->title from the db, and then I presented it as a link like this <?php foreach($task->result() as $row): ?> <tr> <td><a href=#><?php echo $row->title; ?></a></td> </tr> <?php endforeach; ?> wh...

mysql SELECT NOT IN () -- disjoint set?

Hello, I'm having a problem getting a query to work, which I think should work. It's in the form SELECT DISTINCT a, b, c FROM t1 WHERE NOT IN ( SELECT DISTINCT a,b,c FROM t2 ) AS alias But mysql chokes where "IN (" starts. Does mysql support this syntax? If not, how can I go about getting these results? I want to find distinct tuples ...