I have created a form where the user can insert hyperlinks to documents on a server. Every time a new row is created, a dropdown menu is also created with the values which the users uses to make their rating. The problem i have is, i do not know how to link the position of the dropdown menu to the id for the document. For example if i rated the third document in the table how do i create a script so the dropdown position would be registered as 3 and match itself with the 3rd document in the table.
Here is the setup for my MySQL DB
id int ....... primary key
doc varchar(255)
rating int
I have been doing some background reading and most people have a seperate table for the ratings, but how do i implement this into my system
Here is the coding for the form.
<html>
<head>
<title>Dropdown Menu</title>
<head>
<body>
<?php
$host = "localhost";
$user = "root";
$pass = "mysql";
$db = "test";
$connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect".mysql_error());
mysql_select_db($db) or die ("ERROR: Unable to connect to DB".mysql_error());
$query = "SELECT * FROM menu";
$result = mysql_query($query) or die ("ERROR:Unable to run query".mysql_error());
#if (mysql_fetch_row($result) > 0 ){
echo "<form action=formprocess4.php method=POST name=rating>";
echo "<table border=1 cellpadding=3 cellspacing=3>";
echo "<tr>";
echo "<td><font face=Verdana size=-1><b>ID</td>";
echo "<td><font face=Verdana size=-1><b>Document Title</td>";
echo "<td><font face=Verdana size=-1><b>Rating</b></td>";
echo "</tr>";
while ($row=mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td><font face=Verdana size=-1>".$row['id']."</td>";
echo "<td><font face=Verdana size=-1>".$row['doc']."</td>";
echo "<td><select name=rates><option value= SELECTED><option value=1 name=$row[doc]rw>1 - Poor<option value=2 name=$row[doc]rw>2 - Average<option value=3 name=$row[doc]rw>3 - Excellent</select>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<br>";
echo "<input type=submit name=submit value=submit>";
echo "</form>";
#}
echo "<a href=http://localhost/brainstorm/phpFreaks/entryform.php><font face=Verdana size=-1>Back To Form</a>";
?>
</body>
</html>
Here is the coding for the processed table
<html>
<head>
<title>Dropdown Menu</title>
<head>
<body>
<?php
$host = "localhost";
$user = "root";
$pass = "mysql";
$db = "test";
$connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect".mysql_error());
mysql_select_db($db) or die ("ERROR:Unable to connect to DB".mysql_error());
$query = "SELECT * FROM menu";
$result = mysql_query($query) or die ("ERROR:Unable to run query".mysql_error());
#$update_table = "UPDATE menu SET rating=$_POST['rating'] WHERE"
/*
while ($row=mysql_fetch_assoc($result)){
$
*/
$posttech = $row['doc']."rw";
$update_table = "UPDATE menu SET rating =$_POST[$posttech] WHERE id = $id";
$update_result = mysql_query($update_result) or die ("ERROR:Unable to run update query".mysql_error());
echo "<h3><font face=Verdana>Table</h3>";
#if (mysql_fetch_row($result) > 0 ){
echo "<table border=1 cellpadding=3 cellspacing=3>";
echo "<tr>";
echo "<td><font face=Verdana size=-1>Document Title</td></font>";
echo "<td><font face=Verdana size=-1>Rating</td></font>";
while ($row=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td><font face=Verdana size=-1>".$row['doc']."</td>";
echo "<td><font face=Verdana size=-1>".$row['rating']."</td>";
echo"</tr>";
}
echo "</table>";
#}
echo "<br><a href=http://localhost/brainstorm/phpFreaks/entryform.php><font face=Verdana size=-1>Back To Form</a><br></font>";
?>
</body>
</html>
Can someone help me on this please
Thanks
Jermizzle