We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,324 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

compare and hide

I have a drop downmenu on a page, after users add a content to the db,
i do not want the specific value that was added
from the dorpdown menu to show in the list again.
I do not want to delete that specific value from the dropdown table.
Your help will do.

Here is my code below:

                                     `<?php
                                             $query = "SELECT * FROM vreg_no order by vreg desc";
                                            $rs = mysql_query($query);
                                            while($row = mysql_fetch_assoc($rs)) 
                                            {{
                                                $_SESSION['svregx'] = $row['vreg'];
                                            }}
                                     ?>


                                     <select name="svreg" class="bodytxt" id="svreg">
                                      <option>Select Vehicle #</option>
                                            <?php
                                            $query = "SELECT * FROM vreg_no order by vreg desc";
                                            $rs = mysql_query($query);
                                            while($row = mysql_fetch_assoc($rs)) 
                                            {{
                                              $vreg = $row['vreg'];
                                            if($_SESSION['svregx'] == $vreg){
                                                //do nothing
                                            }
                                            elseif($_SESSION['svregx'] != $vreg){
                                                echo"<option value='$vreg'>$vreg</option>"; 
                                            }else{}
                                            }}
                                            ?>      
                                            </select>`
4
Contributors
12
Replies
3 Days
Discussion Span
6 Months Ago
Last Updated
13
Views
dannybarh
Newbie Poster
20 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This looks a bit mashed up to me.

I don't understand what the first bit of code does. You're looping through a recordset, but you keep overwriting the session variable with each iteration. And BTW, just use a single set of braces for loops: { ... } not {{ ... }}

Your second loop has all that messy conditional code:

if($_SESSION['svregx'] == $vreg){
  //do nothing
}elseif($_SESSION['svregx'] != $vreg){
  echo"<option value='$vreg'>$vreg</option>"; 
}else{
}

You just need this:

if($_SESSION['svregx'] != $vreg){
    echo"<option value='$vreg'>$vreg</option>";
}

However, I can't see how you are going to get this to work.

diafol
Keep Smiling
Moderator
10,832 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,533
Skill Endorsements: 61

Hi can you rephrase your problem i really dont understand =)

code739
Posting Whiz in Training
210 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

ok, i select * from a table call vehicle_info,this works fine.Now in my dropdown menu,I have vehicle registration #s in it.When an entry is made,the vehicle registration #s is enterd in to vehicle_info.Now am trying to avoid the case where i don't have to use that same vehicle registration #s from the dropdown menu to make another entry again.I thought of deleting it from the vehicle registration table from whtere i porpulate my dropdown menu,but will mean will have to porpulate vehicle registration table all the time.
So what am trying to do now is compare the vehicle registration #s that i select from vehicle_info table with that of the dropdown menu on the same page,if its the same then it should not echo it, else it should echo it.the app have only one user.

dannybarh
Newbie Poster
20 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This is a bit strange. You populate the select element with numbers from vehicle_info table and then store the chosen number into the same table. You should have a source for the select element somewhere else (maybe some other table) otherwise you keep running in circles. Or have I missunderstood something?

broj1
Nearly a Posting Virtuoso
1,216 posts since Jan 2011
Reputation Points: 167
Solved Threads: 165
Skill Endorsements: 13

Thanks Broj1 for coming so quick.
vehicle_info table stores all vehicle informatiom.Here is table Structure

    id
    ymodel
    chassis
    color
    fleet_no

Then,a table call fleetNumbers which contain unique fleet numbers of each vehicle on our fleet list.Now when an entry is made, i do not want the fleet # that was selected and entered when the entry was made to still show in the dropdown menu that is populated by fleetNumbers on the add vehicle page.There is already much data on vehicles in the db.

dannybarh
Newbie Poster
20 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

So do you get fleet number from the fleetNumbers table? What is the structure of this table? This table has not been mentioned in your previous posts at all.

broj1
Nearly a Posting Virtuoso
1,216 posts since Jan 2011
Reputation Points: 167
Solved Threads: 165
Skill Endorsements: 13

structure of fleetNumbers table

id | fleetNumbers

I was trying to keep it simple,that is why i didn't mention it in my previous posts.

dannybarh
Newbie Poster
20 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

do you think there is an other way that i can do this?

dannybarh
Newbie Poster
20 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

SO to get this right:

TABLES

Vehicle_info

id | ymodel | chassis | color | fleet_no

fleetNumbers

id | fleetNumbers

vreg_no

id | vreg

I'm assuming the following relationship:

fleetNumbers.id (1) -> (many) fleet_no

However, I'm unclear as to how the vreg_no table is related to the vehicle_info table.

BTW - usually a good idea to avoid using the same table and field name as this can result in confusion. Also, when describing a problem, use the same table names and field names that you use in your code.

So to clarify again, which table provides the dropdown info? Which table do you need to use to check in order to remove items from the dropdown?

diafol
Keep Smiling
Moderator
10,832 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,533
Skill Endorsements: 61

Which table do you need to use to check in order to remove items from the dropdown? Content of vreg_no table Versus fleet_no, a filed in Vehicle_info table which holds the values from the dropdown.

dannybarh
Newbie Poster
20 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I'm still none the wiser. Sorry, I can't help you. Good luck with it.

diafol
Keep Smiling
Moderator
10,832 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,533
Skill Endorsements: 61

thank you all for try

dannybarh
Newbie Poster
20 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0936 seconds using 2.7MB