mysql-query

How do I echo out something different when reached last row?

I am wanting to not echo out the comma at the end of the echo after the last row. How can I do that? Here is my code: <?php header("Content-type: application/json"); echo '{"points":['; mysql_connect("localhost", "user", "password"); mysql_select_db("database"); $q = "SELECT venues.id, venues.lat, venues.lon, heat_...

MYSQL how to ignore a table in a 3 table query if it doesnt satisfy the statement

I am trying to have information displayed for this query: SELECT o.sub_number,o.unique_id,o.period_from,o.period_to,o.total_amt, i.paid_amt,i.dated,i.payment,i.paid_by,i.entered_date,i.paid_for_unique, j.cheque_num,j.drawn_on,j.dated AS cheque_dated FROM paid_details o, payment_details i,cheque j WHERE o.unique_id=i....

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...

Mysql - Grouping the result based on a mathematical operation and SUM() function

Hi all... I'm having the following two tables... Table : room_type type_id type_name no_of_rooms max_guests rate 1 Type 1 15 2 1254 2 Type 2 10 1 3025 Table : reservation reservation_id start_date end_date room_type booked_rooms ...

Using mysql i need to retrieve which are inserted last in every category.

Hi, My prob in brief: I have two tables namely category and product. table: category id category 1 cat1 2 cat2 3 cat3 4 cat4 table: product id productName category 1 test1 1 2 test2 2 3 test3 3 4 test4 4 5 test5 2 6 test6 2 My pr...

How to sum values when joining tables?

<hyperbole>Whoever answers this question can claim credit for solving the world's most challenging SQL query, according to yours truly.</hyperbole> Working with 3 tables: users, badges, awards. Relationships: user has many awards; award belongs to user; badge has many awards; award belongs to badge. So badge_id and user_id are foreign...

How to log error queries in mysql?

I know that there is general_log that logs all queries, but I want to find out which query has an error, and get the error message. I have tried running an error query on purpose, but it logs as a normal query and doesn't report it with error. Any ideas? ...

mysql query query

basically i need to write a query for mysql, but i have no experience in this and i cant find good tutorials on the old tinternet. i have a table called rels with columns "hosd_id" "linkedhost_id" "text link" and a table called hostlist with columns "id" "hostname" all i am trying to achieve is a query which outputs the "hostname" ...

django select max field from mysql when column is varchar

Hi, Using Django 1.1, I am trying to select the maximum value from a varchar column (in MySQL.) The data stored in the column looks like: 9001 9002 9017 9624 10104 11823 (In reality, the numbers are much bigger than this.) This worked until the numbers incremented above 10000: Feedback.objects.filter(est__pk=est_id).aggregate(sid...

How can this SQL be wrong? What am I not seeing?

Can anybody please spot my error, this should be a legal query in SQL shouldn't it?? Unknown column u.usr_auto_key in the ON clause This is the database schema: User: (usr_auto_key, name, etc...) Setting: (set_auto_key, name etc..) User_Setting: (usr_auto_key, set_auto_key, value) And this is the query... SELECT ...

create new db in mysql with php syntax

I am trying to create a new db called testDB2, below is my code. Once running the script all I am getting an error on line 7 Fatal error: Call to undefined function mysqlquery() in /home/admin/domains/domain.com.au/public_html/db_createdb.php on line 7 This is my code <? $sql = "CREATE database testDB2"; $connection = mysql_connect...

MySQL search Chinese characters

Hello, Let's say I have a row: 一天吃一個蘋果 Someone enters as a query: 天蘋 Should I break up the characters in the query, and individually perform a LIKE % % match on each character against the row, or is there any easier way to get a row that contains one of the two characters? FULLTEXT won't work with CJK characters. Thanks! ...

Mysql Query - Order By Not Working

I'm running Mysql 5.0.77 and I'm pretty sure this query should work? SELECT * FROM purchases WHERE time_purchased BETWEEN '2010-04-15 00:00:00' AND '2010-04-18 23:59:59' ORDER BY time_purchased ASC, order_total DESC time_purchased is DATETIME, and an index. order_total is DECIMAL(10,2), and not an index. I want to order all purchases...

What can cause legit MySql INSERT INTO command to fail?

I can't figure out what's causing my INSERT INTO's to fail to certain table in MySql. I can manage them to other tables. The table looks like: CREATE TABLE IF NOT EXISTS `Match` ( `id` int(11) NOT NULL AUTO_INCREMENT, `match_no` int(11) NOT NULL, `season` int(11) NOT NULL, `hometeam` int(11) NOT NULL, `awayteam` int(11) NOT N...

Mysql selecting and sorting by the bigger field

I have two fields on my table, lets say date_created and date_updated I want to select 20 recently updated/created records so it means i have to choose the top dates from both fields, how do i do that? ...

Find Consecutive Rows & Calculate Duration

I have a set a of data that tells me if a couple of systems are available or not every 5 or 15 minutes increments. For now, the time increment shouldn't matter. The data looks like this: Status Time System_ID T 10:00 S01 T 10:15 S01 F 10:30 S01 F 10:45 ...

MySql mutliple tables

I've been looking into JOIN, subqueries and other ways of doing this, but I can't work out the best way to do this is... I have a table (ps_category_product): id_product, id_category I want to perform a query on it like: SELECT id_product FROM ps_category_product WHERE id_category='$this_cat' BUT, I only want to perform this query whe...

Order hybrid mixed mysql search result in one query?

This problem is easy fixed clientside. But for performance I want to do it directly to the database. LIST a +------+-------+-------+ | name | score | cre | +------+-------+-------+ | Abe | 3 | 1 | | Zoe | 5 | 2 | | Mye | 1 | 3 | | Joe | 3 | 4 | Want to retrieve a joined hybrid result without dupli...

DELETING doubled users (MySQL)

Hi I have two tables. There are users informations from two sites: p_users p_users2 There are 3726 users in first and 13717 in second. Some users in p_users2 are in p_users. I want merge this two tables to the one big table - but rows with same usernames can't be doubled. How can I do this? I tried something like this: DELETE FROM p_u...

MySQL - Using an alias in a subquery with WHERE clause

I have a feeling I am completely borking this MySQL query but I'll ask anyway. I am wondering why I get the warning Unknown column 'FOO', and how I can get this query to work properly, in 'where clause' when I run the following: SELECT sample_id as FOO FROM tbl_test WHERE sample_id = 521 AND sample_id IN ( Select sample_id FROM tbl_test...