mysql

Can someone show me how I can let a member add their own tags to a question using PHP?

What I mean is that I want logged in members to add their own tags to any given question they see fit. So far, I have got the following script that calls the tags entered into the database which is below. <?php function tag_info() { $result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC"); while($row = mysql_fet...

Mysql joining tables question

I have a tables rooms, apartments and hotel. Now its easy for me to get all free rooms, name of hotel address or same thing for apartments by using separate queries ex : Get all free rooms : SELECT hotel.name, count(*) AS num_of_free_rooms FROM hotel, rooms WHERE rooms.occupied !=0 AND hotel.hotel_id = rooms.room_hotel GROUP BY hotel...

Need a php and mysql tutorial that shows you how to upload info to a databse?

Can anyone show me or point me to a tutorial that shows me how to upload info like an article to a mysql database using php. ...

mysql error when comparing date (php)

I am not sure why this i get this mysql error. Originally i didnt have '' around the date. Then i tried ''' and '`' without any luck. Whats wrong? SELECT COUNT(user) WHERE user=1 AND pass_time<'2009-09-21 13:44:38'; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right synta...

Retrieve rows grouped by hour with MySQL

I have a table containing access logs. I want to know how many accesses to resource_id '123' occured in each hour in a 24 hour day. My first thought for retrieving this info is just looping through each hour and querying the table in each loop with something like... and time like '$hour:%', given that the time field holds data in the f...

Connection Pool Strategy: Good, Bad or Ugly?

I'm in charge of developing and maintaining a group of Web Applications that are centered around similar data. The architecture I decided on at the time was that each application would have their own database and web-root application. Each application maintains a connection pool to its own database and a central database for shared data ...

Counting the same word that a user enters from a form with Mysql and PHP?

I was wondering if some one enters a word into a database from a php form how can you count how many people have entered that same word in the database as well as how not to create a whole unique id for that same word just a count for that same word when the user enters the same word. ...

Adding time in PHP

I am pulling a datetime from a mysql db and i would like to add X hours to it then compare it to the current time. So far i got $dateNow = strtotime(date('Y-m-d H:i:s')); $dbTime = strtotime($row[0]); then i tried $dbTime + strtotime("4 hours"); but 4 hours seem to add 4hrs to the current time instead of raw 4hours. How do i add X ho...

How access data between databases in mysql?

Hi, I'm working in a project that is divided into multiple modules. Each module have it's own independent database in mysql, but now, the modules need to obtain data between them. For example we're going to develop a new "admin" module, and every other modules need to access the data in the "admin" database. I know that I can make a quer...

Mysql and PHP Problem?

It seems there is a parse error with my mysql and php code can some please help me clean up this code. $tag = mysql_real_escape_string($_POST['tag']); $query = 'UPDATE tags SET count = count+1 WHERE tag = '.$tag; mysql_query($query,$dbc); if( !mysql_affected_rows() ) { $query = 'INSERT INTO tags (tag,count) V...

Auto add to database on last day of month

I have a database which stores the work my staff do. One particular query I run tells me how much money I owe them for the current month (month to date), based on the hours that I have recorded for them. However, I would like to store this information into a table itself, for various reasons, not least to record whether I have actually...

PHP PDO prepared statements

I was told today that I should really be using PDO and prepared statements in my application. Whilst I understand the benefits, I am struggling to understand how I implement them into my workflow. Aside from the fact that it makes code much cleaner, should I have a specific database class which houses all my prepared statements or should...

Correct Date and Time Columns in MySQL

I have a timezone mismatch I need to correct in a table. All dates and times before unix timestamp 1253568477 need to have 5 hours added to their values to make them equal GMT. I have the following columns... date (data type date), off by -5 hours time (data type time), off by -5 hours timestamp (data type int), this column is the co...

PHP form won't update my MySQL database.

Can someone please help me fix this code I f***ed up it wont update my database anymore. DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', ''); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'tags'); if ($dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) { if (!mysql_select_db (DB_NAME)) { ...

(Bitwise) Supersets and Subsets in MySQL

Are the following queries effective in MySQL: SELECT * FROM table WHERE field & number = number; # to find values with superset of number's bits SELECT * FROM table WHERE field | number = number; # to find values with subset of number's bits ...if an index for the field has been created? If not, is there a way to make it run faste...

Truncating MEMORY table, and locking

I use a 1 column memory table to keep track of views on various items in my DB. Each view = INSERT query into the memory table. Every 10 mins, I wanna count() the rows for each item, and commit changes to DB. The question is.... if I run the query that will get the list of all items, such as SELECT COUNT(*) AS period_views, `item_id` F...

What is the most efficient way to write query to get latest item from collection?

Hi, Sorry about the title. That was the best I could come up with. Anyways, here is my question - I have 2 tables, a Customer table and Order table as shown below: Customer { Long id; String name; String address; Timestamp createdOn; } Order { Long id; String productName; Long customerId; Timestamp createdOn; } Ther...

MySQL Creating tables with Foreign Keys giving errno: 150

I am trying to create a table in MySQL with two foreign keys, which reference the primary keys in 2 other tables, but I am getting an errno: 150 error and it will not create the table. Here is the SQL for all 3 tables: CREATE TABLE role_groups ( `role_group_id` int(11) NOT NULL `AUTO_INCREMENT`, `name` varchar(20), `description` ...

Java: How to convert MySQL DECIMAL(39,0) IP address to String

So I'm told that the DBAs here are going to be storing IP addresses in a DECIMAL(39,0) field in our MySQL database. How can I go about translating that into a String to pass on to our other applications? Note: Our databases can't take any more load, so as much of the work as possible needs to be done in the Java application. Note2: IP...

Help in a Join query

SELECT game_ratingstblx245v.game_id,avg( game_ratingstblx245v.rating ) as avg_rating, count(DISTINCT game_ratingstblx245v.userid) as count, game_data.name, game_data.id , avg(game_ratings.critic_rating),count(DISTINCT game_ratings.critic) as cr_count FROM game_data LEFT JOIN gam...