BadGoat Posted July 3, 2006 Share Posted July 3, 2006 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 More sharing options...
wildteen88 Posted July 3, 2006 Share Posted July 3, 2006 Use extract function, example[code=php:0]extract($row);[/code] Link to comment https://forums.phpfreaks.com/topic/13582-can-echo-id-but-not-the-variable/#findComment-52612 Share on other sites More sharing options...
BadGoat Posted July 3, 2006 Author Share Posted July 3, 2006 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 stringWhat did I do wrong? Link to comment https://forums.phpfreaks.com/topic/13582-can-echo-id-but-not-the-variable/#findComment-52692 Share on other sites More sharing options...
kenrbnsn Posted July 3, 2006 Share Posted July 3, 2006 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 Link to comment https://forums.phpfreaks.com/topic/13582-can-echo-id-but-not-the-variable/#findComment-52696 Share on other sites More sharing options...
BadGoat Posted July 3, 2006 Author Share Posted July 3, 2006 Many thanks Ken, With that I was able to deduce how/what I had to do next. :) Link to comment https://forums.phpfreaks.com/topic/13582-can-echo-id-but-not-the-variable/#findComment-52708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.