matthewst Posted March 25, 2010 Share Posted March 25, 2010 Example table 1: person: 1 oak_spaces: 5 person: 2 oak_spaces: 8 My first drop down will select the correct work number. The second drop down(the one listed below) will then display the appropriate number of options. Example table 2: person: 1 space: 2 person: 1 space: 3 person: 1 space: 5 How would I make my drop down only show options 1 and 4? $sql="SELECT oak_spaces FROM data_table WHERE id = '".$q."'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { //the above query will get me the maximum number of options to display //how do I set up my query (for table 2) and php to only echo 1 and 4? (in this example 5 is the max) ?> <select name="quote_num" class="formTextbox" size="1"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <?php if ($row['oak_spaces'] > '20'){ ?> <option value="21">21</option> <option value="22">22</option> <?php } if ($row['oak_spaces'] > '22'){ ?> <option value="23">23</option> <option value="24">24</option> <?php } if ($row['oak_spaces'] > '24'){ ?> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <?php } if ($row['oak_spaces'] > '28'){ ?> <option value="29">29</option> <option value="30">30</option> <?php } } ?> </select> Maybe a preg_match? Or a preg_not_match? Quote Link to comment Share on other sites More sharing options...
trq Posted March 25, 2010 Share Posted March 25, 2010 How would I make my drop down only show options 1 and 4? You need to query the database for (and only for) the data you actually need. Your post doesn't make allot of sense to me or I would offer more help adjusting your query. Quote Link to comment Share on other sites More sharing options...
matthewst Posted March 25, 2010 Author Share Posted March 25, 2010 Your post doesn't make allot of sense to me Fair enough. I have multiple tables in a database, one table holds the max number of widgets, somewhere between 20 and 30. For this I'll say max is 20. The first drop down on the form (the one NOT shown) gives me my $q variable that get_quote_num.php uses to dynamically display the second drop down (the one I displayed in post one). In another table I have listed users and the widgets that are already taken. example: user 1 widget 1 user 1 widget 3 My question is how do I write a query or some php to only show select options 2, 4-20? $sql="SELECT oak_spaces FROM data_table WHERE id = '".$q."'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { //I assume the new query will need to go here //something like //$sql = "select widgets from table where user = user" //which will give me 1 and 3 //now echo "<select>" //!!!!!!right here, how do I NOT display<option value'1'> but skip to 2 like below ?> <select name="quote_num" class="formTextbox" size="1"> <option value="2">2</option> <option value="4">4</option> <option value="5">5</option> Quote Link to comment Share on other sites More sharing options...
matthewst Posted March 25, 2010 Author Share Posted March 25, 2010 Now that I think about it, that is a little convoluted. To make things a little clearer. How do I write a query and php to display in a drop down data that is NOT in a database? Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted March 26, 2010 Share Posted March 26, 2010 $sql="SELECT oak_spaces FROM data_table WHERE id = '".$q."' AND oak_spaces NOT IN (SELECT spaces FROM another_table"; Quote Link to comment Share on other sites More sharing options...
matthewst Posted March 26, 2010 Author Share Posted March 26, 2010 Got it!! I just have to use the following code for each <option>. <?php if(mysql_num_rows(mysql_query("SELECT whatev FROM some_table WHERE number = 1 AND person_id = '".$q."'"))){ echo "<option value='1' disabled>1</option>"; }else{ echo "<option value='1'>1</option>"; } ?> BTW Andrew, have you seen Bubba Ho-Tep? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.