MySQL Query - How To Select Names With Out Duplicates
I want to select names from a database
ie:
Dog
Dog
Dog
Cat
Bird
Bird
I want something where I can select >Dog, Cat, Bird instead of the three dogs and two birds. Can I do that?
View Complete Forum Thread with Replies
Related Forum Messages:
Query MySql Database - Duplicates
I've got a field in a MySql database that I'd like to query. This field contains names of people & there are some duplicates as well. The end result of my query should look like this:- HTML Code: NAMENUMBER OF RECORDS Jonh2 records Alice4 records Builder8 records Yahoo5 records
View Replies !
MySQL Query For Domain Names Only
I'm doing a hits counter... basically tracks the hit, the referer and date. The problem is that I want to show results not only for urls, but for domains only, so group for example all referers from google.com and add the hits they all produced. I can't imagine a way other than populating a list of results and then parse them to build a list of domains and add the hits. Is there a way to construct a mySQL query to take only the domain names from the urls in database addind the hits?
View Replies !
Results Of Same Field Names But Different Tables In MySQL Query.
I have a SQL string with a couple of JOINs that works perfectly in command prompt. I get results for all the fields selected just fine. But when I put it into a PHP page, I can't make variables(?) out of fields that have the same field name from different tables. Here's the SQL statement: $sql = "SELECT orders.companyid,orders.ordernum,orders.address,tb l_ih_accounts.company,tbl_ih_accounts.address FROM orderstatus ". "LEFT JOIN orders ON (orderstatus.ordernum = orders.ordernum) ". "LEFT JOIN tbl_ih_accounts ON (tbl_ih_accounts.id = ihid) ". "WHERE submitted <> 'yes' ORDER BY orders.ordernum ASC"; Then in the "WHILE" clause after the database is queried: $o_address = $row[orders.address]; $ih_address = $row[tbl_ih_accounts.address]; I've tried it without the table names in the $row statements, but then I'll just get the results for tbl_ih_accounts.address. I'm thinking there must be some way to uniquely "name" the results of a particular field up in the SQL statement, and then just use that unique name in the WHILE. But I have no clue, and can't find anything about anything like that.
View Replies !
Query To Avoid Duplicates
$sql_ = mysql_query("SELECT * FROM category_table WHERE `group` <> ''"); while ($row = mysql_fetch_array($sql_)) { Â Â Â $group = $row['group'];Â Â Â Â Â Â echo $group; }
View Replies !
Remove Duplicates In Query
I'm querying 2 fields in 1 table. Both fields have got duplicate records. I want the end result to display in 1 temporary(temp) field with no duplicates. My code that does 90% of the work is below. The part that I don't know how to do is how to remove the duplicates from the temporary(temp) field? PHP Code: SELECT DISTINCT ap_expiry as temp FROM developer1 UNION SELECT DISTINCT licence_expiry as temp FROM developer1 ORDER BY temp DESC
View Replies !
Mysql Query - Select Any
I have the following sql statemant to search a mysql database that gets if values from a form with combo box's in. SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid = hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND hottubs.seatsto <= '%s' AND hottubs.shape = '%s' ORDER BY $thesearchtype_search. Everything works fine except I want to add a select "any" from the shape combo box. I really need a way of cutting out the last " AND hottubs.shape = '%s' " if the $_GET['shape'] = 'any' Will this work using a variable as shown below?? IF ($_GET['shape'] != 'any' ) { $shape = AND hottubs.shape = '%s' } SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid = hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND hottubs.seatsto <= '%s' $shape ORDER BY $thesearchtype_search I have only been doing php about a month so go gentle!
View Replies !
Mysql Select Query With Php
I want to create a sql query but don't know if this is possible with mysql. The Query should do the following: Select all db entries from table in which entry a is smaller than the number (count) of all db entries with criteria x from another table.
View Replies !
Mysql Select Query
PHP Code: <?php include 'common.php' include 'db.php' if(!isset($_POST['register'])) { header("Location=register.php"); } else { dbconnect('rishaorg_members'); } if($_POST['newid']=='' or $_POST['firstname']=='' or $_POST['lastname']=='' or $_POST['address']=='' or $_POST['city']=='' or $_POST['state']=='' or $_POST['country']=='' or $_POST['birthcity']=='' or $_POST['birthstate']=='')........
View Replies !
MySql Query With SELECT
The following query used to work on older PHP. I have upgraded to PHP 4.3.2 and now it stopped working. No problems connecting to db can even print the variables used for search. But it seems as if the variables aren't presented to the query: $result = mysql_query("SELECT username, name, surname, email FROM forums_auth WHERE username ='$_POST[pnr]' OR name LIKE '$_POST[fnavn]' OR surname LIKE '$_POST[enavn]' ORDER BY surname, name ASC") OR DIE ( mysql_error() );
View Replies !
How To Corret This Mysql Select Query?
I convert some code from access to mysql. And I have a InboxMessage table which has From and To field. So, the query is like: select * from InboxMessage where To=12 12 is user id. This query works fine in access. But does not work in Mysql. I think the problem is the field To, which must be a keyword in mysql. So, how to fix this? I don't want to change the field, becuase this will need to change a lot of code.
View Replies !
Is There A MySQL Function Within The SELECT Query....
Is there a mySQL function within the SELECT query that can add all of the data within a field. For example if I have a table called "profiles" and a field within that table called "referals" (which is an integer) and I wanted to add all of the results within that field together... I was trying to think of a loop to write this code in and may still do it but was wondering if there is a function within the SELECT statement that can ADD all of them together.
View Replies !
Very Slow MySQL SELECT Query After 11 Records
I have a very weird problem I moved my database to new IIS 6.0 + PHP 4.3 + MySQL 4.0 setup. I tried to check with myphpadmin if everything works fine, but I couldn't browse my table (125 records). I used SELECT option and found out that SELECT query up to 11 records is ok, but after that, even if I choose to limit query to 12 records, it just hangs. I tried selecting from the beginning of the table and from the middle - same thing, but when I run query localy on mysql console, everything works fine
View Replies !
Drop Down Menu Where The Items Are From A MySQL Select Query
I am just starting programming in PHP and wonder if it is possible to have a drop down menu where the items are from a MySQL select query. I am registering people for a weekend seminar and want to have a list of valid weekends to choose from on the form. Any pointers to scripts or PHP references that will help would be appreciated. I am using the book "Build your Own Database Driven Website Using PHP & MySQL" to get me started, but also need recommendations for a general primer to php.
View Replies !
Mysql SELECT Query That Selects The Latest Items
I am building a website that has a software download category, and has news on the main page. Now I have two tables, named "news" and "software". On the main page I want to select the latest 40 updated items, so whether it is a newspost from table "news" or an extra entry in table "software", or an updated version of an entry in "software". They are all INT types holding a time() string. what I want is a mysql SELECT query that selects the 40 latest items.
View Replies !
Combining 2 Fields In A Single Mysql Select Query
i want to combine 2 fields in a single select query fields. pageheader name values. abcd <div id="d"></div> i want to merge/combine the pageheader and name in a single select query so that it can retrieve the pageheader with some styles which i have stored in another table.
View Replies !
MySQL Query: Select Only Numeric Substring From Varchar Field?
I would like to write a MySQL query that will limit the selected records to a specific pattern that end in digits rather than non-numeric characters. Say the field (TESTPHASE) has values like this A000 APM APM1 A015 A010 A045 HPM1 GPM F020 E045 I want the SELECT query to return only A000 A015 A010 A045 F020 E045 I suppose it would be possible to filter these after the fact with some fancy php code, but I'd MUCH rather do it up front with the MySQL query. Oh, and of course I am stuck with MySQL v3.23.45
View Replies !
Trying To Select Names From A Drop Down List And Display Them
So, I already have the code written where I have a drop down menu with names in it. I want to be able to select multiple names from the drop down list and have them display in a table below the drop down menu. First off, I can't get one name to display, not to mention multiples. :p How may I accomplish this? CODE:
View Replies !
Delete Duplicates In MySQL
I have a database in MySql which has 2 fields. The 1st field is called id which is the primary key. The 2nd field is called full_add where there are some duplicates. I would like to delete all the duplicates in the full_add field leaving only 1 record behind. It does not matter if the corresponding primary key gets deleted as well because the primary key is not related to any other table or database. I prefer not to use temporary tables or create new tables because my webhost does not allocate much memory to me & my database is quite big.
View Replies !
MySQL FT Search - Removing Duplicates
I have a MySQL Fulltext search engine that works beautifully. One problem though: If a row has more than one occurence of the search term, it will display the row over and over for each match. Is there a way that I can return only one row? I tried "array_unique" but I couldn't get it to work.
View Replies !
Avoid Duplicates In MySQL Result Set
I have a database say for types of pop. So this is the db Cola 1 Cola 2 Cola 3 Cola 1 all with unique id's. I would like to display the names of cola on the main page but I would not like duplicates displayed regardless of how many there are. So for the db i just displayed i would like the main page to look like this. Code:
View Replies !
Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution. So it goes <select name='status[]'>... <select name='resolution[]'> Then i have a another php page. $status = $_POST['status']; $resolution = $_POST['resolution']; Now my question is, how do i do the sql query statement? mysql_query("SELECT * from bugs where status=$status and resolution=$resolution"); The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.
View Replies !
Execute An Update Query Based On The Results Of A Select Query
I'm trying to execute an update query based on the results of a select query... This doesn't work - any ideas? This is the code I'm trying to get to run (it updates all products which are set to arrive by a certain date if that date has arrived or passed - and there are products that should and should not be updated in the db this is being tested with...): Code:
View Replies !
Function Names Stored In Db; Called Based On Query
I'm wondering whether something like this is possible: 1. I want to store an id# / function-name pair in a database - e.g. 0001 / functionA(), 0002 / functionB(), 0003 / functionC(), etc. 2. Based on some query, some number of these id / function name pairs are returned. 3. The returned function names are called in a script. More background on my question: I'm building an intranet for my company. There are various departments within my company, each of whom will have their own section of the intranet. I've built various online tools that may be of use to some number of these departments. I want the departments to be able to decide which tools they want to appear on their "home page" within the intranet. In my imagination, each time I create a new tool, I register it in a db table. Each department uses an online form to flag the tools they want to appear on their page. The form they edit updates a db table, linking their department with the id number of the requested tool. The script that creates their home page queries the table, determines the tools they've asked to view on their home page, and calls the appropriate functions that will display these tools.
View Replies !
Turn Select Query Result Into Hyperlink To Other Query
I have a query which gives results of selecting coursenames from a table called trainingtopics but this does so in a continuous bulk of text without any breaks between each record. my question how do I create line breaks between each record and also how can I force each query result to become a hyperlink which when clicked runs another query that gives details of that course. <?php $user = "root"; $host = "localhost"; $password = ""; $connection = mysql_connect($host, $root, $password) or die ("Couldn't connect to server."); $database = "courses"; $db = mysql_select_db($database) or die ("Couldn't select database."); $sql = "SELECT coursename FROM trainingtopics"; echo $sql."=sql<br>"; $result = mysql_query($sql) or die(mysql_error()); echo $result."=result<br>"; while($row=mysql_fetch_array($result)) { // NOTE this one ABOVE the echo echo "result found!"; echo $row[0]; } ?>
View Replies !
Retrieve Names From MYSQL
1. Im tryin to retrieve the following names from the database 'kagiso', 'steve', 'dwele', 'raheem', 'raekwon', 'common' 2. i need to retrieve only 3 names @ a time then echo a 'next >>' link that will retrieve the last three
View Replies !
Displaying MySQL Column Names Using PHP
I'd like to be able to display the column names of a table on a page. Is there a way to read that information in using SHOW? And then to display that information again? Or would I have to store these names in a seperate table and display these values? I tried this, but it sure didn't work: $result = mysql_query ("show columns from industries"); print ("<table>"); if ($row = mysql_fetch_array($result)) { do { print ("<tr><td bgcolor=#cccccc>"); print $row["field"]; print ("</td><td bgcolor=#cccc00>"); print $row["type"]; print ("</td><td bgcolor=#cccc00>"); print $row["null"]; print ("</tr>"); } while($row = mysql_fetch_array($result)); } else {print "Sorry, no records were found!";} print ("</table>");
View Replies !
Numeric Column Names In Mysql?
i am trying to create a table with a column name called 2004. But I keep getting a mysql error? Is there any workaround? Unable to execute: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near �� TEXT,2004_reference TEXT,2005 TEXT,2005_reference TEXT,200 CREATE TABLE test (id int(6) NOT NULL auto_increment, membership_number TEXT,first_name TEXT,last_name TEXT,spouse TEXT,phone_priv TEXT,phone_bus TEXT,address_street TEXT,addr_town TEXT,addr_city TEXT,membership TEXT,donor TEXT,1998sa TEXT,1999sa TEXT,2000sa TEXT,200s1 TEXT,2002sa TEXT,2003sa TEXT,2003_reference TEXT,2004 TEXT,2004_reference TEXT,2005 TEXT,2005_reference TEXT,2006 TEXT,2006_reference TEXT, PRIMARY KEY (id),UNIQUE id (id))
View Replies !
Counting Names In Mysql Database
I want is to have the number aof how many times a name is existing in a table_row. you know, my tably is like this status author text: 1 dominik hasjfghkasdfhsk 1 dominik djwkhflwjfv 1 egon jdskljfsldjf I want php to count dominik and view the result on a php-page.l
View Replies !
Setting Variable Names Using Field Names?
I'm having trouble creating dynamic variables using field names. Basically I got a heap of fields named after Players and I want to grab the field name and make a variable called it while assigning it a value from a post variable which is also the player name. This is the code I'm using: $result=mysql_query("SELECT * FROM playerstats"); while($fld = mysql_fetch_field($result)) { if ($fld->name!='match_id' && $fld->name!='opponent' && $fld->name!='map') { $fld->name=$_POST[$fld->name]; } }
View Replies !
Print Out A List Of All Mysql Field Names
I'm trying to make a drop down menu which has got a list of all field names that are in a database so you can do a search in each field seperatly but i can't find out how to do it.. can it be done with mysql_field_name and if so then anyone knows how ??
View Replies !
MySQL Error - Using Different Table Names And Fields
I'm trying to run this query and I'm receiving the following message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition, exc_comments, good_comments, fair_comments, fair' at line 3 I've used this query in other scripts, using different table names and fields, and the query worked without a problem. I don't know why this particular one isn't working. Code:
View Replies !
Select Query With And / Or
Trying to get a search feature running. A table has 2 field 'itemname' and 'itemdescription'. I would like the search to use a keyword on both of these fields but i'm unsure of how to seperate it from the main query. $query = "SELECT " .sellerid . "," . itemname . "," . itemtype . "," . itemstate . "," . itemprice . "," . pic1 . "," . itemid . "," . itemdescription . " FROM item where " . itemtype . "= '$ctype' AND " . itemstate . " like '$stype' AND " . itemprice . " >= '$lprice' AND " . itemprice . " <= '$hprice' AND " . itemdescription . " like '%$kwords%' OR " . itemname . " like '%$kwords%' ORDER BY `itemprice` DESC LIMIT $offset, $rowsPerPage"; The OR seems to be working on the whole query not just the last little bit like i would wish. " . itemdescription . " like '%$kwords%' OR " . itemname . " like '%$kwords%' Something like this but contained in the main query? Does this make sense?
View Replies !
Select * From Query
Im trying to run a simply Select * from query but the result is a blank page. here is my code. when I connect to the db using the same code but inserting data I get no problems. so Im having no server problems. <?php $user = "root"; $host = "localhost"; $password = ""; $connection = @mysql_connect($host, $root, $password) or die ("Couldn't connect to server."); $database = "courses"; $db = @mysql_select_db($database, $connection) or die ("Couldn't select database."); $sql = "SELECT * FROM trainingtopics"; or die (mysql_error()); ............................
View Replies !
Query SELECT * FROM
here is my query to my database $result_pi = mysql_query("SELECT * FROM players WHERE teamid = '".$gm_team2."' AND position != 'G' and status = 'Healthy' AND registered = Ƈ' ORDER BY lname"); this works fine, but i am trying to add in as well status = 'Rookie' When i try and add this, both the status things work against each other. How can I get this query to bring up both of them.
View Replies !
Select Query
However when I echo mysql_num_rows it gives 0 results even though the same date is in the db table. class_date is set as date type in mysql db. PHP Code: $query = "SELECT * ". "FROM class ". "WHERE class_date = $class_date";
View Replies !
Select Query
I have a table with 2 fields, lets say field1 and field2: Now I have records in that table something like this: 1 a 1 ab 2 a What I need is to make a selection and the result returned to be something like this: 1 a;ab 2 a So, I want for the same field1 to concat field 2 using a separator (ex. ‘;’). Mysql server version is 4.0.
View Replies !
Select Query Problem
I use php4 and winxp. This query works as expected: $result = mysql_query(" SELECT feventid, UNIX_TIMESTAMP(fdate) as fdate, ftitle, fpostedby, fdetails, factive, UNIX_TIMESTAMP(fpostdate) as fpostdate FROM events WHERE fdate between '$datefrom' and '$dateto' and factive and fpostdate <= curdate() ORDER BY fdate, fpostdate "); However, when I add the condition !(strpos(fdetails,'$fsearchstring')===false), $result is false. $result = mysql_query(" SELECT feventid, UNIX_TIMESTAMP(fdate) as fdate, ftitle, fpostedby, fdetails, factive, UNIX_TIMESTAMP(fpostdate) as fpostdate FROM events WHERE fdate between '$datefrom' and '$dateto' and factive and fpostdate <= curdate() and !(strpos(fdetails,'$fsearchstring')===false) ORDER BY fdate, fpostdate "); Even simpler stuff like: 'and strpos('abc','c')>0' does not work. I made two more discoveries trying to crack the problem. Ɔ=0', is an acceptable condition, while 'true' is not. For the first query, $result does not return true, but 'Resource id #3'. I have just started with php. What am I doing wrong?
View Replies !
Select Query For Keywords
I am connecting to an Access database. I have the following code that breaks the user submitted title into an array. I want to match only records that have only the array values, but can be in any order. For example: User enters - "Purple People Eater" Matching Records - "Purple Eater People", "Eater People Purple",... but NOT - "The Purple People Eater", "Purple People",... Here is my code: PHP Code:
View Replies !
Select Query / Loop
My users are organised in a table named 'users'. Each user is a member of a department, but some users are members of more than one department, so I have another table named 'user_department'. I have another table named 'submissions' int which users submissions are stored. Right now I am developing an archive of submissions. Generally speaking a simple query will do the job like this: $query = "SELECT * FROM submissions WHERE status != 'Pending' AND sid = '$username' ORDER BY id desc LIMIT $from, $max_results"; $result = mysql_query($query); The problem comes when I try to select only the submissions lodged by the users department. The point being that the department head can view all submissions lodged by his department. If the department head is only head of a single department, this would work: $query = "SELECT * FROM submissions WHERE status != 'Pending' AND department = '$users_department' ORDER BY id desc LIMIT $from, $max_results"; $result = mysql_query($query); But if the department head is head of more than one department, I start to get lost! I can loop through the 'user_department' table to find out which departments the user is the head of like this: Code:
View Replies !
Php Query To Select Min Date
im trying to get a minimum date from my database, the current way im doing it is: SELECT * FROM events where Date > NOW() OR Date = '9999-12-12' ORDER BY Date ASC LIMIT 1 this works in terms of code, but it doesnt do what I want it to do. Its the ORDER BY Date, that is the problem: What I want to select is The next date OR a date = 9999-12-12 I tried searching for a query like "select MIN date" but couldnt find anything on it, plus the date has to be in the future, hence the need for DATE > NOW() quite confusing I know!! but any advice?
View Replies !
Select Menus Query
I have created numerous select menus where the user can if they so wish select all or any one of them. At the moment my code insists that they always select at least the subfund menu. How can I set it up so that they can select any one menu? Code:
View Replies !
Problem With Select Query
This script/function tests properly when using DreamWeaver's Testing Server and Live Data Settings, but fails on the live Web Server, giving the following error. Code:
View Replies !
Select Query + Inner Join
I have 2 tables: keywords{keyword_id, keyword} url{url_id, url, keyword_id} I have a search form where the user enters a keyword and if it is similar to the keyword(s) in database it should return the url. Code:
View Replies !
|