Code: Select all
<html>
<head>
<title>DB Query Page</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
</head>
<body>
<div id="form">
<form action="<?php echo $PHP_SELF;?>" method="POST">
Adgroup: <input type="text" name="$adgroup" />
Date From: <input type="text" name="from_date" />
Date To: <input type="text" name="to_date" />
<input type="submit" value="Apply" name="query" />
</form>
</div>
<?php
//File that holds connection parameters
include 'connection.php';
//Create short variable names
$adgroup = $_POST['adgroup'];
$query = "select * from adgroup_data where adgroup='%$adgroup%'";
$result = mysql_query($query) or die (mysql_error());
echo "<table cellpadding=3 id=table>";
//echo '<th>date</th>';
echo '<th>Account</th>';
//echo '<th>customer_id</th>';
echo '<th>Adgroup</th>';
echo '<th>Impressions</th>';
echo '<th>Clicks</th>';
echo '<th>CTR</th>';
echo '<th>CPC</th>';
echo '<th>CPM</th>';
echo '<th>Cost</th>';
echo '<th>Avg_Position</th>';
echo '<th>Conversions</th>';
echo '<th>Conversions_mpc</th>';
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
//"<td>{$row['date']}</td>".
echo "<tr><td>{$row['account']}</td>";
//"<td>{$row['customer_id']}</td>".
echo "<td>{$row['adgroup']}</td>";
echo "<td>{$row['impressions']}</td>";
echo "<td>{$row['clicks']}</td>";
echo "<td>{$row['ctr']}</td>";
echo "<td>{$row['cpc']}</td>";
echo "<td>{$row['cpm']}</td>";
echo "<td>{$row['cost']}</td>";
echo "<td>{$row['avg_position']}</td>";
echo "<td>{$row['conversions']}</td>";
echo"<td>{$row['conversions_mpc']}</td>
</tr>";
}
?>
</body>
</html>
I am very new (2 days and counting!) to php so there are probably lots of errors here. However I am now at the "can't see wood for trees" stage of development and I would be extremely grateful for any help. When I click "apply" it reloads the page (presumably because of the action within the form) but with no data.
I realise that is an obvious action (set it to load itself therefore any data the query retrieved will be lost) but I can't figure out how to make the page keep the parameters entered within the adgroup text box, and load the results in the table below.
Any help would be greatly appreciated.
Kind regards
Peter