dsbpac Posted April 17, 2013 Share Posted April 17, 2013 Hello guys, my code is a 3 teir auto populate form based on the selected option. The information is pulling from a mysql DB. Everything is working fine, now I'm wanting to expand to giving the options a value number from the MYSQL values.Example:MYSQL DB is setup as follows:teir_one | teir_one_value | tier_two | teir_two_value | tier_three | tier_three_valueHonda 1 civic 10 blue 100How can I pull tier_one_value from the DB and display it for data-cost= ?? Thanks in advance function getTierOne() { $result = mysql_query("SELECT DISTINCT tier_one FROM three_drops") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '<option value="'.$tier['tier_one'].'" data-cost="'.$tier['tier_one_value'].'">'.$tier['tier_one'].'</option>'; } } Here is my full code <?php //************************************** // Page load dropdown results // //************************************** function getTierOne() { $result = mysql_query("SELECT DISTINCT tier_one FROM three_drops") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '<option value="'.$tier['tier_one'].'" data-cost="1">'.$tier['tier_one'].'</option>'; } } //************************************** // First selection results // //************************************** if($_GET['func'] == "drop_1" && isset($_GET['func'])) { drop_1($_GET['drop_var']); } function drop_1($drop_var) { include_once('db.php'); $result = mysql_query("SELECT DISTINCT tier_two FROM three_drops WHERE tier_one='$drop_var'") or die(mysql_error()); echo '<select name="drop_2" id="drop_2"> <option value=" " disabled="disabled" selected="selected">Choose one</option>'; while($drop_2 = mysql_fetch_array( $result )) { echo '<option value="'.$drop_2['tier_two'].'" data-cost="10">'.$drop_2['tier_two'].'</option>'; } echo '</select>'; echo "<script type=\"text/javascript\"> $('#wait_2').hide(); $('#drop_2').change(function(){ $('#wait_2').show(); $('#result_2').hide(); $.get(\"func.php\", { func: \"drop_2\", drop_var: $('#drop_2').val() }, function(response){ $('#result_2').fadeOut(); setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400); }); return; }); </script>"; } //************************************** // Second selection results // //************************************** if($_GET['func'] == "drop_2" && isset($_GET['func'])) { drop_2($_GET['drop_var']); } function drop_2($drop_var) { include_once('db.php'); $result = mysql_query("SELECT DISTINCT tier_three FROM three_drops WHERE tier_two='$drop_var'") or die(mysql_error()); echo '<select name="drop_3" id="drop_3"> <option value=" " disabled="disabled" selected="selected">Choose one</option>'; while($drop_3 = mysql_fetch_array( $result )) { echo '<option value="'.$drop_3['tier_three'].'" data-cost="100">'.$drop_3['tier_three'].'</option>'; } echo '</select> '; } ?> Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 17, 2013 Share Posted April 17, 2013 I don't understand what your question is. How can I pull tier_one_value from the DB and display it for data-cost= ?? That seems to be exactly what you are doing here: echo '<option value="'.$tier['tier_one'].'" data-cost="'.$tier['tier_one_value'].'">'.$tier['tier_one'].'</option>'; Quote Link to comment Share on other sites More sharing options...
dsbpac Posted April 17, 2013 Author Share Posted April 17, 2013 data-cost="'.$tier['tier_one_value'].'" Is the finished code I want. How can I pull the tier_one_value from the mysql DB. When I try to do something like $result = mysql_query("SELECT DISTINCT tier_one, tier_one_value FROM three_drops") it doesn't work. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 17, 2013 Share Posted April 17, 2013 (edited) It does work, it just doesn't do what you want it to do. DISTINCT applies to the whole row. BTW, what does the data-cost attribute do in an option tag? I haven't seen that one before. Edited April 17, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
Solution dsbpac Posted April 18, 2013 Author Solution Share Posted April 18, 2013 UPDATE: I figured out a solution. I took out the DISTINCT and change it to GROUP BY. Thank you everyone for your time $result = mysql_query("SELECT tier_one, tier_one_value FROM three_drops GROUP BY tier_one") or die(mysql_error()); 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.