Buy Sell Discuss UK Domain Names at AcornDomains.co.uk

Today's Drop Dates are: 19-02-2012 or 26-02-2012   All times are GMT. The time now is 12:42:42 PM.
Domain Name Sales Domain Software Calculate UK Domain Drop Dates Domain Registration NameDrive Domain Parking Subscribe to our Domains For Sale newsletter
Go Back   Domain Forum Acorn Domains Buy Sell Auction UK Domains > Website Design and Promotion > Website Design > Scripts and Coding
Connect with Facebook

Scripts and Coding PHP, MySQL, scripts

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 05-08-2010, 06:17:38 PM     #1 (permalink)

 
woopwoop's Avatar
 
Join Date: Jan 2007
Posts: 1,586
woopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond repute

php help? (unique unserialize)

Need a bit of help with some php and a few kind members helped me in the past.

My code is:
PHP Code:
$query "SELECT names FROM table WHERE type='$type'";
$result mysql_query($query) or die(mysql_error());

while(
$row mysql_fetch_array($result)) { 
foreach(
unserialize($row['names']) as $key => $value){ 
echo 
$value '<br />'


Basically, a field on my table is called names. The information in this field is serialized (so many names are together in a single field, for a single row).

I want to be able to search the whole table (where type='$type' - so many rows) for all names and then show unique names only.

My code above unserializes the names from each field and then lists them, but doesn't deal with any duplicates (which I need removing).

I have looked at functions like "unique_array()", and have tried using it in different places but it isn't doing the job.

Any help appreciated.
woopwoop is offline  
Old 05-08-2010, 06:54:21 PM     #2 (permalink)
Member
 
Join Date: Apr 2010
Location: Buenos Aires
Posts: 83
JDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond repute

PHP Code:
$new_array = array();

while(
$row mysql_fetch_array($result)) { 
    foreach(
unserialize($row['names']) as $key => $value){ 
    
//echo $value . '<br />'; 
    
$new_array[] = $value
    

}

$unique_array array_unique$new_array );
var_dump$unique_array ); 
Try this quick fix...
JDubya is offline  
Old 05-08-2010, 07:08:50 PM     #3 (permalink)

 
woopwoop's Avatar
 
Join Date: Jan 2007
Posts: 1,586
woopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond repute

Many thanks for your reply jDubya.

I just took someone's advice on another forum and the following code worked:

PHP Code:
$names = array();
while(
$row mysql_fetch_array($result)) { 
   
$names array_unique(array_merge($namesunserialize($row['names'])));
}
foreach(
$names as $value){ 
   echo 
$value '<br />'

Will take a look at your code later. I love PHP but the more i learn the more i don't understand!

Appreciate your help.
woopwoop is offline  
Old 05-08-2010, 08:27:02 PM     #4 (permalink)
Member
 
Join Date: Apr 2010
Location: Buenos Aires
Posts: 83
JDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond reputeJDubya has a reputation beyond repute

Your welcome - one thing to keep in mind though is that a solution like this doesn't scale well so on a larger data set performance would degrade massively... If working with larger data sets the DB should be doing the work instead of PHP.

My problem when I first started learning PHP I wasn't properly shown Mysql - didn't learn for a long time things like EXPLAIN, INDEXES, DISTINCT(), DATE_SUB() etc instead of relying completely on PHP. Probably the single most useful period of learning I went through.

Good luck!
JDubya is offline  
Closed Thread



Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Domain Name Community Replies Last Post
unique seo minisite offer /3 review copy going cheap domain7172 Mini Sites 1 16-01-2010 05:07:32 AM
PHP include in a Smarty Template admin Scripts and Coding 1 13-05-2008 06:37:26 AM

Web Hosting from UK2 from just 99p


All times are GMT. The time now is 12:42:42 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 RC 2
All content on Acorn Domains is member generated and is not moderated before posting. All content is viewed and used by you at your own risk and AD does not warrant the accuracy or reliability of any of the information. The views expressed are those of the individual contributors and not necessarily those of AD. Please contact us to report any issues or send a PM to "Admin".