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 for diafol

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.

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

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.

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?

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.

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.

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.

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

Member Avatar for diafol

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?

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 for diafol

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

thank you all for try

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.