I have a PHP template system for page page such that the following code will always generate a similar looking page:
<?php
include('header.html');
//Page specific content goes here
include('footer.html');
?>
This system has been working fine, but I just tried adding a dropdown list menu that is generated use values stored in a database. On the initial page load, everything works fine, then when I click go to go to another page, the list will still be there, but it's empty...suggestings that the query isn't running the second time around. Here is the code I am using; it is located in footer.html:
<?php
require_once('includes/mysql_connect.php');
$query = "SELECT LEFT(track, 15) AS name, track_id FROM track ORDER BY track ASC";
$result = mysql_query($query);
echo "<form action=\"songs.php\" method=\"get\">
<select name=\"track\">";
while($row = mysql_fetch_array($result)){
if(strlen($row['name']) == 15){
echo "<option value=\"{$row['track_id']}\">{$row['name']}...</option>";
} else {
echo "<option value=\"{$row['track_id']}\">{$row['name']}</option>";
}
}
mysql_free_result($result);
echo "</select>
<input type=\"submit\" value=\"Go\"/>
</form><br/>";
?>
I also tried loading the database info into an array, hoping that the array would spit out the values that I wanted consistently...but that did not work either. Here's the code:
<?php
require_once('includes/mysql_connect.php');
$query = "SELECT LEFT(track, 15) AS name, track_id FROM track ORDER BY track ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
if(strlen($row['name']) == 15){
$track[$row['track_id']] = "{$row['name']}...";
} else {
$track[$row['track_id']] = "{$row['name']}";
}
}
echo "<form action=\"songs.php\" method=\"get\">
<select name=\"track\">";
foreach($track as $key => $value){
echo "<option value=\"$key\">$value</option>";
}
echo "</select>
<input type=\"submit\" value=\"Go\"/>
</form><br/>";
?>
Thanks so much for the help!!!