I am using a loop to go through the result of query and display the data in a grid. I only want to display the delete button in certain rows. I can setup if else statements for that.
while($rows = mysql_fetch_array($result)){
//HTML code - I am not using echo here just plain html code written below
deleteButton();//I am calling the deleteButton function here.
//HTML code
}
I have a deleteButton function at the top of the page
function deleteButton()
{
echo "<form name='DeleteInfo' method='POST' action='delete.php'>";
echo "<input type='hidden' name='val1' value=$rows[col1]>";
echo "<input type='hidden' name='val2' value=$rows[col2]>";
echo "<input class='center' type='submit' value='Delete'/>";
echo "</form>";
}
I get an error undefined variable rows for col1 and col2. I am assuming it's a syntax problem.
I have also tried.
echo "<input type='hidden' name='val2' value=$rows['col2']>";
echo "<input type='hidden' name='val2' value='$rows[col2]'>";
This HTML code works
<input type="hidden" name="name1" value="<?php echo $rows['col3']; ?>">
EDIT: Resolved. It was out of scope. I have to use global $rows in the function. Thanks Marc.