Jump to content

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.