php help :)

Soldato
Joined
6 Apr 2008
Posts
3,352
Location
Reading
Hi again guys Im in a bit of a pickle.

I have this code here.

Code:
$nrows = mysqli_num_rows($result);

for ($i=1; $i <= $nrows; $i++)
{
	$row = mysqli_fetch_assoc($result);
	
	
    
	foreach ($labels as $field => $label)
	{
		
   		if ($field == 'Barcode' or $field == 'Make' or $field == 'Model' or $field == 'SerialNo')
		{
   			echo "<td>", $row[$field], "</td>";	
   		}
	} 
	
	echo "<form action = 'Results_item.php' method= 'POST'>";
	echo "<Input type = 'hidden' name = 'Barcode' value = '$row[Barcode]'>";
	echo "<td colspan = '1' style = 'text-align: right'>
    	  <Input type = 'submit' value = 'View Item'>";
	
	echo "<tr><td colspan = '10'><hr /></td></tr>";
}
echo "</table>\n";

now that outputs this.

Picture1-4.png


lovley

Obviously the buttons don't pass the correct value to the next php file as they take what ever the last value of the barcode was from the last item hence all buttons lead to the same bit of information.

how can I get them sending the correct bit of information for each item?

Thanks in advance :)

Edd
 
You could edit the <form> tag to have the action as 'Results_item.php?barcode=000000001' - replacing the barcode with the actual barcode of the item.

Then in Results_item.php do a quick check:

if(isset($_GET['barcode']))

and finally get the barcode and use it in your sql:

$barcode = $_GET['barcode'];

$sql = "Select * from items where barcode = $barcode";

Well, something like that.

Actually, just noticed you pass it in as a hidden value...

so you just need to replace $_GET with $_POST above and it should do the same thing? Have i misunderstood the question??

The problem may be because you don't have a '</form>' for each row - so it keeps opening new forms and not closing them...
 
Back
Top Bottom