0

Is it possible in php and mysql to get the value from the table using a query and store the value in a variable and use the variable in where condition of another query, for example

$us = mysql_query("select regional from td_user where user_id='".$_SESSION['use_i']."'");
$us_row=mysql_fetch_row($us);
$reg = $us_row[`regional`] ;

now i have stored the value in a variable called $reg

$sql = "SELECT * FROM td_excel where regional = '$reg'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result)
    {
    <?php echo $row['Vehicle_description'];?>
    <?php echo $row['Year'];?>
      //it will display many rows like this
}

its not displaying any records!!!!,am i doing it in right way..please help me!!! P.S I am a learner!!

vivek
  • 955
  • 2
  • 8
  • 11

2 Answers2

0

Have you tried with this?

$sql = "SELECT * FROM td_excel where regional = ".$reg;
0

change $us_row=mysql_fetch_row($us); to $us_row=mysql_fetch_array($us);

and also change $reg = $us_row[regional] ; to $reg = $us_row['regional'] ;

Darloz
  • 165
  • 11