Re: MySQL / PHP Database Help
| From: | DL Neil | Date: | Fri, 08 Feb 2002 14:30:04 +0000 |
| Subject: | Re: MySQL / PHP Database Help | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-16679@lists.php.net to get a copy of this message | ||
Jonathan,
I'm trying to write a script that checks for multiple entries on a table in a database. So far
I've been
plagued by MySQL errors. I'm fairly confident my scripting is ok (Then again, I've been
wrong before.) I think
moreover there might be some difficulty with my theory. Then again, I could try and do this with
MySQL join
statements. Any feedback would be appreciated.
...
Warning: Supplied argument is not a valid MySQL result resource in
/home/ufr2/underfoot-www/admin/dupeshows.html on line 51
I notice that others have addressed your PHP/interfacing issues...
You asked about "theory". The current solution will require n+1 calls to the database
(where there are n-rows in
the local_shows table). That's quite 'expensive'.
Which is likely to be the 'best tool for the job' - an external scripting language (PHP)
or the RDBMS itself
(MySQL)?
Consider a 'MySQL-oriented' solution:-
1 if the two fields (show_date and venue) were made into a UNIQUE index, then the check would become
superfluous
because MySQL would ensure the situation never arose - at the cost of the time to perform the
check/index
insertion at every row INSERT or UPDATE (although you may gain a speed increase for certain SELECTS)
2 performing the existing PHP routine using SQL - you show only a list of 'duplicates'
(and no DELETE), so:
select show_date, venue, count(*) as freq
from local_shows
group by show_date, venue
having freq>1
will give you what you have attempted to code thus far.
(you may wish/need to juggle the sequence of show_date and venue to suit)
Regards,
=dn