Bill Flippen
Bill Flippen

Reputation: 453

Array to string conversion

looked around and everything seems to be more complex that what I am trying to do.

I have queried an item from a previous page and brought it forward.

$varVeh=$_POST['Veh_num'];

I echo that and it show the proper number....

I then want to use the name associated with that number in a table title. so I do another query:

$sql_vehName="select Veh_name from hc_vehicle_type where Veh_num=$varVeh";
$result_vehName = mysql_query($sql_vehName);
$vehName=mysql_fetch_assoc($result_vehName);
echo $vehName;  
echo "<table border='1'>";
echo "<tr><td>Best Scores for</td><td>$vehName</td> </tr>";

Without using the fetch I get resource #6.

Upvotes: 0

Views: 170

Answers (2)

hawx
hawx

Reputation: 1679

$sql_vehName = "select Veh_name from hc_vehicle_type where Veh_num=$varVeh";
$result_vehName = mysql_query($sql_vehName);
$vehName = mysql_result($result_vehName,0);  
echo "<table border='1'>";
echo "<tr><td>Best Scores for</td><td>$vehName</td> </tr>";

Upvotes: 1

S&#233;bastien
S&#233;bastien

Reputation: 12139

You assign $vehName as an associative array. What you can do is use the key that corresponds to your field name:

echo "<tr><td>Best Scores for</td><td>".$vehName['Veh_name']."</td> </tr>";

Upvotes: 1

Related Questions