Jump to content

Giving an ID to a form?


Pain

Recommended Posts

Hello everyone.

 

I am wondering how can i give different id's to a html form?

 

<?php
...
if ($numrows!=0)
{
// fetching data from the database to variable
while ($row = mysql_fetch_assoc($query))
{
	$view_jam = $row['jamname'];
	$view_recipe = $row['jamrecipe'];
	$view_rating = $row['jamrate'];
	$view_owner = $row['owner'];
	$view_comments = $row['comments'];
	$view_count = $row['count'];
	$view_id = $row['id'];
	$view_count2 = $row['count2'];



	echo "Jam name: <b>" . $view_jam . "</b><br />";
	echo "Jam recipe: " . $view_recipe . "<br />";
	echo "Owner: " . $view_owner . "<br />";
	echo "Comments: " . $view_comments . "<br />";
	echo "Jam Rating: " . $view_rating . "<br />";
	[b]echo '<form action="main.php?id=jams" method="POST">[/b]
Choose rating 
<input type="text" name="jamrate" />

<input type="submit" name="submit1" value="Rate">
</form><br /><br />'; 		
...
?>

As you can see, the form is inside a loop.

I am trying to build a rating system. When there is only one row in a database then everything goes smoothly, but if there are more, then the rating applies to all rows.

I suppose i need to give different id's to the form. How?

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/250725-giving-an-id-to-a-form/
Share on other sites

No, thats not working, besides my form is already has name "jamrate". The problem is that when the loop goes on, my form's name remains "submit1". And i have this code:

<?php
...
if($submit1)
{
$counted = $view_count + 1;
$myQuery = "UPDATE jam SET count = '$counted' WHERE id = '$view_id'";
mysql_query($myQuery);

$counted3 = $view_count2 + $rating_post;
$myQuery1 = "UPDATE jam SET count2 = '$counted3' WHERE id = '$view_id'";
mysql_query($myQuery1);

$finalrating = $counted3/$counted;
$myQuery2 = "UPDATE jam SET jamrate = '$finalrating' WHERE id = '$view_id'";
mysql_query($myQuery2);
$finalquery = mysql_query("SELECT * FROM jam");
$numrows1 = mysql_num_rows($finalquery);
        ...
        ?>        

 

And this is my loop

<?php
...
while ($row = mysql_fetch_assoc($query))
{
	$view_count = $row['count'];
	$view_id = $row['id'];
	$view_count2 = $row['count2'];

                echo "Comments: " . $view_comments . "<br />";
	echo "Jam Rating: " . $view_rating . "<br />";
	echo '<form action="main.php?id=jams" method="POST">
Choose rating 
<input type="hidden" name="jamrate" />
<select name="jamrate">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>

<input type="submit" name="submit1" value="Rate">
</form><br /><br />'; 		
...
?>

 

So everytime a new loop starts, my form will update all rows, because the name remains "submit1", but i need to update only one, therefore id's or name's should be different each time.

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.