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

 

 

 

 

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.