![]() |
Removing Search Results from drop down
Hi i had a little question I was wondering someone might be able to answer. Right now i have a code that searches through the database and outputs results based on the search...then below I have a drop down menu that grabs data from the database to fill it. It works perfectly I was just wondering if there was a way that I could eliminate the first results from showing up in the drop down menu. I hope that made sense...i'll post the code that I have....any help is greatly appreciated.
PHP Code:
Thanks so much |
I always like to use for loops, I always feel like I have better control over the data...here's what I would do...but I'm sure others could provide a simpler answer using WHILE...
PHP Code:
|
Perhaps you could use
mysql_data_seek before you begin to output the results. Normally it will begin at row 0, however by using that function, it will place the pointer to anywhere, so it could start at 5, if you wanted it that way.php Code:
|
Thanks for the responses but i don't think they are going to work...maybe i didn't explain myself good...
I have two tables TABLE 1: postalcode (based on info added by user) postcode (user entered) cat_name (chosen from the list in the category table) status (once user completed the above information this is changed to used) TABLE 2: category (contains a complete list of pre made categories) cat_id (just basic numbers) cat_name (the categories that were pre populated there is like 50) Now the first sql statement uses the postalcode table and outputs all the cat_name that are in a specific postal code Example: CAT DOG PIG Below that I wanted a drop down menu with the complete list of categories from the category table but eliminating the ones already used (ie CAT DOG PIG would not be in the drop down) My thought was that maybe it could be done by maybe an inner join and comparing the the cat_names and if they are the same not to output...but i can't get it to work... Or maybe store the results of the first sql statement into an array and then compare the results of the second sql statement against the array and output accordingly. i'm not that amazing at php i'm still learning...just by code online and playing around so I may totally be off base. But hopefully this gives you a better understanding and more information on what I am looking for. Thanks again |
Quote:
|
Since I don't know exactly how your DB is structure, you could go with your second idea of storing the output into an array. Then compare what's in the array with your second output and don't show if it's in the array.
So create an array like so: $first_list = array(); Then in your first query/output. $cat_name = $rs['cat_name']; Dump the names into that array. $first_list[] = $cat_name; Then in your second query, you can compare the value in the $first_list array and just not output anything that matches... |
Just to note, you can probably save yourself a query by pulling all the data you need at once from the first query.
Then you can store the data that you need for the second output in an array which already has the duplicates taken out. Then for the dropdown, you simply loop through the array instead of calling another call to the DB.... |
Hey I really appreciate your help...
Your idea sounds good... unfortunately I haven't really worked with arrays too much...so this is kinda my first time and I'm not sure how to go about what your talking about. I tried the first idea but then i was having trouble trying to write the second query. Sorry to be a pain |
Quote:
Pain? No, no pain, you should see what I do to the others around here with all the questions I ask....haha.... We will solve your issue. It's really not hard I know what you're trying to do... In your first query, within your WHILE loop. You have this: PHP Code:
PHP Code:
with: $first_list = array(); Then in your second query/output and your WHILE loop just check against the name and don't output if it's listed.. PHP Code:
This should work for you.... |
Thanks
I did exactly what you were saying...i didn't change anything else...except now i get an error at this line PHP Code:
Quote:
I'm losing my mind...lol |
Quote:
Let's try this instead... PHP Code:
|
Man oh man...
still giving me an error.... at the same line I've gone over and over making sure i have all my semi colons and opening and closing { If i remove the if statement then it works with no error...but if i put it back then i get the error... even if I change the statement completely to something very basic it still gives me the error I guess i should just give up on this idea...didn't think it was going to be this hard...just thought it would be a good idea not to have the duplicates. But it's making me lose my mind! lol Thanks for your help. Greatly appreciated |
Quote:
Could you please post your latest code? |
Ok so i decided i would start again just to make sure everything was good...
so this is what my code looks like...hopefully i followed what you said correctly PHP Code:
Now when i run it I get a new error Quote:
PHP Code:
So now i'm not sure what's wrong...i tried looking up the error but none of the answers seemed to work or relate to mine. |
Your code shows this:
$first_list[]*=*$cat_name; What the heck is that? It should be: $first_list[] = $cat_name; |
It doesn't look like that in my code
for some reason when i copy and pasted it in here *'s starting showing up...i thought i had edited them all out...but i guess i missed that one sorry....but it doesn't look like that in my code. it looks like this... $first_list[] = $cat_name; |
Quote:
Anyways, I did a mockup of my code and it worked for me so I'm not sure why it's complaining for you... What I can do is post an example if you'd like, it will take me a little while because I would have to replicate your DB structure, but hopefully that should help you out? |
Sure thanks...i'd appreciate that
|
Kay:
I have the 2 tables created. If you can please give me some example data, I can populate them and we can put this issue to rest. Just give me about 10 data results for the postalcode table and 10 for the category table. That should be enough, and I can then do the dropdown and output..... |
hey i put together some example data...hopefully it makes sense i didn't know how else to write it out
TABLE category cat_id | cat_name 1. 1 Bedroom 2. 2 Bathroom 3. 3 Kitchen 4. 4 Living Room 5. 5 Office 6. 6 Garage 7. 7 Family Room 8. 8 Property 9. 9 Attic 10. 10 Basement TABLE postalcode postcode | cat_name | status 1. B0H Bedroom used 2. X1A Bathroom used 3. X1A Kitchen used 4. R4A Living Room used 5. G2M Office used 6. B0H Garage used 7. R4A Family Room used 8. G3A Property used 9. B0H Attic used 10. X1A Basement used thanks |
| All times are GMT. The time now is 03:40 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0