I've just started learning to create websites. I'm trying to have a SQL query that returns a single value, but can't figure out if there is an elegant solution to what I'm trying to achieve.
Is there a single line of code I can use to assign the SQL query result to the AccountManagers variable?
Is there a single line of code I can use to assign the SQL query result to the AccountManagers variable?
Code:
<body>
<?php
$db = new PDO('sqlite:.\database\siteinfo.db');
?>
<!--Choose list of companies-->
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<p>Company Name:
<select name="CompanySelection">
<?php
$sql = "SELECT DISTINCT CompanyName from CustomerDetails";
foreach ($db->query($sql) as $row)
{
echo '<option value="'.$row['CompanyName'].'">'.$row['CompanyName'].'</option>';
}
?>
</select>
<input name="CompanySelectionButton" type="submit" value="Select"/>
</p>
</form>
<?php
if ($_POST)
{
$CompanyName=$_POST['CompanySelection'];
[COLOR=#ff0000]$AccountManager=$db->query('SELECT AccountManager FROM CustomerDetails WHERE CompanyName='.$CompanyName);[/color]
echo '<h1>Customer Details - '.$CompanyName.'</h1>';
echo '<hr />
<table>
<tr>
<th>Company Name:</th>
<td>'.$CompanyName.'</td>
<th>Account Manager:</th>
[COLOR=#ff0000]<td>'.$AccountManager.'</td>[/color]
</tr>