mysql

MySQL left join one table to itself

Please consider the following table 'mmm': select * from mmm; Output: +-------+-------+------+ | texto | value | n | +-------+-------+------+ | aaa | 10 | 1 | | aab | 10 | 1 | | aaa | 11 | 1 | | aab | 11 | 1 | | aaa | 10 | 2 | +-------+-------+------+ The command: select...

Replace mysql->php->mysql with nested query

Hello all, I have a table with columns 'customer' and 'location' and I need to check top 10 locations visited by unique customers. I'm ready to do the following: SELECT location FROM myTable GROUP BY location load results to an array (maybe a hundred of few hundreds of locations) SELECT COUNT(*) AS total, tbl.location AS LOCATION FROM...

Connect TO Sql Server From MySQL

dear all, how can I connect to a Sql Server Database from a MySql Server? I need to use the Mysql as a proxy db (querying all the Sql servers and MySql connected to it). I need a functionality sort of "linked server" one on Sql server Thanks a lot, Andy ...

How can I make this MySQL SELECT + GROUP BY query more efficient?

I have a fairly popular site that's now getting rammed with a lot of traffic, and I've been informed by my webhost that the following query is taking up to 2 seconds to run. My MySQL skills aren't that great, so I'm sure I'm doing something wrong, but I'm not sure what could be done to improve it. For simplicity's sake, assume live_blu...

Best way to connect node.js and sphinx

I'm trying to search in sphinx from node.js code. The only way to do it I know is to connect to searchd as to mysqld server. I'd absolutely all known mysql libraries, but no of them even connected to sphinx. ...

mysql_num_rows() does not work with SUM()?

Using PHP mysql_num_rows() returns "1" when running the query below on the table below when there are no matching rows present. Upon testing I found out that the problem happens when I use the SUM() function in the query. If I take SUM() out of the query mysql_num_rows() returns "0" like it should. Is there something else I should use ...

how to handle url modifications php/mysql

Hi, I am having a problem in understanding the security issues with the following scenario. I have a site that has user registration and they can create events by logging in. If I am logged in as a user and i am in a url like http://abc.com/index.php?page=edit&pageid=45. I am seeing this page after logging in other wise it will show...

How to get tags of a website?

For example google.com can be tagged as a search engine. facebook as a social networking site I want to automate this process. How do I go about it? That is, I want to create a tag engine which automatically labels websites. I can pull up the meta information for each website and then guess the category.f there are sites already ther...

SQL query for grouping data from two tables

I have 3 tables: Users (id, name) Orders (id, userId) Orders_Items (id, orderId, status) At first I wanted to list all users with their respective count of orders like this: A, 1 order B, 5 orders That's easy, I'm doing a "select name, count(id) from users, orders where users.id = orders.userId group by name". Now, I'd like to f...

mysql php question get parent id recrusive

Hello, MY database looks like (pligg cms, sample data) id catID parentID catName 1 1 0 location 2 2 0 color 3 3 1 USA 4 4 3 Illinois 5 5 3 Chicago 6 6 2 Black 7 7 2 Red Let say, how do i get top parentID of chicago, it should b...

Convert dd-M-yyyy to mySQL datetime

I have a MySQL varchar column full with dates stored in dd-M-yyyy format. E.g: Row 1: 12-jan-2010 Row 2: 23-jun-2016 What's the best way to convert this to mySQL datetime format using php? ...

How to display data from 2 related tables in Zend Framework

Hello I need help with displaying data from 2 table. So i Have 2 models: //Klasy.php class Model_Klasy extends Zend_Db_Table_Abstract { protected $_name = 'klasy'; protected $_primary = 'id'; protected $_referenceMap = array( 'Nauczyciele' => array( 'columns' => array('Wychowawca'), 'refTableCla...

PHP using array_replace with multidimensional array

I am trying to build a game board 8x8 for a small game of battleship with game pieces in place (kind of like checkers) so i could move the pieces with MySQL the players can move freely in the board to go against each others battleships. the pieces will be place in predetermined spaces while other space will be empty and be handle by mys...

Effective ip->location query

Hello all, I have two tables: one is ip_group_city from ipinfodb.com containing ip_start numbers for determining location of IPs, and other is "visits" with information about web site visitor containing column 'ip'. I need to select top 10 region_code (from ip_group_city) by checking region_code for each IP from "visits" table. Right ...

Using a db vote table for many arguments tables

Hi, I'm trying to understand if it's right to use one table for votes for more than one argument: table_votes id | vote (±1) | id_user | timestamp | argument_type | argument_id table_photos // could be argument_type = 1 id | photo_file | photo_name | etc. table_house // could be argument_type = 2 id | house_name | etc. My prob...

force new record to be inserted at the end of table?

whenever i delete a record and then insert new one, new record is inserted at the deleted index? how can i force new record to be inserted at the end of table? ...

How to create MySQl tables forA PHP Game for movement?

I am trying to build PHP based battleship the php code below displays a board but now im trying to ad values to the individual squares of the board so I can use those values with mysql to move the pieces in place around the board so the players can go after each others battleship: the game does not involve session it is strictly 2 playe...

mysql - three joins on the same table

I have two tables: persons - person_id - fullname students - student_id _ person_id - father_id - mother_id In students table the last three columns store ids from persons table. What SELECT could retrieve the following data: - student name - father name - mother name We assume no WHERE, ORDER BY, or LIMIT for simplicity ...

How to UPDATE a certain row OR RETURN FALSE if it doesn't exist?

How to do it in one query? ...

IIS6 Web Garden

I have a site that's becoming more active. I use a MySQL Database, .NET 3.5, IIS6, Memcached, and state server. I was looking into ways to improve performance and found that web garden adds additional threads for requests. I read that this should be equal to, or equal to + 1, the number of physical processors in the machine. So I tri...