mysql

Select query in MySQL

Two tables Table1 ID FileName 1 abc 2 abc 3 abc 4 xyz Table2 ID Table1_ID isDeleted 1 1 1 2 2 1 3 3 0 4 4 0 I need to get the count of filename for the isDeleted=1 by passing any ID of table1, i.e for all the values(1,2,3) of ID, i need the count as 2 I tried with the following query S...

Sorting through a Database query for all rows created in the same day Unix Timestamp in PHP

Hi, I am developing a PHP application which will handling many company articles. Now I am creating a page which should order articles BY DATE ie all articles created in a certain day are shown with the appropriate heading and so on for all the articles. I have used Unix timestamps to save the dates in the MySql db but I cant find cod...

Pattern match within the IN operator (MySQL)

I would like to match patterns inside an IN expression like this: ... WHERE ... IN ('%alma%','%sajt%') Is it possible somehow and if not, how could I achieve this some other way? ...

jQuery getJSON not working

Hi guys, I am trying to get some data back from a server using jQuery $.getJSON, and the code seems to work fine, until it gets to $.getJSON, it doesn't seem to be triggering that at all, there are no console logs when I press the button, here is the code below, $(document).ready(function(){ var funk; $('#button').live('click', func...

PHP function to escape MySQL regexp syntax

I'm looking for something similar to preg_quote, but for the MySQL regexp syntax. Any ideas? ...

logging visitors online for large traffic website.

Hi, I manage a rather large traffic website. On each page we keep track of a visitors online by running the following code. We then have a cron which deletes the records which are older than X minutes. if(!isset($_SESSION[users_online_id])) { if(!(date('H')=='02' && date("i") >= 37 && date("i") <= 45)) { # NEW VISITOR - DOESN'T HAVE...

How to get a MySQL Trigger to fire from multiple accounts

Hi folks, Here's my situation: I have a MySQL database in which I'd like to use triggers to automatically manage the updating of date creation and date modified fields in a few of my tables. Later, I'd like to expand them into logging data changes, but that's neither here nor there at the moment. The triggers work fine and update the...

combining two sql queries into one?

I have two similar queries on same table and same where condition but different selects on it. Select flatpos from archdetails where version='1.3' AND compname IN ( select distinct compname from svn3 where revno='r270294' ) AND select count(distinct compname), sum(CASE WHEN inFlat=1 THEN 1 ELSE 0 END), min(flatLoopIndex)...

Jruby Activerecord is giving me stale connections

I have a Jruby app that spins up several background Java threads that share an ActiveRecord (2.3.5) connection. If they sleep for some time and then try to do something database related, the first queries never execute. I believe this is because the connections are stale, but the code itself doesn't throw any errors. I've tried doing ...

MySQL ORDER BY [custom SET field value]

Hi there! I hop there's a simple solution for this: I have a table where each row has it's own status (SET type field). Statuses can be: offline available busy distance I'd like to order as follows available busy distance offline I thought a simple ORDER BY `status` ASC will do the trick (alphabetical order) but it gives me ...

mysql "group by" very slow query.

hi all, i have this query in a table with about 100k records, it runs quite slow (3-4s), when I take out the group it's much faster (less than 0.5s). I'm quite at loss what to do to fix this : select msg.id, msg.thread_id, msg.senderid,msg.recipientid, from_user.username as from_name, to_user.username as to_name from msgtable as msg le...

Handling DB error in PHP

Hey everyone! I'm building a webapp in PHP that uses a MySql DB. What I want to do is for example when someone tries to access to a page, but the DB throws an error, to display a HTML (or redirect) page with the HTTP code 500. Something like the "fail whale" in Twitter. Is that possible? ...

Creating carriage returns in csv cell via php

I'm trying to dynamically generate a csv file with some cells that will contain multiple lines, the address field for example will need to be grouped into a single "address" cell instead of address,city,state etc. All is going well and but for the last two days i've tried to insert \r, \r\n, \n, chr(10),chr(13), as well as a carriage ret...

ActiveRecord - pre fetch single records from association

Consider the following models.. class Product < ActiveRecord::Base has_many :pricings end class Pricing < ActiveRecord::Base belongs_to :server end Pricing is a historical tracking table for prices of products, so there may potentially be hundreds of price points captured over time. What I want to add is a way to get only the...

Recommendations for implementing custom CRM administrative system

I manage a website which houses several pieces of Seller and Buyer(member) information. In order to cut costs, we decided we wanted to launch an all-web-based CRM system which allows us to look into customer information, update that information, perhaps process payments/change payment schedules, etc. Similarly, our site houses several p...

how to increase mysql full-text accuracy?

I am running a simple mysql full-text query that searches for users on my site based off of their "display name". The query example is below - in this example we are searching 'lancaster toy store': SELECT MATCH(`display_name`) AGAINST ('lancaster toy store') as `rel` WHERE MATCH(`display_name`) AGAINST ('lancaster toy store') ORDER BY ...

XML error at ampersand (&)

I have a php file which prints an xml based on a MySql db. I get an error every time at exactly the point where there is an & sign. Here is some php: $query = mysql_query($sql); $_xmlrows = ''; while ($row = mysql_fetch_array($query)) { $_xmlrows .= xmlrowtemplate($row); } function xmlrowtemplate($dbrow){ return "<AD> ...

Unknown column in mySQL CSV import

Hey everyone. I am trying to import a small CSV file into my django program. I am using SQL, and here is what I have so far. The CSV file itself has Column1 which is named Customer and I am trying to take that information and assign it to the model field name 'client_name'. Problem I get when I run this query is that I keep getting t...

Needed to be guided trought SSH Tunnel with a delphi Application

Hi there I created a Delphi 2010 application. It is use by many company in the region from trusted to untrusted users. The application authenticate users with MySQL behind MD5 encrypted password. Following this, the application need to upload and download many files trought ftp. The fact is : any network sniffer (such as Ethereal also ...

sprintf() Versus mysql_query()

Having trouble formatting my code to execute without error using sprintf() When I run the code I get this error: Parse error: syntax error, unexpected T_VARIABLE in /location on line 16 $query = sprintf('UPDATE `%s` SET `stock` = :amount WHERE `itemname` = '$q'', $tablename); Above is line 16 in my code. I'm assuming it is syntax rel...