Jump to content

Archived

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

BadGoat

Can echo ID but not the variable

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Use extract function, example
[code=php:0]extract($row);[/code]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Change your code from
[code]<?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);
?>[/code]

to

[code]<?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>';
?>[/code]

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

Share this post


Link to post
Share on other sites
Many thanks Ken, With that I was able to deduce how/what I had to do next. :)

Share this post


Link to post
Share on other sites

×

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.