Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





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 Complete Forum Thread with Replies

Related Forum Messages:
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 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 !
Checking For Duplicates In Database
how can i check for duplicates in a database. For instance, checking for already registered users, etc.

View Replies !
Checking For Duplicates In Database On Form Submit
I had the idea to use the following to check for duplicate value when a form is submitted to a database:

elseif ($result == $_POST['serialnumber']) {
         $db_handle = pg_connect('dbname=test2 user=andy password=da4531');
         $query = 'SELECT serialnumber FROM system';
         $result = pg_query($query);
         pg_close($db_handle);
       echo "<h2><b>Duplicate serial number!  Go back, change serial number and submit form again.<b></h2><br />";  }

I can't figure out how to get $_POST['serialnumber'] to check against each record of $result.  Any ideas?  All values of 'serialnumber' need to be unique.

View Replies !
Duplicates In A Dropdown Menu Populated From My Database
I've been searching to figure out how not to have duplicates in a dropdown menu populated from my database. This is what I have, but how do I change it to get rid of duplicates.

<?php
$result = mysql_query("SELECT City FROM residential order by City");
echo "<select MULTIPLE NAME="City_code">";
while($row = mysql_fetch_array($result)){

echo "<option name="City" value="$row[City]">$row[City]</option>";

}
?>
</select>

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 !
Query A Mysql Database
how would i query a mysql database and format the results in a table with php?

View Replies !
Query MySql Database
I have a html form which I'm using to query my MySql database. At present, both the form & the database reside on my server. Everything is working fine. I now want to place the same html form on another server(belonging to my customer) & allow them to query my database(which will remain on my server under my control).

This arrangement will be exclusively provided for a selected group of customers only. What do I need to learn / read / know in order to make this arrangement work? Could you provide me some keywords to Google / Yahoo or point me to some sites that provide some tutorials / information on this matter?

View Replies !
Upload & Query MySQL Info Database With Image Files
I want a database I can enter information and upload a photo from a web form. Then I want to query that database for the text info with its related photo and display it (formatted) in a browser (html).

Summary:

1. upload photo's and text information to database with my add article form.
2. Query the database and page the results with the text and related photo.

It comes in three parts:

1. add_article.php [Text / Photo Upload Form]
2. insert_article.php [Inserts into database]
3. articles.php [View Output]

Here is what I have this far:

View Replies !
Nest One Mysql Query Within Another (for Cross Referencing Another Table In The Middle Of That First Query)?
How do i nest one mysql query within another (for cross referencing another table in the middle of that first query)? for example:

i am referencing a table with news posted by members and in the middle of that reference i want to reference an up to date version of their email address as listed in their profile (in case they change it after posting a news message).

View Replies !
PHP Update Query Mysql: Query Succussful?
I can't seem to successfully test an update query. Below is a piece of code that updates a statistics table. If row today doesn;t exist, a new day must be created. But this doesn't work...

thank you for your reply.

$today= date("Y-m-d");

$qq="update totals_r set hits_r=(hits_r+1), lang_$lang=(lang_$lang+1), cat_$cat=(cat_$cat+1), rating_$rating=(rating_$rating+1), bussite_$bussite=(bussite_$bussite+1) where date='$today'";

$result_6 = mysql_query ("$qq");

if (!$result_6){ /// IF !ROW_TODAY ==> CREATE NEW DAY

$qq_2="insert into totals_r (hits_r, lang_$lang, cat_$cat, rating_$rating, bussite_$bussite, date) values(&#391;',&#391;',&#391;',&#391;',&#391;','$today')";

$result_6_2 = mysql_query ("$qq_2");

if (!$result_6_2){
$err_msg_sql_6= mysql_error();
$err_loc_6="$PHP_SELF"." // Query6: update totals_r";
}
}

View Replies !
Query - Create The Mysql Query To Get All Fields
I've a table "article".
Any article is of a type in table "type1" or "type2"
Each type may be of a model in table "model1" or "model2".
Each model can be on a certain make, also in 2 tables, "make1" and "make2".

they are a few possibilities.
"article" can be of "type1" or "type2"
"type1" can be of "model1" only - "type2" can be of "model1" or "model2"
"model1" can be of "make1" only - "model2" can be of "make1" or "make2"

"article" has "type.id" field (char10). If it start with "my" then it's a
"type2", otherwise is a "type1"
"type1" has only "model1.id" field. "type2" has "model1" and "model2"
fields. If one is filled, the other isn't
"model1" has only "make1.id" field. "model2" has "make1.id" and "make2.id"
fields. If one is filled, the other isn't

so here are the possibilities:
article -> type1 -> model1 -> make1
article -> type2 -> model1 -> make1
article -> type2 -> model2 -> make1
article -> type2 -> model2 -> make2

Now, I must create the mysql query to get all fields given the "article.id".
Is it possible ?
How ?
will this work ? in pseudo-code

article left join type1 articleid = type1id
inner join model1 type1id = model1id //inner because if type1, the model is
1
inner join make1 model1id = make1id //inner because if model1, the make is 1
left join type2 articleid = type2id
left join model1 type2id = model1id
left join model2 type2id = model2id
left join make1 model2id = make1id
left join make2 model2id = make2id

View Replies !
Duplicates
check for duplicates of anything? For example, in the customers table, I want to check for duplicate zip codes, and display them. So, if there are 40 records of zipcode ?', and 35 records of? By the way, I don't know what zip codes are out there, I just used those as examples. So, I don't have an particular zip code I'd like to view. I'm just curious to see how many of any duplicate zip codes are in the table.This query does the exact opposite of what I want to do:PHP Code:

SELECT DISTINCT zipcode FROM customers And I tried this query,but it only seemed to cause my PhpMyAdmin to bog down:PHP Code:

SELECT zipcode FROM customers
WHERE zipcode IN
       ( SELECT zipcode FROM customers GROUP BY zipcode HAVING COUNT(*) > 1 )

How would I pull out only zip codes, if, there are more than 1?

View Replies !
Code To Look For Duplicates
I would like to create a php script that would search a log file and spit out the top 10 requested songs but...only allow an IP to vote for the same artist once. So for example. The log file looks like this.

04-03-2002,18:40:40,xx.xx.xx.xx,0,Brett Raymond - Angel's Gonna Find You.mp3
04-03-2002,19:33:20,xx.xxx.xxx.xx,0,Alex Mackey - I Know That My Redeemer Lives.mp3
04-03-2002,19:43:21,xx.xxx.xx.x,0,F:Jenee Wright - His Eye Is On The Sparrow.mp3
04-03-2002,19:45:44,xx.xx.xx.xxx,0,Jeff Long - Gethsemane.mp3

The xxx's are the IP's which I masked for this example. Is PHP capable of doing what I need or should I look into a Delphi or C++ program? If PHP can do this how would I start it out?

View Replies !
Removing Duplicates
I'm getting some data from a database, but there are duplicates for every entry. For instance, if you looked a table of posts for this forum, you'd see posts and the author.  I'm getting the author, so there could be hundreds or more of repeats. I'd like to basically get all the uniques in a column. 

View Replies !
Sql Counting Duplicates
Hy

I have this code:
------------------------------------------------------------------------
$result = mysql_query("select * from smjestaj left join grad on
grad.grad=smjestaj.grad_pbroj order by grad_pbroj ASC", $db) or die ("Could
not read data because ".mysql_error());


// print the data in a table
if (mysql_num_rows($result)) {

print "<table cellspacing=0 border=1 width="25%" class="redovi">
";
print "<tr class="headline"><td> Grad </td></tr>";
while ($qry = mysql_fetch_array($result)) {
print "<tr><td><a href="" .
"lista_sa_linkovima_po_gradovima.php?grad=$qry[grad_pbroj]"[color=blue]
>$qry[Naziv]</a></td>";[/color]
print "</tr>
";
}
print "</table>
";
}
mysql_close($db);

------------------------------------------------------------------------
Table smjestaj has coloumns:
id | Name | grad_pbroj | ...

Table grad has coloumns:
grad_pbroj | Naziv|

Now i wanna display all the grad_pbroj coloumns from 'smjestaj', buth not
displaying duplicates, just to count them, and put the count behind the
'grad_pbroj' coloumn.

Result:
Naziv_first (3)
Naziv_second (1)
Naziv_third (8)

I nead full solution, because i have tried everythig and either sql of php
displaying is fucking me.
I have tried all of that group by, count sql syntax, and i allways get
error.
Anyone cann help me plz.
Dejan

ps. sorry to all the people i have asked this before, buth not giving full
description (Arjen, Jerry Stuckle).

View Replies !
Prevent Duplicates
I have a simple db with three columns,id name and details. There are two forms for adding and editing details, to be sure that the add details form does not create duplicates i need to:

check that a name does not already exist before the new data is inserted, if the name already exists then i want to simply update the details.

View Replies !
Getting Only Duplicates In Array
how is it possible to get only duplicates in arrays? Here's the example I want to work on and only want to get the data that are marked here with a * Code:

View Replies !
Check For Duplicates
i have a small problem of checking for duplicated unique data input. i want to know if its possible to write a php script which if i copy and paste an address book from one data source and save it, then update addresses from a different source it will say something along :- error $address already exists in this document. if so could someone point me in the right direction?

View Replies !
Remove Duplicates
I have the following:

$result = mysql_query("SELECT * FROM products ORDER BY CategoryID");

How do I modify that to get rid of the duplicates in CategoryID?

e.g. I dont want a list saying red, red, red, blue, blue, yellow, yellow.

Rather, I want it to show red, blue, yellow.

View Replies !
Find Duplicates
I want to have a php page which displays all the duplicate members in my database, I just want it to show in a table FirstName, LastName, The No. of Matches, And also have a clickable View link... Anyone done this before?

View Replies !
Preventing Duplicates
I'm doing something where I need to enter ID numbers, but I don't want the same one twice. Furthermore, I would like for the page to give an error if this happens.

I don't entirely know how to do this, but I've read around and found stuff like

mysql_query("SELECT COUNT(*) FROM <table> WHERE <column>"). This is great and all, but if I try to save that value to a variable, like

$counter=mysql_query("SELECT COUNT(*) FROM <table> WHERE <column>"),

I don't get a number, such as 0 or 1 or anything that I want, I get a Resource #3 or something along those lines. All I want is to be able to check the database against the ID given in a form to see if it is there. Code:

View Replies !
Trying To Avoid Duplicates
I am trying to run a select statement before an IF to avoid inserting duplicate records, as follows Code:

View Replies !
Duplicates Across All Fields
I ve been reading all the forum posts on finding duplicates and theyre generally on the first name last name basis.

I however need to find duplicates across the entire structure of a table. That is, every field (total 30) of a record is a duplicate entry of another record except the id field which is set to autoincrement.

View Replies !
How To Delete Duplicates But Keep 1?
I need a way to delete from friend_bulletin WHERE user_id AND subject have duplicates

example

user_id subject
1 test
2 test
1 test
4 dfgdf
5 dsgdsf
1 test

In the axample there are 3 duplicates 1 - test

I would like a way to do this but keep 1 of the duplicates

View Replies !
Deleting Duplicates
I need to compare two arrays of strings and delete all the duplicates values from both arrays. Is this possible? The only related function I could find is array_unique() but even that doesn't seem to do what i need.

View Replies !
MySQL Query - 2 Steps In 1 Query?
I have two tables and the first one contains 2 main fields- 'user_id' and 'username'. The second table contains 2 main fields- 'poster_id' and 'message'. And what I need to do is lookup the user_id from the first table with the username, then pull * from the message_table if the poster_id matches the value pulled from the first table.

Now, I got this working without a problem at all but I had to use 2 queries to do it (1- pull the user_id from the first table by matching it with the username, then 2- using the first id, pull everything from the second table that matches it). Is there an easy way to do those 2 steps in 1 query? I know there must be some way since this seems like a fairly simple and routine problem, but I can't find it online or in any books I have here.

View Replies !
Count Query In Mysql Query
Is it possible to retreave all data from 1 table. and count a number of records where 1 row has the same number as id of the main table? example

Table categories
id name
1 blah
2 hello

Table Threads
id name categoryid
1 first 1
2 mid 2
3 noon 1
4 blah 1
5 roar 2.

View Replies !
Want To Remove Duplicates In A String
I have one further question about improving a validation.
Currently this will validate a string of words separated by commas, and
if it's greater than 9 will do something, or something else if less
than 9. How can I improve this, so before it does the checking remove
any duplicates in the string?

<?
$tmp = explode(',',$your_str);
if (count($tmp) > 9) {
// do something

} else {

// do something else

}
?>

View Replies !
Duplicates Appart From 1 Field.
I have a table containing 4 columns. There are a number of duplicates that have the same data in 3 columns, the 4th column is time, which is always different.

The following 'nearly' works. The time field is obviously not included.
SELECT DISTINCT `ID`, `State`,`OptUser` FROM tblStatus ORDER BY ID DESC

If I add the time, all fields are returned as they are all different.

I need to remove the duplicates. It doesnt matter which date gets removed, preferably the latest one stays, but doesnt matter.

View Replies !
Remove Duplicates In An Array
Here is my array:

$myarray = "B12@A10@C11@C11@B12@F10@B12";


Is there a function I can use that will remove all duplicates and just keep 1 instance if there is a duplicate. So in the above example my new array would be:

$new_myarray = "B12@A10@C11@F10";

View Replies !
Loop Through CSV - NOT Inserting Duplicates
we have a script that opens a CSV loops through the file and inserts the contents into a DB. is there any way to ensure we dont INSERT duplicate records?

View Replies !
Removing Duplicates From A List Box
I have written a script, that pulls the cities and zip codes from a database and puts them in a list box, for people to select from. I have several duplicates in each. How can I remove the duplicates so that every city and zip code only displays once. Here is the code I am working with.

<?
@require_once('connectdb.php');
$select = "SELECT * FROM listings";
$result = mysql_query($select);
while($data = mysql_fetch_array($result)){
$city[]=$data[&#397;'];
$zip[]=$data[&#399;'];
}
?>
<form action="search.php" method="post" name="search">
<table>
<tr><td>
...

View Replies !
What Is Indexing In Mysql And How It Will Be Useful And How We Can Retrieve Database Content Easily From A Database Table Containing About 5lakhs Datas
I need to select data from a database table containing huge amount of
data. Now I am storing data using one primary key and I am just using
simple select statement, and this process gives me the output but it is
taking long to execute the query. As much I had heared I want to use
some indexing or cluster indexing which might help me but I am not so
familiar with these things.

View Replies !
Automatically Update Database On Server Usign Php.e.g Mysql Database
I want to automatically update database on server usign php.e.g mysql database on web server and oracle is on local pc one php take data from the oracle and check on web server using the php and if some data is difference between oracle and mysql than that php page upload data on web server.

View Replies !
Getting Database Name For A Given Query
In PHP you can retrieve the table.column name of a MySQL
query doing
something like this:

$result = mysql_query($query, $dbConnection);
$resultArray = mysql_fetch_row($result);
$i = 0;
foreach ($resultArray as $data)
{
$tableName = mysql_field_table($result, $i);
$fieldName = mysql_field_name($result, $i);
$returnVal["$tableName.$fieldName"] = $data;
$i += 1;
}

The problem is that I am selecting across databases and it
is
conceivable that two tables will have the same name. How do
I get the
Database Name for a given field?

I would want something like this:

foreach ($resultArray as $data)
{
$dbName = mysql_field_db($result, $i);
$tableName = mysql_field_table($result, $i);
$fieldName = mysql_field_name($result, $i);
$returnVal["$dbName.$tableName.$fieldName"] = $data;
$i += 1;
}

View Replies !
Database Query
Needing some assistance with Joining some databases together for result display. I have been reading some of the JOIN topics in the forum and I am still somewhat lose when it comes to my example. There will be four different search types (center_name, city, state, and zipcode), obviously each search will be conducted based on that type.

my main table looks as follows:
center_id, alley_name, alley_address, city_id, state_id, zip_id, alley_phone, alley_website, alley_email

When I go to list based on the search term, I need to be able to pull the city, state and zip IDs from each of 3 seperate tables and create a listing that may have 1 to 50 or more results.

View Replies !
Query Database
I have 3 forms all located in 1 page. The code is below. All these 3 forms have got their form action pointing towards Untitled-3.php. The code of Untitled-3.php is also below.

Now here's what I want to achieve. I want each form to query different fields individually. Explained slightly differently, form1 should query the add_1 field, form2 should query the address field & form3 should query the price field. I've already got form1 to query the area_1 field successfully by using the code below: Code:

View Replies !
Database Query + Int Value
When creating a database query should an int value be inside quotes??

e.g. $query = "SELECT * FROM tbl WHERE id = '$id' ";

Is the above the correct way or is this one correct...

$query = "SELECT * FROM tbl WHERE id = $id ";

id is stored as integer in database

View Replies !
Trying To Prevent Duplicates In Preg_replace Regex
I'm trying to write a regex pattern to use in preg_replace. Basically
I want to put [brackets] around every line (
) in this variable.
However, I need to exclude lines that already have brackets or
quotation marks around them as well as lines that start with a
hyphen. Lastly the lines with ** need the brackets before the **,
instead of at the end of the line.

Here is what I have so far - it is close, but I keep ending up with
duplicate brackets.

$temp = 'this
is
a
test
"this"
"is"
"a"
[this]
[is]
[a]
test ** 93.23
test 2 ** 10.05
-this
-is
-a
another good test
'
$PATTERNS = array("/^[^"[]/m", "/[^"]]$/m", "/[
]+/", "/ **
(.*)]/");
$REPLACEMENTS = array("[", "]", "]
[", "] ** $1");
$output1 = trim(preg_replace($PATTERNS, $REPLACEMENTS, trim($temp)));
print_r($output1);



View Replies !
Is There An Easy Way To Purge All TRUE Duplicates?
I have a table with a lot of duplicate records... Is there an easy way to purge all TRUE duplicates? or do I need to write a script to do it?

View Replies !
Count Duplicates / Array Script
In table accounts_contacts, there are multiple contact_id's related to a given account_id, and I would like to count the reationships and assign the count(*) value to accounts.mao (multi agent office) Code:

View Replies !
How To Import Csv File And Check Duplicates
is there any sql code that can import csv file into your mysql db and at the same
time checked or send a report of the duplicate items? currently this is the query that i use for uploading csv file. Code:

View Replies !
Count Duplicates In A Text File
I have a script that write log id number to a text file. I have written a script to read the data line by line. What I need to accomplish is to count the number of time the id is repeated. Example of data is listed below:

37775
35707
37450
28105
28105
35527
28223
28224
28372
28373
36730
38144
37581
36201
38154
22341
36834
36540
37992
31305
26570
31662
35743

View Replies !
Random Image Stop Duplicates
i am trying to create a homepage with random images and data displayed... e.g the items picture and price.... i have managed now to do this but i get duplicates how can i stop this.. Code:

View Replies !
Mass Mailer Sends Duplicates
I wrote a mass mailer program and am having problems with it sending duplciate emails to the same email address. Sometimes it will send as many as 4 or 5 emails to the same address. I am using the phpmailer class version 1.73. I also have it set up to use a POP3 account. I am going to be changing it so that I use either sendmail or qmail depending on the server I set it up on. I have tried writign the program several different ways to try to stop it from sending duplicates, but it still does.

When I run a test with 2 or 3 emails in the test table in the database it only sends one message to each email address, but when I send out to several hundred or more email addresses it sends multiple emails to each address. It sends to all the addresses in the query one row at a time, then it proceeds to send to all of them again.

View Replies !
Remove Duplicates And Loop After Explode()
I've used explode() to seperate a string of words into a whole bunch of substrings, and now need to manipulate them a bit beyond merely echoing them out one by one. Firstly, there will be duplicated substrings, how would I go about removing them? After removing any duplicates I then need to echo all the remaining substrings as a list on my page, how would I run a while loop on them to do this.

View Replies !
MySQL Database Backup - Restore Certain Tables Into The Database
I am stuck with a MySQLdatabase backup. Now I wish to restore certain tables into the database.

View Replies !
PHP Saying Error In Mysql Syntax, But Written My Mysql Query Browser!
I have a basic db that I access with MySQL query browser. Everything
seems fine to me but I am using this db as part of a php shopping
basket and when I try to add an item I get:

Notice: Query failed: 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 '>function.extract]: First argument should be an
array in functions.inc.php on line 31
Notice: Undefined variable: price in functions.inc.php on line 36
Notice: Undefined variable: price in functions.inc.php on line 39
Notice: Undefined variable: total in unctions.inc.php on line 39

I'm assuming the last three are caused by this problem as price should
be passed to the cart, and total is worked out using it. However
although I know mySQL code it was the MySQL query browser that
actually generated the code and I cannot see a way to view or debug
the code.

The db has one table in it which is made up of id, name, subname,
desc, and price.

The code in the php file that is being referred to is:

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved