I am trying to print out the data I have in a MySQL table, but I want them filtered based on the values of a column. I want these values to be displayed in a drop down list, and after one of them is chosen I wont the program to print out all the records that fill that requirement. To make it more clear I want books that are in the library to be printed, based on the category that is selected from the drop down menu. I have done some research and I've modified some codes. But it's my very first time coding in PHP and I have clearly done something wrong. The code I try to execute is this:
<form id="form1" name="form1" method="POST" action="">
Fusha e kërkimit:
<select Name='NEW'>
<option value="">---Zgjidh---</option>
<?
mysql_connect('localhost', '<password>', '<user>');
mysql_select_db("<mysql_db>");
if (isset ($select) && $select!=""){
$select=$_POST['NEW'];
}
?>
<?
$list=mysql_query("SELECT * FROM 'arkiva' ORDER BY 'Fusha'");
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<?php echo htmlspecialchars($row_list['Fusha']);?>">
<?php echo htmlspecialchars($row_list['Fusha']); ?>
</option>
<?
}?>
</select>
<input type="submit" name="Submit" value="Dërgo" />
</form>
but this only prints out the box of the drop down with no actual values, and I have a missing piece of code that prints out after the selection.
Thank you so much in advance!
Your query isn't ordering correctly due to syntax. Adding backticks should help:
$list=mysqli_query("SELECT * FROM `arkiva` ORDER BY `Fusha`");
This answer addresses what backticks do in your query.
Still not able to make it show my fields in the dropdown. I have temporarily solved this by manually creating the fields of the dropdown. Bur it certainly gets very confusing and long with the growth of my database. So I still need to work this out for a permanent solution. Anyways thank you both for the help