You are here: Re: Set variable outside of scope (redo) « PHP « IT news, forums, messages
Re: Set variable outside of scope (redo)

Posted by Al on 10/16/07 11:36

Mike Tuller wrote:
> Excuse the last post, I didn't have all the code it there.
>
> I have a table listing items in a database, and have a delete button
> next to each item, and I want to be able to click on the delete and
> delete only that record in the database and then reload the page
> where it would display the updated information. Here is part of the
> code I have.
>
> // list elements one by one until there are no more in the database
> while ( $row=mysql_fetch_array($result2) )
> {
> if ($row[range] != "")
> {
> echo "
> <form action=".$_SERVER['PHP_SELF']." method=\"post\" name=
> \"deleteRange\">
> <tr class=\"trlist\">
> <td>$row[id]</td>
> <td>$row[range]</td>
> <td align=\"right\"><input type=\"submit\"
> name=\"deleteRange\"
> value=\"Delete\" /></td>
> </tr>
> </form>
> ";
> }
> }
> echo "</table>";
>
> echo "
> <br />
> <form action=".$_SERVER['PHP_SELF']." method=\"post\" name=
> \"addrange\">
> <table class=\"nolist\">
> <tr>
> <td>Add Range: $row[id]</td>
> <td><input type=\"text\" name=\"name\" size=\"53\"
> tabindex=\"9
> \" /></td>
> <td align=\"right\"><input type=\"submit\"
> name=\"addRange\"
> value=\"Add Range\" /></td>
> </tr>
>
> </table>
> </form>";
>
>
>
> }
> elseif (isset($_POST['deleteRange']))
> {
>
> $query = "delete from district.ip_range where id = $row[id]";
>
> mysql_query($query, $link) or die (mysql_error());
>
> echo "Record ".$row[id]." has beed deleted.";
>
> }
>
> They key I am using to find the record I want to delete is the the
> $row[id], but that is out of the scope of where the variable is set.
> Is there a way to set a variable so that it goes outside the scope?

You have a lot of detail for folks to analyze just to give you an answer.

If I get the gist of your question, here is the genesis of an approach.

Put something like this in your loop that generates the table rows. The checkbox can be anywhere in the row that looks
good.

echo "<input type=\"checkbox\" name=\"row$i\" value=\"$value\">";
$i++;

Then when you process your $_POST, you'll see all the $_POST[rowx] {"x" is the row number} that were checked by the user.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация