mysql

How can i get in between rows in mysql query.

I want to fetch intermediate rows from by database. Like for last 10 rows i will use limit : return Doctrine_Query::create() ->select('v.*') ->from('Video v') ->where("v.community_id='$community_id' AND v.user_id='$user_id' AND v.published='$published'") ...

SQL help query not returning all data,

I am building a website that remembers the users choices from a navigation menu and then shows content the next time they visit the webiste there last view content is available, to this I am running this query SELECT * FROM (`categoryTable`) LEFT JOIN `userMenuTable` ON `userMenuTable`.`categoryId` = `categoryTable`.`categ...

MySQL database setup help

I am making a classifieds website... I have these 6 tables: Every category has sub-categories (or options) which you can see below. Lets say the user wants to post a classified, and has entered all info into the forms necessary, and I am at the stage where I have to create the PHP code to actually INSERT the data into the database. I a...

Foreign key constraint (complex?)

I have a table that manages virtual download folders for a site. CREATE TABLE `folder` ( # id = PK `id` int(10) unsigned NOT NULL auto_increment, # folderId = self referencing FK to id `folderId` int(10) unsigned default NULL, # siteId = FK to id in site table `siteId` int(10) unsigned NOT NULL ) Ideally I like siteId to r...

Is this possible to join tables in doctrine ORM without using relations?

Suppose there are two tables. Table X-- Columns: id x_value Table Y-- Columns: id x_id y_value Now I dont want to define relationship in doctrine classes and i want to retrieve some records using these two tables using a query like this: Select x_value from x, y where y.id="variable_z" and x.id=y.x_id; ...

Inserting and retrieving id before form is submitted

Here is what i'm trying to do: I have a form with few text fields and image upload via JavaScript(to have that loading animation). here is the link http://netfecs.com/inprogress/phat_cat/admin_edit_car.php?id=4 I'm using row id as part of the image name in the database. What is a good way to set the id and retrieve if before submitti...

SQL join help for friend list

I have three database tables: users, user_profiles and friends: users id username password user_profiles id user_id full_name friends id usera_id userb_id What would be a query which finds the friends list of any user and also joins the table users and user_profiles to get the profile and user information of that friend? ...

Safely using prepared statements to query database

I'm trying to write a function that is versatile in the queries it is allowed to make, but also safe from injection. The code below throws an error as is, but if I run it with 'name' instead of ':field' it works fine. $field = "name"; $value = "joe"; function selectquery($field, $value) { global $dbcon; $select = $dbcon->prepare...

SQL clause to optimize UPDATE queries?

In my fictional database, I have several columns of data. In designing a PHP front-end to the script, it was necessary to allow the user to modify all attributes of a tuple if necessary. If the end-user only ends up modifying one attribute instead of all of them, the following statement: UPDATE foo SET name='bar' location='YYZ' dri...

How do I build a on-the-fly search engine? (with ranking/relevancy)

I was a heavy user in Sphinx and Lucene. Sphinx just takes a database, indexes it. And you call Sphinx to get the ID's. But what if I want to create a search engine that's very tiny. Just a few rows of data and a few paragraphs of words? The trick is, the rows of data is constantly changing. So, I can't have an "index". I want to be ...

How to design a static/dynamic survey application?

I'm struggling here a lot really. I need to prepare a form that is something between static and dynamic. Basically on the first part of the survey you get a question asking you to select items from the checklist. You select the items and then you are presented with a list of n number of questions. Now, some facts: the questions and p...

Advanced many2many query for MYSQL

I im trying to build a imagegallery where people have access to different groups and the groups decide what catalogues and images they are allowed to see. I though many2many structure would be best for this. So far, ive manage to build the database like this: image (image_name, image_file, image_id) catalog (catalog_id, catalog_nam...

Show which columns an index is on in PostgreSQL

I would like to get the columns that an index is on in PostgreSQL. In MySQL you can use SHOW INDEXES FOR table and look at the Column_name column. mysql> show indexes from foos; +-------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Tabl...

mysql_query returns false after successfully executing query in PHP

I have a strange bug where I call an insert query, it executes successfully (the row appears in the DB) but mysql_query returns false. It only returns false when a particular field contains an underscore or dash (or probably some other chars but these are the two I've run into so far). "INSERT INTO Hoopoes (name, owner, dbuser, dbpass,...

How do I store XML data into a mysql database? I don't want foreign keys like crazy.

If my XML data is very complex, is there a way I can store this in DB? ...

Efficient db design for retrieving 'most popular' table rows

I am planning to create a mysql 5 (myISAM) table that will contain x thousand rows of data. Each row will have a count field, & the rows with the 20 highest count values will be retrieved quite a lot, probably on a one-for-one ratio to every row update. The x thousand rows not in this 20 will not typically be retrieved. What are the c...

MySQL database collation and character set.

I have a mySQL database that has collation and character sets as follows: mysql> show variables like "character_set_database"; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | character_set_database | utf8 | +------------------------+-------+ 1 row in set (0.00 sec) mysql> show...

MySQL Zend Framework - SQLSTATE[42000]: Syntax error or access violation: 1064

I've read every response I could fine on SO before posting this question. Although similar, none addressed my particular problem (or I didn't recognize them doing so). I have a table class that extends Zend_Db_Table_Abstract. In the model, I'm trying to return a single row using a join() method and based on the table ID like this: ...

Incrementing Slower Data Insertion into mySQL

Hi there, Background: We have large flat files span around 60GB and are inserting into database. We are experiencing incremental performance downgrade during insertion. We have 174 (million) records and expecting another 50 (million) to be inserted We have splitted main table into 1000+ tables on the basis of first-two-characters of ...

Is it bad to rely on foreign key cascading?

The lead developer on a project I'm involved in says it's bad practice to rely on cascades to delete related rows. I don't see how this is bad, but I would like to know your thoughts on if/why it is. ...