mysql

phpMyAdmin versus mysql_fetch_array - why can't I get GROUP BY to work?

I have a simple table called "board" that has a column called "sid" - that is just integers. Many of these are duplicates. I want to know only distinct values in this column, so I do this: SELECT sid FROM board GROUP BY sid When I run this query directly in phpMyAdmin, I get the set I was expecting. No problem. However, this bit of cod...

compare two arrays of numbers and remove duplicates in php

Hi, OK i have two groups of mobile numbers (from mysql) which i need to process, the problem is i need to remove duplicate numbers from the results. Someone told me about "array_intersect" but I am not very good at these things and I don't see any good examples on the PHP website. Any help or suggestions is appreciated thanks :) ...

No server-side prepared statements using MySQL Connector/J

From what I understand, MySQL 5.1 supports server-side prepared statements. Therefore the following code should prepare the statement once, and execute it 10 times: Connection conn = ds.getConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT COUNT(*) FROM users WHERE user_id=?"); for (int i=0; i<10; i++) ...

In a Many to Many relationship, how can records collectively owned be selected.

I'm sure I'm missing the correct terminology here, but for this example many-to-many relationship: A user has many books. A book is owned by many users. What's the best way to see all books owned by both of two users? Right now I'm just using this: SELECT * FROM books WHERE book_id IN (SELECT book_id FROM user_has_book WHER...

How to split text in column into 2 columns (MYSQL) after separator

Hi Guys. I am looking for some code, which can do separated text from column description into columns test 1 and test 2 Example description (price $250, New York, Beautiful house) What I need test 1 $250 test2 New York ...

MySQL query to print output as CSV to standard output

I want to do the following mysql -uuser -ppass -h remote.host.tld database < script.sql where script.sql contains the following SELECT * FROM webrecord_wr25mfz_20101011_175524 FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' I want CSV output directed to standard out. The reason is because running this query with a...

crawling a html page using php?

this website http://courses.westminster.ac.uk/CourseList.aspx which lists over 250 courses in one list, i wanted to get the name of each course and insert that into my mysql database using php, the courses are listed like this: <td> computer science</td> <td> media studeies</td> etc... is thier a way to do that in php, instead of me ...

How to check that at least one row complies to a condition (WHERE clause) in MySQL?

The task is to have a query returning 0 if no rows are going to be returned if the condition is applied and 1 if there are going to be more than 0 rows. Preferably this query should be faster than just querying the table with the condition and limiting the query with 1 row in result set. ...

#1222 - The used SELECT statements have a different number of columns

Why am i getting a #1222 - The used SELECT statements have a different number of columns ? i am trying to load wall posts from this users friends and his self. SELECT u.id AS pid, b2.id AS id, b2.message AS message, b2.date AS date FROM ( ( SELECT b.id AS id, b.pid AS pid, b.message AS message, b.date AS date FROM ...

What are the most likely scaling issues a website with a modified lamp stack (Lighttpd instead of Apache) on EC2 will encounter as it grows?

What are the usual bottlenecks (And what tends to break first) to Lamp based sites on EC2 when your number of users increase? Assuming: -Decent DB design -There are some Ram and CPU intensive processes on cron but no ram/cpu intensive stuff during normal use. ...

mysql regex & distinct values

I am using mysql & perl. I have the following values for one of my columns in my database: 123 Hollywood 345 New York 847 Hollywood 192 Boston 876 Chicago I want to select all of the distinct cities....ie, the results would be: Hollywood New York Boston Chicago Is there a way to do this via msyql? I would imagine some sort of REGEX...

Mysql WHERE problem

Hi, I need help for this problem. In MYSQL Table i have a field : Field : artist_list Values : 1,5,3,401 I need to find all records for artist uid 401 I do this SELECT uid FROM tbl WHERE artist_list IN ('401'); I have all record where artist_list fields values are '401' only, but if i have 11,401 this query do not match. An...

SELECT with array()

I'm trying to filter a table to SELECT the values to certain rows based on condition. The first rather complex SELECT works fine yielding me a group of id's. But I want to use this id group ($art_id) in an array for the 2nd SELECT to get rows more straight forwardly. Hope someone ha suggestions. Thanks, Allen. the first SELECT is not ...

mysql insert command with a where clause

im trying to insert data into a particular row in the database, but i mysql is saying this is an error: INSERT INTO user (rep, course) VALUES('5', 'computer science') WHERE user='2' ...

Get count of posts from a union mysql query?

SELECT u.id AS pid , b2.id AS id , b2.message AS MESSAGE, b2.uid AS uid, b2.date AS DATE FROM ( (SELECT b.id AS id , b.pid AS pid , b.message AS MESSAGE, b.uid AS uid, b.date AS DATE...

Sphinx Mysql query problem

Hello. My sphinx config: source logs { type = mysql sql_host = localhost sql_user = root sql_pass = sql_db = bot sql_port = 3306 sql_query_pre = SET NAMES utf8 sql_query = SELECT * FROM logs sql_attr_uint = host sql_query_info = SE...

Problem logging in with PHP's $SETTINGS

I'm trying to get the user's login details from the database using $SETTINGS["admin_username"] and also the password. I have defined them as 'user' (for username) and pass (for password), and I want them to be pulled from database table userLogin. Any ideas? Please help, I have tried everything but the page either doesn't open or it doe...

Challenging data modeling scenario

I have to create a model that stores gameplay controls for games on several platforms. I am having trouble finding the right approach. Controller buttons are different on different systems (Wii, Xbox 360, PS3 have their own specific controller buttons.) Some games are actually several games packaged as one; this means a single product ...

Use PHP to truncate the age of a MySQL entry to the nearest unit of time

I have a table with a datetime field, and I want to pull that time stamp and use PHP to convert it to the nearest largest unit of time. For example, if the entry was made 2 minutes and 36 seconds ago, I want to echo 2 minutes in PHP. If it was 3 hours and 5 minutes ago, I want it to say 3 hours. If it was 6 days and 4 hours and 40 minute...

How to model something if the desired information is the same as an already existing record

How to model something if the desired information is the same as an already existing record e.g. Address (Street, Country, Province, Zip) We need to capture an User who has a permanent address and an address for correspondence (i.e. 2 rows per user). There is a provision to say that the "address for correspondence" is the same as the "p...