mysql

Deleting rows from other tables if row is deleted from main table

I have a table called 'pages'. Each page has a content type of either text, video or image. Depending on what the content type is a record is also inserted into either text, video or image table. When I delete a row from 'pages' how can I ensure the rows from the other table is removed? I understand a little about CASCADE but I am not u...

MySQL JOIN & Split String

I want to JOIN two table. Have no problem with that. I have problem with quite different thing. Here's my code: SELECT * FROM `table1` JOIN `table2` ON `table1.`field`=`table2`.`field` ... The main issue is that table1.field is a string, comma-separated. Is there any good and fast way to split it? Update I found a function by Federi...

Pros / Cons of MySql JOINS

This is a question that has bugged more for a few weeks now and I haven't got around to asking it to you guys. When I'm selecting data from multiple tables I used to use JOINS a lot and recently I started to use another way but I'm unsure of the impact in the long run. Examples: SELECT * FROM table_1 LEFT JOIN table_2 ON (table_1.colu...

Seats Bus Booking PHP and MySQL

I have another case. I got the bus with 27 seats then, if people pick the seat 4, so nobody can take that seat 4. my question: how design database contain 27 seats? I guess using looping until 27 with PHP how to show in form, selection form contain the un-booked seat? how to prevent if other people take same seat? thanks. ...

Updating AUTO_INCREMENT value of all tables in a MySQL database

Hello, It is possbile set/reset the AUTO_INCREMENT value of a MySQL table via ALTER TABLE some_table AUTO_INCREMENT = 1000 However I need to set the AUTO_INCREMENTupon its existing value (to fix M-M replication), something like: ALTER TABLE some_table SET AUTO_INCREMENT = AUTO_INCREMENT + 1 which is not working Well actually, I woul...

PHP5 and mysql examples

is there any website which has given very good examples of php5 and mysql. how to use OOP for website development from small website to large. or is it good to start development in zend framework. ...

Backup MySql database with PHP

I have a pretty large db in MySql, and I need to take backups of it every day or so. I need to be able to take backups from any computer, so therefore I thought about making a php script to do this and put this php script online (offcourse with password protection and authorization etc so that only I can access it). I wonder however, h...

On a stats-system, should I save little bits of information about single visit on many tables or just one table?

Hello I've been wondering this for a while already. The title stands for my question. What do you prefer? I made a pic to make my question clearer. Why am I even thinking of this? Isn't one table the most obvious option? Well, kind of. It's the simpliest way, but let's think more practical. When there is a ton of data in one table a...

How do I restore one database from a mysqldump containing multiple databases?

I have a mysql dump with 5 databases and would like to know if there is a way to import just one of those (using mysqldump or other). Suggestions appreciated. ...

Actual size of TEXT field (MySQL)

Hello. Will a TEXT field use the same storage space in the database no matter if it is empty, got a few characters or filled to the limit? ...

PHP Array vs MYSQL Queries speed optimization

I'm trying to make my php mysql driven pages as fast as possible. I've got a fairly standard website with a left-column menu with lists of articles and recipes (loaded from the db) and then on the main content there are some randomly changing articles with clipped previews and also random recipes. What I've got at the moment is one sql ...

Debugging MySQL Insert Failure When No Error Is Returned to PHP

I'm testing some new code to insert into a MySQL database from using PHP. The test $stmt->execute(); if ($stmt->errorCode() != 0) { $arr = $stmt->ErrorInfo(); throw new Exception('SQL failure:'.$arr[0].':'.$arr[1].':'.$arr[2]); } It threw a number of errors that I fixed one by one. Finally it dropped through, but nothing was ...

MySQL: Finding multiple words in full text search - exact matches only

I'm writing some code to automatically tag some articles. I have an array of tags and a table of articles. I run the following query to check for headlines matching a tag: SELECT headline FROM `news` WHERE MATCH(headline) AGAINST ("+Green +Day" IN BOOLEAN MODE) This finds all articles with the exact phrase 'Green Day' in the hea...

Only import tables from a complete MySql database export

If I have exported a .sql file with my database in it, can I then only import "parts" of that database instead of the entire database to MySql? The question appeared when I was trying it out on a test database. I exported the testdatabase. Then emptied some of the tables in the database. Then I planned on importing from the .sql file...

Mysql query return duplicate entries with in and find_int_set

Hello, I have a mysql query that shows the users last viewed documents. Some sort of history view, and I want to show this in a history tab, but I cannot get this to work. The history is saved on another server so I'm getting a list of ID's, and I have to get the document's info from the document database. I want it to show duplicate e...

sql help getting data from all the followers ? ( like twitter if we follow )

example if i have follow table company one ( cid = 1 ) following two ( cid = 2 ) company one ( cid = 1 ) following three( cid = 3 ) feeds table company one ( cid = 1 ) type 'product' description 'hello ive updated a product'; company two ( cid = 2 ) type 'product' description 'hello ive updated a product im from company 2'; company ...

Mysql query - invalid use of group function

mysql_query(" SELECT b.id as b_id FROM banner b INNER JOIN bannerhits bl ON b.id = bl.bannerid AND bl.userid = '".$this->userid."' INNER JOIN ...

mysql many to many relationship

Been reading the tutorial How to handle a Many-to-Many relationship with PHP and MySQL . In this question I refer to the "Database schema" section which states the following rules: This new table must be constructed to allow the following: * It must have a column which links back to table 'A'. * It must have a column which links ...

Returning multiple columns from SELECT nested within CASE MySQL

Is there a better way to do this? SELECT subs. * , CASE subs.member_type WHEN 'member' THEN ( SELECT CONCAT_WS( ' ', members.first_name, members.last_name ) FROM members WHERE members.id = subs.member_id) ELSE ( SELECT members_anon.username FROM members_a...

No query error - but query doesn't return data?

SELECT b.id as b_id, b.maxhits as b_maxhits, b.maxklik as b_maxkli, b.maxviewsprday as b_maxviewsprday FROM banner b JOIN bannerhits bl ON b.id = bl.bannerid AND bl.userid = '".$this->userid."' JOIN bannerhits blog ON ...