Jump to content

I think i have built my rating system wrong......


j3rmain3

Recommended Posts

Im going to bare all bcz i have been working on this problem for too long.

I have created a DB in mySQL which stores records of drinks. I have created a form which allows me to enter records. This works fine.

To rate the drinks i have displayed the DB in PHP with dropdown menus to the right so the user can rate the drink.

This is my MySQL table
>>>

id int unsigned NOT NULL auto_increment
doc varchar(255)
rating int(11)

>>>

In the rating column are dropdown menus which has these options 1 - Poor; 2 - Average; 3 - Excellent

Here is the coding >>>

[CODE]
<?php
$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());

$count = "SELECT COUNT(*) FROM menu";

$count_result = mysql_query($count) or die ("ERROR: Unable to $count".mysql_error());

#for ($i=1;$i<$count_result;$i++){
#}

#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=Verna size=-1>".$row['doc_id']."</td>";
echo "<td><font face=Verdana size=-1>".$row['doc']."</td>";

/*
$rating1= ' '; $rating2= ' '; $rating3= ' ';
switch($row['rating'])
{
case 1: $rating1=' 1'; break;
case 2: $rating2=' 2'; break;
case 3: $rating3=' 3'; break;
}
*/

echo "<td><select name=rates><option value= ' '></option><option value=1 name=' $row[doc]'rw>1 - Poor</option><option value=2 name=' $row[doc]'rw>2 - Average<option value=3 name=' $row[doc]'rw>3 - Excellent</option></select>";
echo "</td>";
echo "</tr>";
#echo "<br>";
}
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>[/CODE]

I think i have done this wrong bcz there is not way to identify were the dropdown menu is postioned on the table. I have currently named the dropdown menus $row['doc']rw. --- I do not know what to name the dropdown menus so that they can be linked to the id or doc name of the document being updated. And also my update query is not working >> this is shown in the code below.

This is the coding i have placed in the table which is supposed to display the ratings.

[CODE]
<?php
$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());

$row1 = mysql_fetch_assoc($result);

$doc1 = "$row1[doc];

$update_table = "UPDATE menu SET rating = '$_POST[$doc]' WHERE doc = '$row1[doc]'";

$update_result = mysql_query($update_table) or die ("ERROR: $update_table".mysql_error());

$count = "SELECT COUNT(*) FROM menu";

$count_result = mysql_query($count) or die ("ERROR: Unable to $count".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>ID</td></font>";
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_id']."</td>";
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>";
?>[/CODE]

What i think i need to do is name the dropdown with a number so i could use that as the position in the table. But i am not sure how to get the database to register the number from the dropdown menu.

Can someone help me please. Thanks

j3rmain3
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.