Jump to content

When the button is pressed the table disappears


tallberg

Recommended Posts

I have a problem with a disappearing table. Please can anyone help?

When form is submitted the $condition is built from the form $_POST array. 

if($condition){
$query = "SELECT * FROM plantsdb WHERE $condition";
$dbRecords = mysql_query($query, $dbLocalhost)
or die("Problem reading table: " . mysql_error());
$intCount = mysql_num_rows($dbRecords);
}
else
echo "Please select the properties you would like your plant to have";

… all the $dbRecords array items are put into other arrays to go through a set of similarity computation… this works fine.

Then, the code to display the table.

for($i=0; $i<$intCount; $i++)
{
 
echo "<form action='" . $_SERVER["PHP_SELF"] . "' method='post'>";
echo "<tr><td>$simArray[$i]</td><td>$descriptionArray[$i]</td><td>$usageArray[$i]</td><td>$idArray[$i]</td><td><input type='submit' name='add' value='add to list' ></td><tr>";
}
echo "</table>";
echo "</form>";


When the add button is pressed the table disappears.
first off you are making a new form everytime you loop. put your form tage before the loop. Also you might want to add some debugging functions to help out till everything works.

[code]$dbRecords = mysql_query($query, $dbLocalhost) or die (mysql_error());[/code]

Also is would be much easier to echo you results out through a while statement rather then all the arrays, but personal preference i guess.

Ray

Ive realize what part of the problem is.
The $condition may contain a string such as this: The_Group='Annuals'.
the value attribute of the hidden feild has its content in quotes. When it reads the first quote mark of The_Group='Annuals' it think it is the end of the value. Does any one know a way out of this.


echo "<form action='" . $_SERVER["PHP_SELF"] . "' method='post'>";
echo"<input type='hidden' name='condition' value=$condition>";

for($i=0; $i<$intCount; $i++)
{
echo "<tr><td>$simArray[$i]</td><td>$descriptionArray[$i]</td><td>$usageArray[$i]</td><td>$idArray[$i]</td><td><input type='submit' name='add' value='add' ></td><tr>";
}
echo "</table>";
echo "</form>";

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.