mysql

Single query for selecting a random images from X unique parents?

I've used this query to randomly select a total of $limit-images (attachments), each from a unique and randomly selected parent. $query="SELECT {$wpdb->posts}.post_parent, {$wpdb->posts}.ID FROM {$wpdb->posts} INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.post_pare...

replace inner join with select from, perhaps?

I am trying to understand and modify an SQL query used by an input field to do a smart search. The original code is here: ((`clients` INNER JOIN `addresstorecord` ON `clients`.`uuid` = `addresstorecord`.`recordid` AND `addresstorecord`. `tabledefid`='tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083' AND addresstorecord.primary='1')...

Syntax error in automatically formed SQL query

I am trying to generate a query for use with a smart search field, ala google suggest. I can not form the query directly, although I can see what query was made via the logs. I have posted the query that gets sent, which has a syntax error but I am unsure why. SELECT DISTINCT IF(guests.passport != '', Concat(guests.passport, ...

How can i mix OR and AND in ORM queries

I am developing a site using kohana 2.3 and am having trouble with a specific ORM query. Essentially what I am doing is the following query SELECT * FROM 'records' WHERE ('ServRepSupervisor' = name AND 'Followup_read' = 0) OR ('ServRepSupervisor' = name AND `read` = 0) when I try the ORM query like this... $unread = ORM::factor...

Retrieve MySQL data with webservice to create FTP Folder and user/pass ?

Hi there, I need to create something that will retrieve new Users from a VTiger CRM and create a FTP folder and user/pass on another server. SERV-A: VTiger CRM, powered by MYSQL. With WSDL directory. SERV-B: FTP server The reason why I thought doing a WebService is that I must constantly check for new users. The language used isn'...

Blocking a submission to MySQL if conditions are met

Hello, The code below works well. It submits some variables into a MySQL database. How could I block the submission and redirect the user back to domain.com/index.php if the conditions below are met? Conditions: $uid has been used more 11 or more times in a calendar day. $cleanurl has ever been used before. Thanks in advance, J...

trouble with automatically generated sql query

I am having trouble with an automatically generated SQL query, that is based on several smaller queries stored in a table, and combined with what the user inputs. I will show the inputs for a query that works, and then the query itself. I will then show my inputs, and the query that fails. If someone could point me what input I have u...

Best way to store a many-to-many relationship in MySQL?

Let's say I have a simple database with tables 'posts' and 'tags'. Posts can have many tags and tags can belong to many posts. What is the best way to structure the database? I thought of using a list/serialize: tags idx tag_id, str tag_name posts idx post_id, str title, list tag_ids OR having another table with the associations. Pr...

Should I use PHP or Ajax for dynamically loading content into a social website profile?

Getting some data from a MySQL database and loading it into the page. None of the stuff really needs to be retrieved at any point other than page load, so that advantage of Ajax is moot. Is there any other advantage to Ajax? ...

error while trying to push database to heroku

I am trying to do a $heroku db:push this is the error I get C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/utils.rb:138:in `union': can't convert Array into String (TypeError) from C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/utils.rb:138 from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in ...

Improving table cache in mySQL

Hi, Can someone know how to improve table cache in mysql? I have optimized few tables by creating indexes. Please share your thoughts. Thanks. ...

How does MyISAM scale compared to Solr for Django searching?

Imagine you have a web application written in Django and Python 2.65, and MySQL 5.1 is your database of choice. Now, imagine you will need to scale your app to handle searching 100's of thousands of document and potentially 100's of thousands of users will be using it. Reality: Haystack 1.0 with PySolr and Solr 1.4.0 is proving slow i...

When should I NOT use mysql_real_escape_string

I saw this comment.... http://www.php.net/manual/en/function.mysql-real-escape-string.php#93005 And began to wonder why this would be a bad idea. ...

SQL SELECT criteria in another table

I have 2 related tables: messages -------- mid subject --- ----------------- 1 Hello world 2 Bye world 3 The third message 4 Last one properties ---------- pid mid name value --- --- ---------------- ----------- 1 1 read false 2 1 importance high 3 2 read false 4 2 i...

Selecting All Children From All Parents in mySQL

I have a simple table like this: +------------+---------+-----------+--------------+ | comment_id | post_id | parent_id | comment_text | +------------+---------+-----------+--------------+ | 1 | 200 | 0 | a | | 2 | 200 | 0 | b | | 3 | 200 | 1 | ...

Tracing an ajax error to a sql query

I am working within the confines of CMS software, that automatically generates a query for use in a google suggest like input field. The provided fields works fine, with the query they use which uses an inner join over two tables. I am trying to make a query which will grab information from just one table, and will returns results on e...

Case sensitive RLIKE

Consider a table datatbl like this: +----------+ | strfield | +----------+ | abcde | | fgHIJ | | KLmno | +----------+ I want to write a query something like this: select * from datatbl where strfield rlike '[a-z]*'; As in a non-SQL regex, I'd like to return the row w/ abcde, but not the rows w/ capitals. I cannot seem to f...

asp.net MVC password recovery tool not working

I am using the password recovery control in an ASP.NET MVC 2 web app. When I click the submit button without a username, it indicates the username is missing with an asterisk. If I put in an a username the form submits but nothing happens. Am I missing something here? Web.config: <system.net> <mailSettings> <smtp deliveryMetho...

What is the best way to efficiently calculate which points are close to a given lat/long using MySQL?

I'm trying to design a MySQL schema that can store a list of users with an associated latitude and longitude. I would then, for a given user, like to build a query which can return the nearest 50 users to him/her and sort those users by distance (with the nearest being presented first). Given that there may be many thousands of users ...

Need help with correct SQL

So I'm a noobie, starter, beginner - throw all of the above at me. I'm trying to create a query that will search through a database and return blah blah blah. The problem is, it isn't quite working. Here's an example query - As you can see, above other things, I am trying to return results from someone with the last name Johnson SEL...