1,105,363 Community Members

compare and hide

Member Avatar
dannybarh
Light Poster
36 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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>`
Member Avatar
diafol
Where are my eyes?
12,980 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
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.

Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
0
 

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

Member Avatar
dannybarh
Light Poster
36 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
broj1
Posting Virtuoso
1,578 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
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?

Member Avatar
dannybarh
Light Poster
36 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
broj1
Posting Virtuoso
1,578 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 219 [?]
Skill Endorsements: 21 [?]
Featured
 
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.

Member Avatar
dannybarh
Light Poster
36 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
dannybarh
Light Poster
36 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
diafol
Where are my eyes?
12,980 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
1
 

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?

Member Avatar
dannybarh
Light Poster
36 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
diafol
Where are my eyes?
12,980 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

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

Member Avatar
dannybarh
Light Poster
36 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thank you all for try

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: