mysql

MySQL Query to calculate the Previous Month

Hello I would like to calculate my total order amount in the previous month. I got the query for getting the data for the present month from the current date. SELECT SUM(goods_total) AS Total_Amount FROM orders WHERE order_placed_date >= date_sub(current_date, INTERVAL 1 MONTH); Now how can I get Previous Months Data only, excludin...

No delete database table

I need to create an article system where no articles are ever deleted. Even more, they want all article edits, once the original is saved, to create new articles rather than overwrite the old ones. So, person A writes article 1 and saves it. Person B edits article 1. What is the best way to organize this database? My thoughts are: ...

MediaWiki: how to get the last N edited articles by a user?

Using PHP and MySQL, I am integrating a site with a wiki based on MediaWiki, so that profiles of users in the site have some stats about their contributions in the wiki. I want to show the last 3 edited articles of a user in a namespace (the main one, id 0), without repeating, and the links to them. In order to do that, I do more or l...

MySQL Query to calculate Previous Week

Hello I would like to calculate my total order amount in the previous week. I got the query for getting the data for the last 7 days from the current date. SELECT SUM(goods_total) AS Total_Amount FROM orders WHERE order_placed_date >= date_sub(current_date, INTERVAL 7 day); Now how can I get Previous week data only, excluding this ...

How can I get the last ten rows in a Mysql database table ?

hi I use this $query = "SELECT * FROM info ORDER BY id DESC limit 10"; $result = @mysql_query( $query ); $row = mysql_fetch_array($result); print_r($row); but it gets just the last row ...

Question on a variable passed to query.

function add_new($father = 0 , $chName, $desc , $icon ) // add new category { $position = $this->get_position($father); $sql = "INSERT into ".$this->table_name."(position,c_name,c_desc,c_icon,c_group) VALUES('','".$chName."','".$desc."','".$icon."','".$this->Group."')"; mysql_query($sql) or die(trigger_error("<br><storng><u>MySQ...

mysql_insert_id help

$position .= mysql_insert_id(); $sql = "UPDATE ".$this->table_name." SET position = '".$position."' WHERE id = '".mysql_insert_id()."'"; When i return $position i get two values 150 and 151. That is current row ID and previous or selected row ID. I just need the previous ROW ID.When i look into my DB i have two values 150151...

How to find the small and big id in mysql

Here the Situation . I am having 2 million records in table . Just consider the contacts tables has id filed. and id has different number . But now i want to find the smallest and largest id from contacts table . ...

MySQL set current date in a DATETIME field on insert

I have a 'created_date' DATETIME field which I would like to be populated with the current date upon insert. What syntax should I use for the trigger for this? This is what I have so far but it is incorrect. CREATE TRIGGER set_created_date BEFORE INSERT ON product FOR EACH ROW BEGIN SET NEW.created_date = now(); ...

MySQL T4 Templates Error: Metadata file 'MySql.Data' could not be found

D:\Web\CityV2\App_Code\ActiveRecord.tt(0,0) : error CS0006: Compiling transformation: Metadata file 'MySql.Data' could not be found Let me start by saying I'm using VWD 2008 Express. These are the steps I've taken so far: Created an entirely new project Added references for Subsonic.Core.dll and MySql.Data.dll Copied Active Record te...

MySQL: Passing procedure params to EXECUTE USING statement

This is MySQL 5.1. (Note: I realize there are better ways of doing this particular example, this is not my real code) Here is what I want to do: The below procedure gets created, but when I CALL it, I get "ERROR 1210 (HY000): Incorrect arguments to EXECUTE" DELIMITER // CREATE PROCEDURE get_users_by_state(IN state CHAR(2)) READS S...

Encoding JSON for jQuery Calendar

Hi, I'm trying to use the PHP json_encode function to encode some JSON to send along to a jQuery plugin that will render out a calendar. The plugin's name is FullCalendar. I've started on grabbing event data from a MySQL database and encoding it in a JSON string, but I've run into a problem. The default JSON example that comes with the...

Best practise to reset a database index once a year?

Using php and mysql (and Drupal), I want to generate an index based on the number of items in the database by year - 20090001, 20090002, 20090003, etc. Is there a way to do this without testing if the year has changed for each and every item - a cron job perhaps? ...

MySQL to XML

I want to convert my entire MySQL Table into XML... Can anyone Help me out with a tutorial or code. ...

Upper Limit for Number of Rows In Open Source Databases?

I have a project in which I'm doing data mining a large database. I currently store all of the data in text files, I'm trying to understand the costs and benefits of storing the data relational database instead. The points look like this: CREATE TABLE data ( source1 CHAR(5), source2 CHAR(5), idx11 INT, idx12 INT, ...

MYSQL MAX and Min query

Hi could someone help me with this problem for my college assignment cars Make MadeIn Sales GM 2005 100 GM 2006 1200 GM 2007 600 What I have to do is work out the greatest increase in Sales between 2005 and 2007 and display this value and the Make I think I have the answer to the inc...

MySQL/PHP Algorithm for Weekday/Weekend count (per month)

Hey everyone, Before I start coding, I want to come up with a good design first. Basically, I have a database table filled with dates, and users who are associated with those dates (the dates are in sql format). Using PHP I want to, for each user, calculate (count in total) how many weekdays they are associated with, as well as how ma...

Can I get feedback on this PHP function that tests if a user has signed up?

I'm just getting started on writing functions instead of writing everything inline. Is this how a reusable function is typically written? function test_user($user) { $conn = get_db_conn(); $res = mysql_query("SELECT * FROM users WHERE uid = $user"); $row = mysql_fetch_assoc($res); if (count($row) == 1) { return true; } else { return...

php: sessions vs. database

I have a class that retrieves its memeber (more or less 10 members) from a database. My question is: is it more efficient to fetch them every time from the db (MySQL), leaving just an ID in the session's array or store them directly in the session's array? And is the difference in performance terms so great? (given a database with say ...

How long do prepared queries "last" for on the server side?

I was just wondering how prepared queries work. I am using PHP and MySQL. I know that prepared queries compile the query and then repeated uses only have to change the parameters, so it saves time. But how long does that compiled query have an effect? At which point does it have to be reevaluated? Is it just as long as the PHP script is...