Jump to content


Photo

Can echo ID but not the variable


  • Please log in to reply
4 replies to this topic

#1 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 03 July 2006 - 07:33 PM

Hiya,

Working on a script to teach me how to echo variables, but it's not working correctly. I can echo the variable from the main table, but not the variable from another table which matches an id field in the main table.  I know I'm close, can someone let me know what I have missed?

Here's a snippet:

    $car_id = $_GET['car_id'];

    $query1 = "SELECT car_model.year, make.a_make, model.a_model, trim.a_trim FROM car_model, make, model, trim WHERE trim.trim_id = car_model.trim_id AND model.model_id = car_model.model_id AND make.make_id = car_model.make_id AND car_id = '$car_id'";
    $result1 = mysql_query($query1);
    $row1 = mysql_fetch_array($result1);

echo'

<table>

<tr>
    <td>'.$year.', '.$a_make.', '.$a_model.', '.$a_trim.'</td>
</tr>

I can echo the ID, so I know that I am only one fix away:


<tr>
    <td>'.$row1['year'].''.$row1['make'].''.$row1['model].''.$row1['trim'].'</td>
</tr>


Thanks in advance!



#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 03 July 2006 - 07:35 PM

Use extract function, example
extract($row);


#3 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 03 July 2006 - 10:45 PM

I'm clearly doing something wrong..


<tr>
    <td colspan="2" class="header2">';extract($row1('.$a_make.', '.$a_model.', '.$a_trim.'));  echo'</td>
</tr>

I get this error:

Fatal error: Function name must be a string

What did I do wrong?

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 July 2006 - 10:57 PM

Change your code from
<?php
    $car_id = $_GET['car_id'];
    $query1 = "SELECT car_model.year, make.a_make, model.a_model, trim.a_trim FROM car_model, make, model, trim WHERE trim.trim_id = car_model.trim_id AND model.model_id = car_model.model_id AND make.make_id = car_model.make_id AND car_id = '$car_id'";
    $result1 = mysql_query($query1);
    $row1 = mysql_fetch_array($result1);
?>

to

<?php
    $car_id = $_GET['car_id'];
    $query1 = "SELECT car_model.year, make.a_make, model.a_model, trim.a_trim FROM car_model, make, model, trim WHERE trim.trim_id = car_model.trim_id AND model.model_id = car_model.model_id AND make.make_id = car_model.make_id AND car_id = '$car_id'";
    $result1 = mysql_query($query1);
    $row1 = mysql_fetch_assoc($result1);
    echo '<pre>' . print_r($row1,true) . '</pre>';
?>

Examine the output and you will see how PHP is storing the information. From that you should be able to deduce how to echo the variables.

Ken


#5 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 03 July 2006 - 11:59 PM

Many thanks Ken, With that I was able to deduce how/what I had to do next. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users