2 Replies - 4300 Views - Last Post: 10 June 2011 - 10:37 PM Rate Topic: -----

#1 teahou  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 223
  • Joined: 01-April 11

Fill a select drop down with multiple fields from mysql DB

Posted 10 June 2011 - 10:00 PM

I have a vehicle table in a mySQL DB. I am pulling 3 columns, vnum, year and model. I need to populate my select boxes with the results from this query, and I need all 3 fields to be in each option, so option one would show something like:

101 1996 Econoline

and so forth. Currently I am getting this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\work\inspection\newInspection.php on line 93

Line 93 is the one with the 'echo' in it. Please look over my code and let me know if you see something wrong. thank you.

<body onload="getTodayDate()">

<?php
//Connect to server
$link = mysql_connect("localhost", 'root', 'password') or die(mysql_error());

//Select the database
mysql_select_db ('vending');

//SQL Query
$query = 'SELECT vnum, year, model FROM vehicle ORDER BY vnum';

// Run the query


mysql_close($link);



?>

<div id="contentWrapper">


<h1>New Inspection</h1>

<form name="formInfo" action="" method="" >
<dl>
<dt><label>Choose a vehicle:</label></dt>
<dd><select>

<?php
if ($result = mysql_query($query))
{
	while ($row = mysql_fetch_array($result))
	{
		$i=0;
		echo "<option value = \"".$i."\">.$row['vnum']."-".$row['year']."-".$row['model'] ";
		$1++;
	}
}
?>

</select>



This post has been edited by teahou: 10 June 2011 - 10:01 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Fill a select drop down with multiple fields from mysql DB

#2 teahou  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 223
  • Joined: 01-April 11

Re: Fill a select drop down with multiple fields from mysql DB

Posted 10 June 2011 - 10:13 PM

Ok, I fixed the errors, but the drop down is not filling. Here is the corrected code:

<?php
if ($result = mysql_query($query))
{
	while ($row = mysql_fetch_array($result))
	{
		$i=0;
		echo "<option value = \"".$i."\">.$row[vnum]."-".$row[year]."-".$row[model] ";
		$i++;
	}
}
else
{
	print '<p style="color: red;">Could not retrieve the data because: ' . mysql_error() . '</p>';
}
?>


Was This Post Helpful? 0
  • +
  • -

#3 teahou  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 223
  • Joined: 01-April 11

Re: Fill a select drop down with multiple fields from mysql DB

Posted 10 June 2011 - 10:37 PM

I got it figured out. Here is the working code:

<?php
if ($result = mysql_query($query))
{
	while ($row = mysql_fetch_array($result))
	{
		$i=0;
		echo "<option value = \"" . $i . "\">" . $row[vnum] . "-" . $row[year] . "-" . $row[model] . "</option>";
		$i++;
	}
}
else
{
	print '<p style="color: red;">Could not retrieve the data because: ' . mysql_error() . '</p>';
}
?>



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1