mysql

Preventing a submission from being re-submitted upon refreshing a browser

Hello, The code below all works great. On a file called submit.php, a user can enter a submission through a form. The form goes to submit2.php, where some code inserts the submission into a MySQL database. So far so good. Here's the problem: once the user has landed on submit2.php, if the user refreshes the browser, a "Confirm Form ...

Making a new sql table, where one of the fields copy data from another table field

Hello, I have one existing table for guests, with information such as name, passport number and such. I want to make a new table for sales, and want to make it so that when a client is chosen from the existing table, certain fields are populated in the new table, such as passport number. I am doing this with php and ajax. Could someon...

How to generate lists using PHP & MySQL.

I was wondering how would go about displaying five images in a row using lists. For example, how would I generate the following XHTML code below using PHP & MySQL? Here is the XHTML code. <ul> <li><a href="#" title=""><img src="" /></a></li> <li><a href="#" title=""><img src="" /></a></li> <li><a href="#" title=""><img src=...

MySQL Logic help

I have the following query which works great. I have 2 questions.... 1) Can I remove the inner join to order on the sub query and tie it back into the main query? 2) I need to factor in returns into all of the values generated. Price per item is ONLY stored in order_product. My table structure is as follows... order id | account...

How to calulate a number in a table from a different field in the same table?

Say I have a basic table, products, with 3 fields, productname, cost, and costnotax. Is it possible to automatically fill in the costnotax field by subtracting a percentage from the cost field? ...

Mysql count number of regex match per field

I'm trying to get mysql return the number of times a regex matches. something like: select 'aabbccaa' regexp 'a' should return 4 (4 matches of a), rather than just true (or 1). any way around it??? thanks !! ...

Change the owner of a MySQL Stored Procedure?

The MySQL Manual says that I can print the code used to define a stored procedure using SHOW CREATE PROCEDURE, but apparently that only works if you a) have select permissions on the mysql.proc table, or b) own the procedure. The database in question was maintained by a co-worker who's moved on, so I should be the owner of all the stuff...

MySQL JDBC ResultSet next method returns null even though there are more results?

I have a Java application that uses a Statement to execute a query that should return about 100,000 records. I iterate over the ResultSet, calling the next method to retrieve each record. The number of records I receive varies from one execution to another. No exception is thrown, the next method simply returns null. What could explain ...

Mysql Many to Many with Count and math

I have a many to many table setup in my mysql database. Teams can be in many games and each game has 2 teams. There is a table in between them called teams_games. What I am looking to do is create stats for each team. An ideal printout would be: team_id, team_name, wins, losses, draws, error My problem is linking the math of which tea...

A quick SQL query to generate example data

I need to populate a currently empty table with a hundred or so fake records to simulate logins over the past two years to test my code with. The login table schema looks like: CREATE TABLE `Logins` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `User_ID` int(11) NOT NULL, `Date_Login` datetime NOT NULL, `Location` enum('site','admin'...

MySQL only returns { first row } from the result of query !

I've used my server for testing PHP & MySQL Applications long time ago. Suddenly, When i try to execute any query on the any table in any database, i get only the first row in the result of the query ! I checked the configuration file, and didn't see anything strange there. OS: Linux / Ubuntu 10.04 64bit Server Edition, Web Server: Ap...

Display a MYSQL field using CAKE

<div class="nhplft"> <div class="view_item_title"><i><?= $users["First_name"]["First_name"]; ?> in MANHATTAN has (an)</i> <?= $item["Item"]["item"]; ?><br /></div> that line of code is pulling the item name from the ITEMS table and the ITEM field... what can i do to display the user first_name from USERS table in the same database o...

What does the filtered column of a EXPLAIN'ed query mean in MySQL?

mysql> EXPLAIN EXTENDED SELECT * FROM table WHERE column = 1 LIMIT 10; +----+-------------+----------+------+---------------+--------------+---------+-------+--------+----------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+----------+-----...

What's the deal with the various MySQL versions?

I haven't been paying attention for a while, but I just checked and the latest release of MySQL is at 5.5. I always use what the vendor of whatever OS I'm using provides, which has been 5.0 or 5.1 for the last couple years. This page lists two community versions, 5.1 and 5.5: http://dev.mysql.com/ There is documentation for 5.0, 5.1, ...

Optimal query to fetch a cumulative sum in MySQL

What is 'correct' query to fetch a cumulative sum in MySQL? I've a table where I keep information about files, one column list contains the size of the files in bytes. (the actual files are kept on disk somewhere) I would like to get the cumulative file size like this: +------------+---------+--------+----------------+ | fileInfoId | ...

Replace all fields in MySQL

Hi, I need to replace some chars in the columns of a table, by using the REPLACE command. I know that the REPLACE command needs a column name, then the text to change (in the following example, the 'a' char) and the new text (in the following case, the 'e' char). UPDATE my_table SET my_column = REPLACE (my_column,'a','e' ); So that ...

MySQL: Two n:1 relations, but not both at once

Sorry for the title, it's difficult to explain. I need a data model similar to this: As you can see, a set can belong to both a user or a school. My problem: It should only be allowed to belong either to a user OR a school. But never both at the same time. How can I solve this problem? ...

Sorting a MySQL query with ORDER BY or with PHP sort functions

Hi all, I have a query that I want to sort alphabetically, but the trick is that I want the sorting to treat two columns equally. For instance, if the first row of first_col equals apple and the second row of second_col equals aardvark I want the value in the second row of second_col to be listed before the value in the first row of fir...

how to make a multi-lingual php site?

I am developing a site using php and mysql. I want to know... what's a good way to deal with multi-lingual support? I want a user to be able to select from a drop down and select their language. Then everything (content, buttons, links) except the user-written content is in their language. What's a good way to approach this? Use a cooki...

MYSQL data archiving

I have a table with a timestamp column that records when the record is modified. I would like to on a nightly basis move all records that are older than 6 days. should I use insert into archive_table select * from regualr_table where datediff( now(), audit_updated_date)>=6; delete from regular_table where datediff( now(), audit_upd...