Jump to content

Can echo ID but not the variable


BadGoat

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!

Link to comment
https://forums.phpfreaks.com/topic/13582-can-echo-id-but-not-the-variable/
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

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.