mysql

PHP - How to get, and display the biggest values from a database?

Hello. Can anyone tell me how to get and display the biggest values from a database? I have multiple values in my database with the heading "gmd", but how would I get only the first 3 biggest ones to be displayed? How would I do it in this example: $query = "SELECT gmd FROM account"; $result = mysql_query($query); while($row = mysql_...

Select statement that combines similar rows with certain ids?

hi I have a warehouse_products table which defines how many products in the warehouses so lets say I have 20 records/rows in the table, some rows may contain the same product id but in a different warehouse I need to create select statement that give every product one row, and in this row I must have the quantity in warehouse A and wa...

Comma separated variable in MySQL

I want to create a stored procedure in MySQL and one of the input parameters will need to be a comma separated list of integers. How do I loop through each integer and run an update statement on it? I've googled it but can't seem to find anything that will work for MySQL. ...

Accessing data entered into multiple Django forms and generating them onto a new URL

I have a projects page where users can start up new projects. Each project has two forms. The two forms are: class ProjectForm(forms.Form): Title = forms.CharField(max_length=100, widget=_hfill) class SsdForm(forms.Form): Status = forms.ModelChoiceField(queryset=P.ProjectStatus.objects.all()) With their respective models as follows:...

How to delete an image using PHP & MySQL?

I was wondering if some one can give me an example on how to delete an image using PHP & MySQL? The image is stored in a folder name thumbs and another named images and the image name is stored in a mysql database. ...

cakephp COUNT items per month in a year

How do you use cakephp to count, for example the number of posts, made every month in a year? Preferably using Model->find('count') and get the data in an array. ...

Mysql stored procedure where clause

Ok let me try this again. query("CALL getemployee('$eml')"); $result = $sql->fetch_array(); ?> This is my stored procedure: Delimiter // Create procedure getemployee(in eml varchar(50)) Begin Select * from employees where email = eml; End// Delimiter ; The error i get from browser: "Fatal error: Call to a member function fetch_ar...

PHP & MySQL delete image link problem

I'm trying to create a delete image link if the image is present and when the user clicks the delete image link it should delete the image. But for some reason this is not working can someone help me fix the delete image link problem? Thanks! Here is the PHP code. if (isset($_POST['delete_image'])) { $img_dir = "../members/" . $us...

restoring with mysqldump, but where is the data?

Ok, so I'm in need to restore a table and I do: mysqldump --opt database table_name < table_name.sql I hit enter and Done! Well, not really, when I go to see if there is anything on the table it show 0 records. I have look into the table_name.sql and I see two records. What am I doing wrong? ...

Is there a way to select only integers of a field in mysql?

I want to search for numbers, but some of them have - characters or spaces inbetween them, is there a way to do like a select numbersonly(phone) from table ? Thanks. ...

MySQL performance - 100Mb ethernet vs 1Gb ethernet

Hi All I've just started a new job and noticed that the analysts computers are connected to the network at 100Mbps. The ODBC queries we run against the MySQL server can easily return 500MB+ and it seems at times when the servers are under high load the DBAs kill low priority jobs as they are taking too long to run. My question is th...

Max value amongst 4 columns in a row.

I have test_scores table with following fields: Table schema: id (number) score1 (number) score2 (number) score3 (number) score4 (number) Sample data: id score1 score2 score3 score4 1 10 05 30 50 2 05 15 10 00 3 25 10 05 15 Expected result set: id col_name col_value 1 score4 ...

Need help joining tables...

I am a MySQL newbie, so sorry if this is a dumb question.. These are my tables. student table: SID (primary) student_name advisor (foreign key to faculty.facultyID) requested_advisor (foreign key to faculty.facultyID) faculty table: facultyID (primary key) advisor_name I want to query a table that shows everything in the student tabl...

Good error flagging | PHP

For everyone that was thinking of the error_reporting() function, then it isn't, what I need is whenever a MySQL query has been done, and the statement has like if($result) { echo "Yes, it was fine... bla bla"; } else { echo "Obviously, the echo'ing will show in a white page with the text ONLY..."; } Whenever statements have b...

Optimize a MySQL count each duplicate Query

I have the following query That gets the city name, city id, the region name, and a count of duplicate names for that record: SELECT Country_CA.City AS currentCity, Country_CA.CityID, globe_region.region_name, ( SELECT count(Country_CA.City) FROM Country_CA WHERE City LIKE currentCity ) as counter FROM Country_CA LEFT JOIN glo...

Get 10 Most Entered Entries

Hi, I'm just wondering if it's possible to retrieve the the most entered entries from the mysql database It's like this : ID - Value Id is auto increment, and value is the text that is being entered, i'd like to have it display the top 10 most entered terms, how could i do that? ...

PHP & MySQL Image deletion problem?

I have this script that deletes a user's avatar image that is stored on the filesystem. In addition, the image name is stored in a MySQL database. But for some reason the script deletes all the user's info. For example if the users_id is 3, all of the user's info like first name, last name, age and so on, are deleted as well. Basically...

Query results taking too long on 200K database, speed up tips?

I have a sql statement where I'm joining about 4 tables, each with 200K rows. The query runs, but keeps freezing. When I do a join on 3 tables instead, it returns the rows (takes about 10secs). Any suggestion why? suggestions to speed up? Thanks! Code SELECT * FROM equipment, tiremap, workreference, tirework WHERE equipment.tiremap = ...

How do I impliment a hidden field in a post form so users can't accidentally double post? (PHP/Mysql)

When users submit a form, they will sometimes click refresh or backspace then resubmit which causes multiple entries in mysql. How can i prevent mysql from allowing more than 1 of the same entry? People suggested a hidden field with a value, but how do I use that? <label for="state" class="styled">State:</label> <input type="tex...

php and mysql listing databases and looping through results

Beginner help needed :) I am doign an example form a php book which lists tables in databases. I am getting an error on line 36: $db_list .= "$table_list"; <?php //connect to database $connection = mysql_connect("localhost", "admin_cantsayno", "cantsayno") or die(mysql_error()); //list databases $dbs = @mysql_list_dbs($connec...