mysql

How to get the First and Last Record of DB

How can I retrieve the first and last record from a table. Note : I am not going do to order by ...

Problem in SQL query from PHP

I have a table qotwVote1a with fields QuestionId, MemberId, Vote1a where QuestionId and MemberId are the primary key. I want to run a query to find that a member, has voted for a question or not. If not, I set the variable $j to 0, if yes I set it to 1. I wrote this query. But it is giving me an error. Can someone have a look at it? A...

Numbers and calculations in php/sql

ok im new on the scene with php and sql, i read the basics and was able to produce a DB driven shoutbox. This is my website http://www.teamdelta.byethost12.com/ What i want to do next im not sure what i should be using java? php? sql? i have no idea... but i assume php and sql if sql can do what i think it can.. What i want to do next i...

Grouping problem

When you use Group By how do you keep the other fields in sync when using aggregates Here I am trying to find the min value of col4 when col2 = xxx select col1, col2, col3, min(col4) from table where col2 = 'xxx' group by col3 I can get the minimum value in col4 but col1 is not correct but col2, col3, col4 are. Can anyone show me ho...

Referencing a MySQL sub-select in another query

I have a basic MySQL table, terms, comprised of an id and term field. I want to create an alphabetically sorted dictionary index (in the literal sense), that would list ten 10 terms above the selected term, and 20 below it. An example of this could be found here http://www.urbandictionary.com/define.php?term=GD2&defid=3561357 where ...

Unable to connect mysql from Sequel gem

When i try to connect to mysql from sequel. I am getting below errors? can you help me? require 'rubygems' require 'sequel' DB = Sequel.connect(:adapter => 'mysql', :user => 'root', :host => 'localhost', :database => 'scanty',:password=>'xx') DB.tables Sequel::DatabaseConnectionError: NameError uninitialized ...

Good DB requirements

Hey everyone I am currently doing a research project, and I was given with about 400G of data. They are all pairs, and currently I am using mysql's load data into my db. I have looked into quite a lot of options into mysql's optimization for insertion, but it's taking far too long to complete (estimation is 118 days). And then I looke...

MySQL random rows sorted by a column name

Original Question: I am currently using Zend Framework with Zend_Db_*, and I am selecting three random rows from a table: $category->getTable()->select()->order(new Zend_Db_Expr('RAND()'))->limit('3') Where $category is a Zend_Db_Table_Row. I would like to grab three random rows, but have those three rows ordered by the column named ...

Mail to MySQL Database

I want to send data to an emailaddress and save it into a MySQL database (PHP). What is the easiest way to do this? (no form post, no curl etc., just email) ...

MYSQL - one column per piece of data or combine into one column

I'm creating a blog, and am storing user permissions (to post/edit/delete blog posts) in a mysql table. Should I create one column per permission, or combine all percussions into a string in one column such as 101 would mean that a user could post and delete but not edit. The reason I ask is that I am worried about having too many colu...

Is this PHP/MySQL statement vulnerable to SQL injection?

Should be a simple question, I'm just not familiar with PHP syntax and I am wondering if the following code is safe from SQL injection attacks?: private function _getAllIngredients($animal = null, $type = null) { $ingredients = null; if($animal != null && $type != null) { $query = 'SELECT id, name, brief_description, des...

Trouble storing more than 64000 in mysql mediumtext column

I am having difficulty storing more than 64000 in a column defined as mediumtext within mysql. I ran into this limitation with the text datatype earlier and decided to drop the column and recreate it as a mediumtext field. Trouble is, my data is getting truncated at 64000 bytes. I did double check that the field is now a medium text...

Making a video sharing site, need a videoplayer

I want a videoplayer like youtube's on my site. What should I look for? I'm making a videosharing site in PHP with MySQL. Should I look into flash? Maybe you know some good video players that are easy to implement on a site. // Mariusz ...

To read SO's data dump effectively

I use currently Vim to read SO's data dump. However, my Macbook slows down when I roll down just a few rows. This suggests me that there must be more efficient ways to read the data. I know little MySQL. The files are in .xml -format. It is rather hard to read the data at the moment in .xml. It may be more efficient to convert the xml -...

Indexing calculated field for search conditions in Thinking Sphinx

I have a products model set up that I am trying to search with Thinking Sphinx. The model has an attribute called status which can be Active, Not active or Active during specified dates. I would like to be able to restrict my search results to products that are active. I.e. has status of active or has status of active during dates and ...

Deploy standalone PHP/MySQL applications

I have been looking for a solution that would allow me to deploy PHP applications on Macs and Windows. I've been developing online applications but would like them to be offline applications as well but that would require that Apache/PHP/MySQL be installed on their platforms as well. I've set up WAMP and it was NOT that easy. Lots of con...

select 10 rows per day with order

hi i have a db with records with date (timestamp) i need to select 10 records for each day (there are many more per day) and order them by few columns... how should that query look like? ...

Storing an array in a string (Database experts question)

I have a product table with 100000 products and also I have a user table with 5000 records. and suppose a user can give us feedback about any combination of this products. So suppose he chooses to compare products 1,3,100,200,400,500 and so on. (he can send us another feedback about some other products) So here is my question, I just wa...

Google Maps - server side clustering is still quite slow - do I use mapplets?

Hi guys, I'm still working on my google maps application. However clustering on the server end works but at the same time its quite slow and at times if I'm zooming out too much and playing around with the panning my browser stalls. There is only so much that I can choose to hide using clusters. EDIT I'm thinking of using mapplets in...

Avoiding using the same subquery multiple times in a query

In an MMORPG server I am refactoring, I have two tables. One for items, and one for spells. Each item has up to 5 spells, so I went with a sparse-matrix format, having 5 columns for spell IDs. The original devisers of this structure chose to use MyISAM which does not support referencing, causing the items table to contain items with non...