Hopefully this question doesn't drive anyone to drink. I've been at this for about 9 hours now and cannot get a drop down to populate. I know I'm missing something very simple and I'm reaching out to see if anyone can give me some insight. The table I'm calling from has 1 column and just has names (which are unique)
I have a db class being called in the beginning of all of my pages, in all but 2 cases , its working fine, in the 2 exceptions, it's the pages that require the dropdown. I've deleted and recreated both pages with no change.
Both Pages are named select.php and select_p.php. The initial call is as follows and breaks at the first "->" so begins printing everything after it and up until the "?>"
include("database.class.php");
$database = new database;
$sql_page = $database->mysqlQuery("SELECT * FROM spec_tables");
$edata_page = $database->mysqlFetchArray($sql_page);
return $edata_page;
?>
Heres the fucntion in the class file that works on 2 other sites and other pages in this same site
function mysqlQuery($qry)
{
$rs = mysql_query($qry, $this->DatabaseLink);
return $rs;
echo mysql_error();
}
Now if I use the code in the page, it doesnt print but the dropdown is blank
<select name='list' value=''><option>Select List</option>
<?
$sql_page = $database->mysqlQuery("SELECT * FROM spec_tables");
$edata_page = $database->mysqlFetchArray($sql_page);
return $edata_page;
foreach($edata_page as $row){
?>
<option value="<?php echo $row; ?>"><?php echo $row; ?></option>
<? } ?>
</select>
I've looked at the following (plus about 20 pages that are not this close)
PHP- Fetch from database and store in drop down menu html
How to put table value in a dropdown menu with MYSQL and PHP
http://www.plus2net.com/php_tutorial/list-table.php
http://www.tutorialrepublic.com/faq/how-to-populate-dropdown-list-with-array-values-in-php.php
Here's all the snippets of code I've tried to no avail, some of them actually print the code in the html form, any constructive help would be very much appreciated.
*********************************************************
<select name='list' value=''><option>Select List</option>
<?
$sql_page = $database->mysqlQuery("SELECT * FROM spec_tables");
$edata_page = $database->mysqlFetchArray($sql_page);
return $edata_page;
foreach($edata_page as $row){
?>
<option value="<?php echo $row; ?>"><?php echo $row; ?></option>
<? } ?>
</select>
*****************************************************************
<select name='list' value=''><option>Select List</option>
<?
$result = $database->mysqlQuery("select * from spec_tables");
if (!$result) die('Couldn\'t fetch records');
$num_fields = mysql_num_fields($result);
$row = array();
for ($i = 0; $i < $num_fields; $i++)
while ($row = mysql_fetch_row($result))
{
?>
<option value="<?php echo $row; ?>"><?php echo $row; ?></option>
<? } ?>
</select>
********************************************************************
<select name='list' value=''><option>Select List</option>
<?
$result = $database->mysqlQuery("select * from spec_tables");
if(mysql_num_rows($result) > 0){
while($row = mysql_fetch_array($result)) {
echo '<option value=". $row['name'] .">' . $row['name'] . '</option>';
}
}
?>
</select>
****************************************************************************
Placed in top of file
$servername = "localhost";
$username = "uname";
$password = "pword";
$dbname = "db_name";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if ($result = mysqli->query("SELECT * FROM 'spec_tables'")) {
printf("Select returned %d rows.\n", $result->num_rows);
/* free result set */
$result->close();
}
**********************************************************************
<?
$sql = "select * from spec_tables";
$result = mysql_query($sql);
echo "<select name='list' value=''><option>Select List</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['name'] ."'>" . $row['name'] ."</option>";
}
echo "</select>";
?>
**************************************************