Jump to content

MYSQL Pulling Values


dsbpac

Recommended Posts

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_value
Honda            1           civic          10            blue           100

How 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> ';
}
?>


 

 

Link to comment
https://forums.phpfreaks.com/topic/277077-mysql-pulling-values/
Share on other sites

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>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.