mysql-query

PHP script results 500 Internal server error

Hi, I can't understand why this PHP script gives me 500 internal server error. $query = "SELECT video_id,title FROM video_id"; $videos = mysql_query($query); if($videos){ $videos = mysql_fetch_assoc($videos); foreach($videos as $video){ echo '<div class="video">'; echo '<a href="video.php?v="'.$video['vid...

Count multiple appearances in DISTINCT statement with two parameters?

Dear all, I am trying to filter (or count) companies with multiple contact persons from a table containing a company_id and a person_id. Currently I just do this: SELECT DISTINCT company_id,person_id FROM mytable GROUP BY company_id ORDER BY company_id as well as SELECT DISTINCT company_id FROM mytable The first query returns a co...

How to get all selected ids at once ? PHP/MySQL question

I have MySQL table called Files which has file_id column and file_type column (and also other columns that are not relevant to the question). I would like to get all file_ids of all picture files (i.e. file_type='picture'). I do the query like this: $pictures_query = mysql_query("SELECT file_id FROM Files WHERE file_type='picture') ...

Query between federated tables and local tables

Hy, I have problems with Mysql query's made between few federated tables and local tables. With multiple joins in querys and inserts that are using one or two federated tables with two or three local tables results in time-out .... How can this problem be resolved?Where is the problem? Is not recomended? If not what is the best way to...

How to select UNIX date = "2010" in mysql query?

Here is my code so far: SELECT `date`, title, category, url FROM cute_news WHERE category = '4' ORDER BY `date` DESC I want make pages based on the year, like, 2010 , 2009, 2008 and so on. The database saves the date as UNIX_Timestamp. Not sure how to query a recordset with a Year parameter? WHERE unix_timestamp(YEAR) = '2010' or som...

Multiple MySQL Queries and fatching MIN price from a table

TABLE PRODUCTS_CATEGORIES product_id category_id link_type position 2 22 M 0 3 22 M 0 4 22 M 0 5 22 M 0 6 1 M 0 7 1 M ...

mysql_query in a while loop

I'm trying to execute I have an html form in a page of this sort : Name: <input type="text" id="namebox" value="" name="fields[]" /> <br /> Position: <input type="text" id="positionbox" value="" name="fields[]" /> <br /> <input type="hidden" name="createcard"> <input type="submit" value="Create"> .. and 3 other fields. I'm passi...

Engine select with SOURCE in mysql

How do I change the engine to MyISAM when using a SOURCE import in mysql? It currently defaults to InnoDB. would there be any difference between the speed of the import between the engines for say a 5gb .sql file? ...

SQL Syntax with regards to SELECT

I keep getting an error saying that a specific column, doesn't exist for b.BookCode But I am fully aware that it does exist! I just wanted to make sure after staring at this for so long that I am not missing something obvious. SELECT AuthorLast, AuthorFirst, OnHand, Title FROM (Inventory i, Author a, Book b) WHERE (i.BookCode = b.Book...

How can I avoid a sub-query?

This is my table: ID KEY VALUE 1 alpha 100 2 alpha 500 3 alpha 22 4 beta 60 5 beta 10 I'm trying to retrieve a list of all KEY-s with their latest values (where ID is in its maximum): ID KEY VALUE 3 alpha 22 5 beta 10 In MySQL I'm using this query, which is not effective: SELECT temp.* F...

Mysql: Use REGEX to extract string

I would like to have a mysql query like this: select <second word in text> word, count(*) from table group by word; All the regex examples in mysql are used to query if the text matches the expression, but not to extract text out of an expression. Is there such a syntax? ...

get annoying error: form is not defined with AJAX, JQUERY MYSQL Fetch

Hi I've been building a site with a ajax feature that retrievs data from a Mysql database given a surtain variabel. Here is an example of how it's been done. http://www.lensfinder.se/testar5.php I'm given this error in Firefox when I choose different data to retrieve, the AJAX is activated on the select change. "form is not defined [...

minimizing no of query in Zend

Hi, first thing I want to know in between two algorithms which one is better select table1.* from tabel1 inner join table2 on table1.id = table2.table1_id; and then to extract or select * from table2; and then using foreach loop select * from table1 where table1.id = table2.table1_id *Please tell me a plausible reason also and no...

MySQL many-to-many relationship: Help With Query

My current code is this: $select = $this->select() ->from(array('r' => 'recipes'), $this->getAdapter() ->quoteInto("r.*, MATCH(title, directions) AGAINST(?) AS score", $searchText)) ->where('MATCH(title, directions) AGAINST(?)', $searchText); //SQL: SELEC...

Select query in MySQL

Two tables Table1 ID FileName 1 abc 2 abc 3 abc 4 xyz Table2 ID Table1_ID isDeleted 1 1 1 2 2 1 3 3 0 4 4 0 I need to get the count of filename for the isDeleted=1 by passing any ID of table1, i.e for all the values(1,2,3) of ID, i need the count as 2 I tried with the following query S...

Pattern match within the IN operator (MySQL)

I would like to match patterns inside an IN expression like this: ... WHERE ... IN ('%alma%','%sajt%') Is it possible somehow and if not, how could I achieve this some other way? ...

combining two sql queries into one?

I have two similar queries on same table and same where condition but different selects on it. Select flatpos from archdetails where version='1.3' AND compname IN ( select distinct compname from svn3 where revno='r270294' ) AND select count(distinct compname), sum(CASE WHEN inFlat=1 THEN 1 ELSE 0 END), min(flatLoopIndex)...

Unknown column in mySQL CSV import

Hey everyone. I am trying to import a small CSV file into my django program. I am using SQL, and here is what I have so far. The CSV file itself has Column1 which is named Customer and I am trying to take that information and assign it to the model field name 'client_name'. Problem I get when I run this query is that I keep getting t...

PHP Output of SQL Query

As of now I have no errors in my program, but I need the primary key for one of the tables for a relation for the following Query. but instead of getting a actual number the value the query is sending back is Resource id #4 Here is my Code: (The query that I'm having issues with is the $sql_branch, is there a function to change the resu...

how to use select result with like in mysql

I need some mysql code that uses a select output in LIKE statement in WHERE. I mean something like this: SELECT id FROM (SELECT id,parent_id FROM units WHERE ptitle like '%(SELECT ptitle FROM units WHERE id='".$id."')%') Thanks for your help. ...