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




How Do You Select Unique Instances Of A Field Entry?


If I want to select and display the 'county' field from a table for all records, I'll get a list of records, many of them repeated.

How do I select and display only one instance of each record, effectively cutting out all the duplicates?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Unique Value In Field
I'm trying to do a query of PHP on MySQL, basically searching a field, varchar field it is...and basically I only want it to return the first occurence of a value..

Say:

ID Text
1 Hello
2 Hi
3 Hello
4

I only want it to return ID 1 not 3, is this possible??

Retrieving Full Entry From Multiple Select List
I have a list box with multiple selects. I define the name as numList[]. I
get the values from

$picked = $_POST['numList'];

It retrieves values for all those selected.

If the entries are, say,
First
Second
Third

and the first and third are select then $picked[0] has "First" and
$picked[1] has "Third".
If, however, the entries are:

First one
Second one
Third one

Then the values are for $picked[0] and $picked[1] are "First" and "Third"
respecticely.
How do I retrieve the entire value and not just the first word?

MySql Select Unique Rows?
I am have a table which contains recent search querys of another table.

I am tryng to output this data into a list so the user can click, and re-run a recent search...

The problem is that the table is full of duplicate searches from the same user.

How do I select the searches without retrieving duplicates?

SELECT id, term FROM project_term WHERE pid='$_SESSION[project_id]'

Also, would it make more sense to store all serches of a paricular user, or stop the insert if the record exists? Is there a way I can do this without performing 2 queries (ie adding some sort of LIMIT or other xeyword to the INSERT query?) I can't make the column unique because two users could perform the same search...

RegExp - Removing Newline/carriage Return In Data Entry/form Field
I have a database generated calendar (written in php) which puts the contents of one of the fields in a javascript mouseover popup ( Carriage Driving World and select "Calendar" from top menu) which is populated by event organizers entering data via a form. Some people are putting line feeds in their EventDesc (field used for javascript mouseover popup) which screws up the javascript, where linefeeds/newlines aren't allowed.

The best solution I can think of is to either remove the linefeeds before the data gets stuffed into the database or when the data is presented to the javascript coding.

Here's where I need help. What RegExp string do I use to pull linefeeds/returns? Some of teh entries have more than one which needs removed.

MySQL - Select Specific Row Based On Unique ID
I am building a photography website in html, and have a pre-formated table in which i want to put a thumbnail pic, the date of the pic, the name, and links to different sizes of the image. In a MYSQL database i have a table with four columns: ID (INT, auto-increment), ImageName (VARCHAR), FileName (VARCHAR), Date (VARCHAR).

I'm just getting started with PHP, and i want to either:

have the information automatically inserted into my pre-made table via a php loop command

or

write a script which will allow me to only enter the id# and will subsequently insert the name and the date into my table, and which might display the image of the filename.

I hope this is clear enough, I've bought quite a large book on PHP and have been browsing forums in an attempt to learn, but i can't find an example that inserts it into a pre-existing table.

Select All Unique Collumn Entries In Mysql
Can anyone tell me how you can query mysql for all unique entries into
a particular table collumn. Ive checked the manual but had no luck!

Select Both Field Name And Field Value- Mysql ?
What function to use to select both field name and field value from a mysql table ?

Array To Select Field
I need to echo the contents of an array to a <select> field.
Whatīs the easiest way to do that?

I could just:

<select name="blaha">
<option>$array[0]</option>
<option>$array[1]</option>
<option>$array[2]</option>
</select>

The problem is that the numbers of "parts" (I donīt know what they are called) in the array is different from time to time, so first I need to check if itīs empty or not, and if it isnīt, echo it.

Having 1 Select Field Enable Another
I want to create a php script that displays say (for the purpose of adding to database):

Customer Id # (as a select)
Email (as a select)
two other fields

a customer may have more than 1 email, but each email is unique as is the customer id #
i know how to populate the customer id # from the database but is there a way (without creating a new script and passing it customer id # (storing it as hidden in the next scripts form, and then limit the emails listed)) to disable the email select until the customer id # has been selected (which then populates the email select and enables it)
in other words is there a way to do this in 1 script?

Auto Select Field
I have a contact form in php and want the first text field to be auto selected, my field is called 'First' id= First. is this php or java script?

Select * From Table When Field Is Less Than 3
i think it simple but i want to select all db entries where a certain field is less than 3?

Select From Table Where Field = String
How to select all lines containg a string (located in $pastmove) in the
moves column.

I tried several ways, for example:

$requete="SELECT moves, opening_id FROM suitemove where moves like
'%".$pastmove."%'";

but did not succeed;

How Do I Select The Last Field Of A Mysql Table ?
how do i select the last field of a mysql table ?

Select Only Rows Where Certain Field Is Empty
Basically i need to select the rows from a table where the user is "$curr_user" and the "seen" field is empty. Then i want to count the rows and use the count in a javascript alert. Heres what i got so far: Code:

How To SELECT Records WHERE Field Contains A Particular String?
I need to SELECT records WHERE a string matches the content of a field...

eg. I have field values like:

Phone namePhone name pinkPhone name bluePhone name polka-dot
What I want is to have a MySQL query which selects ALL records which match the search term, eg. 'Phone name' returns all of the above, but not 'Phone':

Currently my query looks like this:
SELECT * FROM [table_name] WHERE [field_name] LIKE '%s' ORDER BY [value] ASC

Automatic Select Form Field Default
I would like to allow registered users to my site the ability to change your personal information. Let's say the country in which they are in.

The country field is a drop down list. So its supposed to read from the table and make the value the default. How am I going to do this?

Hidden Input Field Inside A Select?
I need to get a field from the database and attach it with the loop that is created around the <select> options, however doing a hidden field won't work, as it isn't detected when in a <select> Code:

Populating SELECT Multiple Form Field And Inserting Into Db
I have an update form where I'm trying to populate a SELECT multiple field with a list of 48 categories, from tbl work_cat. And show, as SELECTED, the one or many choices that the user had previously selected from the 48 categories which are stored in tbl cat_relations as $relation_cat.

Then allow the user to update their selections and update the database. But I can't get my form to work. First problem, I can't get the SELECT field on the form to show the categories, and then I don't know where to go from there. Below are my form page and my processing page. Code:

Update If Unique User And Unique Id?
I have a site which lists some links on a page.Each link gets parsed to "/out.php?entryid=x" When they do this, my out.php updates the number of times that has been viewed It then pushes them on to the appropriate link.

To prevent "gaming" of the link count, I want to try and use the IP or a session or something that will mean users can not inflate the count of any one link by more than 1. Code:

Populating A Second "select" Field
is there a way to populate a second select field in a form based on input for a first select without reloading and using only php? Code:

No Array Entry Vs Null Array Entry
Consider this statement related to Fields sent to PHP via an HTTP POST.

$A = $_POST["FieldName"];

If the page did not have a form field with FiledName, the result is
that $A is empty.

If the page DID have a form field with FieldName, but the field was
left empty, then $A is empty also.

How should I test $_POST to distinguish between these two conditions.

IE Hangs In Certain Instances
To anybody experienced using Filemaker FX, any possible help would be
appreciated.

When the script dialogue box is open on the client and one tries to access
via the web, IE hangs up. Is there any way to trap for this condition?

It appears to hang up when the following line is being performed:

fputs ($fp, $socketData);

Count The Instances...
Is there a PHP function that counts the number of time something appears in a MySQL query? So I run the query, and it finds the number of times "[page]" is found in the returned results.

How Many Instances Are Working?
which is the cleanest way to know how many instances of a certain php are currently working on the server? is there a server variable for that? if not, how do I know (via php) how many concurrent accesses are there on a certain php page?

PS: I know how to do that for mysql (the "SHOW PROCESSLIST" command), but I need a similar function for the php page iself.

Two MySQL Instances In One Server
Would it be possible to have two MySQL instances running on one server
(each having different ports) and then have only one running Apache
server with PHP?

I have tried this once but PHP can only connect to one MySQL server
because it can only read one socket file at a time. As much as
possible, I would prefer a purely mod_php solution as opposed to one...

PHP Instances Writing To The Same File?
I read in Programming PHP (O'Reilly) that flock() "cannot prevent two
PHP scripts running in the same web server process from accessing a
file at the same time".
In my case a single PHP script appends text strings to an existing text
file. Several clients may trigger the same script on the same web page
and thus more than one PHP instance might try to open and append text
to the same file at the same time. I would assume that using flock()
_does_ in fact prevent simultaneous access in this case. Am I correct?


Sessions Across Browser Instances?
I've hit a problem with sessions.

If I have a document relying on sessions which has a link target=_blank
then the new window inherits the session from its parent (in IE).

However, if I embed an instance of IE in a VBA form in Excel and click
on the link, the new window doesn't inherit the session.

I have no idea why this should happen at all since both instances of the
browser have access to the same cookies.

Can anyone tell me how to inherit a session like that? I've tried
passing over $PHPSESSID without any success (PHPSESSID is set correctly,
but $_SESSION is empty)

Please Help: Prevent Multiple Instances
How can I prevent a script from running when a previous instance of
the script had already been triggered and the script is running in the
background already?
So, even when a script is startet several times (eg. by several
website visitors) I want only one script-instance running on the
server. Subsequent instances should be exited (or prevented) right
away to keep the server load as low as possible.

However, when no instance of the script is currently running (eg.
after a server shut-down), triggering the script should make it run -
but again: only one instance should be running at all times. Further
script calls, as said above, should then not be allowed.

List All Instances Of A Class?
am writing a script which dynamically creates
instances of a class with names like $object1, $object2, etc.. I now
want my script to be able to list all of the objects which are instances
of a specific class -- but I haven't been able to find any code which
does this in the online PHP references I've consulted. Given that the
names of the objects are predictable, it would be possible for me to
write some code which looped sequentially through the object names
$object1, $object2, etc., until it reached an object name which didn't
exist. However, I was expecting there to be a tidier, easier way of
doing the same thing with a command that says simply "List all instances
of class X."

Could you please tell me how to do this, or why it is not possible?

How To Count The # If Instances An ID Is In A Table?
I am trying to count the # of instances where an ID appears in a table. I have a city table where each city has an id and a region id, a region table where the region has an id. I want to be able to count the # of cities are in a region by id. Everything I've tried is either 0 or 4, no clue how I got 4, even though I verified that none of the regions had only 4 cities. Code:

Counting Number Of Instances
I have a table surv_item and a field of "name"

in the name field, I would like to count the number of instances that name appear how would I go about in doing that?

Can You Have Instances Of Classes Within A Class?
I wanted to know how you can have instances of classes within a class?

Finding Multiples Instances Of An Expression
Im trying to expand a search util by uing regular expression to allow
common search criteria such as +-* and phrases "".

My understanding of ereg(string pattern, string string, [array
registers]) is that the array register should collect all instances
that match the pattern.

Heres is an example of the code:

$word4 = "+budgie +ferret dog."; //set phrase

$regexp = "+[0-9A-Za-z]+"; //assign pattern

if(ereg($regexp, $word4, $reg)){ //test for true result
for($i=0;$i<count($reg);$i++){ //loop through array result
echo "<b>finding multiple instances.:</b> Found string '$reg
[$i]'<br>"; // echo result
}
}else{
echo "<b>finding multiple instances.:</b> $regexp not found"; //
echo if none found
}

This is succesfully finding the first word but id does not find the
second word.

Array Of Instances Inside Constructor
keep an array of all
of its instances? This was my first and obvious first shot...

class A
{
function A()
{
static $a = array() ;
$this->array =& $a ;

$this->array[] =& $this ;
}
}

But, if I make changes to the instance contents (not included above)
they are lost when I eventually try to use the array of references.

Session Variable And Instances Of Classes
What are the drawbacks, limitations, etc. of referencing/manipulating an
instance of an object across calls via a session variable?

PHP Multiple Instances / Sessions Question
I am currently running 2 instances of a web application on the same
server.
one of them has address http://www.justanexample.com/prod and the other
has an address of http://www.justanexample.com/ipeer_demo. By logging
into the demo with the guest passwords, the address becomes
http://www.justanexample.com/ipeer_...on=Student.home.
I can get into the production instance by simply changing the base url
to http://www.justanexample.com/prod/i...on=Student.home and
hitting enter. I'm sure there are quite a few solutions to this, but
what do you think is the most secure way of overcomming this problem?

Return All Instances Of A String Within A Page...
I'm looking to do this, but is it possible?:

A page to be downloaded via file_get_contents which has stuff similar to
the following in :

<a href="file.php?name=Widget1">Widget1</a><br>
<a href="file.php?name=Widget2">Widget2</a><br>
<a href="file.php?name=Widget3">Widget3</a><br>
etc.

I would like to be able to create an array which contains all the strings
between <a href="file.php?name=Widget1"> and </a><br> (The link text)

so
<a href="file.php?name=Widget1">Widget1</a><br> => Widget1

So that $linktext[0] = Widget1, [1] = Widget2 etc.

Is this possible, if so, how?
I've looked at preg_match_all, but can't see how to output multiple matches
of text *between* two strings to an array.....

Sharing Instances Over Requests/sessions
Is there a mechanism within PHP for sharing data over
multiple requests that are not tied to a specific session.

I need to write a memory senstive cache in pure PHP. I
have an application which needs to store documents
from an application server elsewhere, due to the data
within the documents I can't write them to disk and I
have to minimise the amount of accesses to the server.

So my plan is to write something to store the documents
in a cache avaliable to all requests and store an access
key in the session. When a request is made for a
document that is not in the cache I'll do a quick check
to see if I need to free some space before I add the new
document. However the actual docs to remove will most
likely belong to a different session.

The question is, how do I create an instance of my cache
so it is available over different requests and users.

This was a trivial exercise in a java servlet, however
I now need to use PHP.

Multiple Instances Of Body Tags In A Page Due To The Includes Each Having A Set.
This is not the way it's supposed to be, is it... ok then for me just
to remove the body tags from the include files, it'll all work ok? I
don't know php and I'm working with a webmaster who, I suspect,
doesn't know it too well either.

Multiple Php.ini Instances - Configuration Tree Errors (PHPIniDir)
We're running multiple vhosts in an apache-2.x configuration for which
we would like to provide separate php.ini files (for different
reasons).

At the moment, we're unable to do this - the error I'm seeing is:

Starting httpd: Syntax error on line 87 of
/etc/httpd/conf/vhost.conf.admin:
Only first PHPINIDir directive honored per configuration tree -
subsequent ones ignored
[FAILED]

So my question here is in a couple of parts. One, is it even possible
to do what I'm trying to do... and what is a "configuration tree" -
does that refer to the entire instance of the apache server itself. Is
it possible to have more than one "configuration tree"s.

Function To Check For Multiple Instances Of A String In An Array?
I need to check if there are more than one of the same string in an array. Does anyone know of a function?

Can A Field Communicate To A Server And Return Information To Another Field Without Retrieving The Whole Html Code Again?
Iīve got a sql table which has 3 fields.
Their relation to each other is like this example.

| CARS | YEAR | PRICE |
ford 2000
ford 2001
ford 2003
volkswagen 1999
volkswagen 2000

I am developing an ASP web page that modifies a specific registry.
So, it loads the information to some fields, but the user will be able
to change only the "PRICE" field.
I have to create two selects, one for "CARS" and other for "YEAR".
But the "YEAR" field will only contain the correspondent years for each
car the user selects. Example: selecting "ford" in the "CARS" <select>
box, only the years "2000", "2001", "2003" would be automatically
loaded in the "YEAR" <selec> box.
How could i implement it?

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.

SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

How To Update A Table's Field With Another Tables Field?
I need to take the state field from dt_profile table and update the dt_matchfinder with this state making sure the member_id field matches.

the problem is the dt_matchfinder table has null set for many of the state field but in the dt_profile each member ID has a specific state and I need the same to be true in the dt_matchfinder table.

PHP To Query Only The Last Entry
How could i make it in the PHP to query only the last entry of a certain column.

example column
Interest
2.5
1.3
4.4

php will extract 4.4, and when a data is enter to that column

Interest
2.5
1.3
4.4
5.0
php will query 5.0 by now

i use mysql_affected_row() but it is not the final outcome.

Mail() And An MX Entry
I am having a problem with the mail() function. Specifically, I have a client who has a MX account set up. They have a site set up on a remote server with a local server handling their mail.

The mail() function will send mail to myself, however, when I set it to someone on their sever, it sends it to the remote server, igoring the MX entry, and therefore stranded on the remote server in the catchall.

Crontab Entry
How can I have cron back up my database to a new file name each time Ex: db.001, db.002, db003....etc ? What would really be nice is if I could append the current date to the file ? Ex: "db.10-26-00" current crontab entry:

02*** mysqldump -u root -pZXCC helpdesk > /mnt/zip/db.backup

Reading Last Entry Only
I am sending data to a text file, and displaying the data on the return page. Then it emails that entry only. (this works fine) But when I call the second page, it displays everything in the text file. Is there a way to to call the last entry to the text file only?


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