PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 14th, 2005, 07:21 AM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 14
To display fields using php multiple selection criteria on MySql database

I have a MySql database comprising of about 4000 records of 12 fields of all type varchar. I am trying to find a php script that works with a checkbox selection form with several variables, that will display a result based on the user making two or more selections. There are two fields being used to select the records, namely 'Subcat1' and 'location_cat', but when each 'location' checkbox is selected, each box actually refers to 3 or more codes which correspond to an area code. Each record has only one of these codes. Subsequently, when a selection is made, the user is asking for a category (activity) and a location (or locations) which selects records that have corresponding town codes where the activity is taking place.

However, the problem is that there is some overlap, as some groups share area codes, (see example at bottom)

I have trawled through manuals and php/MySql forum and have successfully produced a form/php script that selects fields, puts them into an array, posts to a php script, strips out leading commas, connects to the database and then makes the right selection of records if only 1 selection is made from each 'subcategory' and 'location' because I can't seem to get the code to walk through the array and process the SELECT 'foreach' value.
Here is the selection form:-
Search for:
<form method="POST" action="phpscript.php">
<input type="checkbox" name="searchitem[]" value="activity 1">Activity 1<br>
<input type="checkbox" name="searchitem[]" value="activity 2">Activity 2<br>
<input type="checkbox" name="searchitem[]" value="activity 3">Activity 3<br>
<input type="checkbox" name="searchitem[]" value="activity 4">Activity 4<br>

<br>
Select Areas to search:
<input type="checkbox" name="wheresit[]" value="group 1">location 1<br>
<input type="checkbox" name="wheresit[]" value="group 2">location 2<br>
<input type="checkbox" name="wheresit[]" value="group 3">location 3<br>
<input type="checkbox" name="wheresit[]" value="group 4">location 4<br>

<input type="submit" value="Continue"><input type="reset">
</form>
Here is the php script that I have at the moment:-
<?php
foreach ($searchitem as $svalue)
{
$search=$search.",".$svalue;
}
foreach ($wheresit as $wvalue)
{
$wher=$wher.",".$wvalue;
}
/* Remove Leading comma*/
$searchit=substr($search,1);
$where=substr($wher,1);
/*Show the selected fields and array contents to see what is parsed*/
print "$svalue<br>";
print "$wvalue<br>";
print "$search<br>";
print "$searchit<br>";
print "$where<br>";

//connect to mysql
mysql_connect("HOST","USER","PASS");

mysql_select_db("DBNAME");


if ($where){
foreach($where as $value){

$result = mysql_query("select FIELD1,FIELD9 from TABLE where (Subcat1 like '$searchit') and (location_cat like '$value')");
}
$num=mysql_num_rows($result);

//grab all the content
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];

$FIELD1=$r["FIELD1"];
$FIELD9=$r["FIELD9"];


//display the row
echo "$FIELD1 $FIELD9 <br> ";
}
?>
</table>
</html>

I am pretty sure that it messed up around the mysql_query statement for the foreach command. Also I want to know how to tackle the area groups.
For example selecting group1 looks out for records containing area codes 1 CHS,1 BIK,1 SID or 1 MOT and group2 looks out for 1 BRM, 1 BIK or 1 SHT etc etc. I would like these codes to be defined in their respective group somewhere in the php code so they don't have to be selected by the user.

So there are 2 queries here,1. how do I successfully code php to walk through the array in the selections? and
2. how do code for looking for groups of records with codes in the location_cat field that will not be duplicated when more than 1 group is selected and both groups have the same area code defined?
I am sorry my explanation might be confusing but it is difficult to express in writing what I have whizzing around in my mind!
Thankyou for any help and guidance, John

Reply With Quote
  #2  
Old January 17th, 2005, 04:12 AM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 14
This link is an example what of I'm trying to achieve:-
http://www.latitudes.co.uk/dept_search_pages/search_provence.php

Reply With Quote
  #3  
Old July 1st, 2006, 12:59 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - *Local Friend*
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 469 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 36 m 37 sec
Reputation Power: 13
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
im not to knowleagable in php, but im sure others are, therefore im replying to get this form back up and moving...

sorry i couldnt be of any help

colton22

Reply With Quote
  #4  
Old July 1st, 2006, 01:12 PM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 14
No no no! I was only joking! I'm really embarassed about the questions I asked all that time ago when php was not my life at all! I hoped that this post would be never seen again. But I must say I admire your keen approach to this forum, so don't be put off by me, just do it other people like Mittineague or MadCowDzz.

Reply With Quote
  #5  
Old July 2nd, 2006, 11:39 AM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 552 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 33 sec
Reputation Power: 14
old threads

:lol: memory flashback! I joined a year ago. My tendency is to post unanswered threads first, and then any that catch my interest in my RSS feed reader. Although I imagine some have since worked out a solution for any problem after such a time, this isn't always true. For example, I have a bunch of midi files that I wanted to play sequentially. I finally played each one (time consuming) and used settimeout to change to the next file using that amount of time plus a little to make up for slow HTTP transfers. Months later, and I'm revisiting the problem again. I have thought that maybe I could use the "complete" property and maybe eliminate the "plus a little" but as not all browsers/versions handle the complete the same it can't be relied on. It would be nice if the plug-in player could signal some script when the file was done playing and then do the change.
Anyway, as to answering old threads, it seems it can cause a maintenance problem for the forum mods http://forums.devarticles.com/sugge...eads-28002.html

Last edited by Mittineague : July 2nd, 2006 at 11:43 AM.

Reply With Quote
  #6  
Old July 2nd, 2006, 11:54 AM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 14
Did you realise Mittineague that you have joining in with answering old threads in the javascript lounge yesterday, threads that colton22 has been digging up from years before both of us has joined? Not that I knew there was anything wrong with it, he is very enthusiastic about answering javascript problems rather like a young schoolboy puts his hand up to all the math questions the teacher asks in class!

Reply With Quote
  #7  
Old July 7th, 2006, 03:51 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - *Local Friend*
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 469 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 36 m 37 sec
Reputation Power: 13
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
well i am 16 years old, sorry for embarrising you, if you want just edit your thread above so it doesnt show the thing your trying to hide, lol

Reply With Quote
  #8  
Old July 7th, 2006, 03:54 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - *Local Friend*
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 469 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 36 m 37 sec
Reputation Power: 13
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
also i think it is unique that all posts are posted by "top five" posters, Congratulations for getting that to all of ya

colton22

Reply With Quote
  #9  
Old August 31st, 2006, 10:47 AM
caretaker caretaker is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 3 caretaker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 6 sec
Reputation Power: 0
How??

Hello SnapCracker,

Could you fill me in on the solution?, I am doing a similar project and have just two days experience with MYSQL and PHP. I am completing a project where the user can find venues using drop down boxes (same logic).

Thanks

Chris

Reply With Quote
  #10  
Old August 31st, 2006, 11:03 AM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 14
Sure, I have the solution filed away somewhere. Could you give me a while to dig it out of the old archives? But if you want the scripts for a drop down menu that is abit different. go to parentpages and see if this more something you are after. There are four drop down menus which are interactive with each other by javascript; Area and category.

Reply With Quote
  #11  
Old August 31st, 2006, 02:31 PM
colton22's Avatar
colton22 colton22 is offline
\ ^_^ / - *Local Friend*
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: near chicago, Illinois
Posts: 469 colton22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 36 m 37 sec
Reputation Power: 13
Send a message via AIM to colton22 Send a message via MSN to colton22 Send a message via Yahoo to colton22
lol, though you didnt want to give the your address out, lol

it works though...


colton22

Reply With Quote
  #12  
Old September 1st, 2006, 03:48 AM
caretaker caretaker is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 3 caretaker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 6 sec
Reputation Power: 0
Re:

Quote:
Originally Posted by SnapCracker
Sure, I have the solution filed away somewhere. Could you give me a while to dig it out of the old archives? But if you want the scripts for a drop down menu that is abit different. go to parentpages and see if this more something you are after. There are four drop down menus which are interactive with each other by javascript; Area and category.


Yes sure, thanks. hmm the parent pages site is interesting, actually a bit more complex than I need. I basically need the values of the drop down boxes to be used as the search variables so in that sense I think it is similar logic to the radio buttons, in fact probably less complex.

Reply With Quote
  #13  
Old September 2nd, 2006, 09:30 AM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 14
No, caretaker, with drop down menus you end up with one value, but with multiple radio buttons, you might end up with loads which you must present to the php script file as an array. That's why I asked if you were sure what you wanted. If you were to use the radio buttons and post the info to the script you would use something like:

connect to the database

foreach ((array)$searchitem as $search){
foreach ((array)$wheresit as $where){

$result=mysql_query("select * from table where field1 like $search and field2 like $where")

while($r=mysql_fetch_array($result)){

$first=$r["first"];
$second=$r["second"];

echo the $first and $second fields


++$r;
}

It was something like this, I'm only going by memory!
Hope it's useful
and Colton...well it gives a hit!

Reply With Quote
  #14  
Old September 5th, 2006, 06:23 AM
caretaker caretaker is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 3 caretaker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 6 sec
Reputation Power: 0
Thanks for your help SnapCracker, a simplified solution I came up with for a basic search of two drop down boxes is:

<?php

$var = @$_GET['Number'] ;
$var1 = @$_GET['Name'] ;
$trimmed = trim($var);
$trimmed1 = trim($var1);

include("Connect.php");

$query = "SELECT * FROM album WHERE ArtistID LIKE \"%$trimmed%\" AND AlbumName LIKE \"%$trimmed1%\"
ORDER by AlbumName";

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);

while ($row= mysql_fetch_array($result)) {
$title = $row["AlbumName"];

echo "$count.)&nbsp;$title" ;
$count++ ;
}

It is more advanced than this, with 10 result per page (from tutorial) at the mo, but I will probably simplfy it!

Chris

Reply With Quote
  #15  
Old September 5th, 2006, 06:44 AM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 14
Ah! so you are in the UK, where else would they say " at the mo". Are you doing some sort of computer course or as a hobby/fun? I have been a datacomms tech for 15years now and would like to get into web developing instead. There are experts on this forum, but I am just learning stage at the moment, however I have picked up quite a bit from these Canadian/US/Dutch experts and it has been a pleasant experience as well. Thanks for the interest Chris. Cheers and good luck!

Reply With Quote
  #16  
Old April 23rd, 2009, 10:37 PM
allozysob allozysob is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Location: Switzerland
Posts: 7 allozysob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 44 sec
Reputation Power: 0
Send a message via ICQ to allozysob
Aux amateurs de Recherche

Yoo ! Ca fait un bou que j'vous li mais l je deecide de m'abonner pour vous demander c'est quoi l'adresse web au juste du magasine plein air plein air . J'ai entendu par la bande qu'il y a un tas d'affaires faire sur ce site..! Merci!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > To display fields using php multiple selection criteria on MySql database


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap