Solved

Query Tricky Distict

Posted on 2013-01-07
6
128 Views
Last Modified: 2013-03-22
Hello,

I am using the below query to find all of the trails someone has traveled.

I have the trails stored like:

id|trail
1|trail1
2|trail2
3|trail1, trail6, trail2
4|trail3
5|trail2, trail5

The problem is that they were setup as one per field but now we have a multiselect so they have have more then one in a field and they are separated by ', '.

$result3 = mysql_query("SELECT DISTINCT trail FROM cms_activities WHERE user_id = '".$_COOKIE['member_id']."'") 
or die(mysql_error());  

$trails = mysql_num_rows($result3);

Open in new window

0
Comment
Question by:movieprodw
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:Rimvis
ID: 38754617
Hi  movieprodw,

You can try this approach:

MySQL String Splitter
http://www.tero.co.uk/scripts/mysql.php
0
 
LVL 1

Author Comment

by:movieprodw
ID: 38873369
I am sorry but I still can not figure this out, I have tried the method you sent but I can not find the common ground using just one table.

Would love some help
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 38878125
There are approaches that are using cursors to process the string. This one for example:
http://stackoverflow.com/questions/3908966/mysql-procedure-to-load-data-from-staging-table-to-other-tables-need-to-split-u/3909888#3909888

But I would stick to the original solution. You could create a table with sequential numbers and use it in your SELECTs. Is there something that prevents you from doing it?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:movieprodw
ID: 38881318
Well all the data and code is there and I only have access to the page that retrieves the code.

I wonder if there is a way to pull the rows, break them up and store them in an array then count them?
0
 
LVL 19

Accepted Solution

by:
Rimvis earned 500 total points
ID: 38882305
Does that mean you can't create any database objects, like tables and functions?

Of course, you can do it at PHP side, with explode function for example:
http://php.net/manual/en/function.explode.php

But I'm not a PHP expert, I wouldn't be able to help you further with that.
0
 
LVL 1

Author Closing Comment

by:movieprodw
ID: 39012541
Thanks for your help
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now