Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
floppydrivez
Involved
Involved



Joined: Feb 26, 2006
Posts: 340
Location: Jackson, Mississippi

PostPosted: Wed Sep 13, 2006 5:54 pm Reply with quote

I have been trying to make clickable delete button for a table row from db. I searched the web am I missing something?
 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
floppydrivez







PostPosted: Wed Sep 13, 2006 5:57 pm Reply with quote

Something similar to this,
[ Only registered users can see links on this board! Get registered or login! ]
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Thu Sep 14, 2006 6:02 am Reply with quote

How far have you gotten? Do you have form code that you can share? What about your delete code... any sample of where you are at with it? Your question is pretty generic, so I am trying to narrow this down to what problem you are having. There are numerous examples of this throughout nuke that you could "steal".

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
floppydrivez







PostPosted: Thu Sep 14, 2006 6:09 am Reply with quote

Code:
OpenTable();

echo "<table align=\"center\" width=\"100%\"><tr>";
echo "<td><strong>Games</strong></td></tr>";
echo "<tr><td><strong>Name</strong></td><td><strong>Version</strong></td><td><strong>Abbreviation</strong></td></tr>";
$result = $db->sql_query("SELECT gid, gname, version, gabbr FROM ".$prefix."_league_games ORDER by gid");
while (list($gid, $gname, $version, $gabbr)=sql_fetch_row($result)) {
echo "<tr><td>$gname</td><td>$version</td><td>$gabbr</td></tr>";}
echo "</table>";
CloseTable();


I would like to put a delete button just after $gabbr. As far as status, I am finished coding the whole admin section except for edit and delete links.

This is my first "user friendly" module just trying to get an idea of how this concept works.
 
montego







PostPosted: Thu Sep 14, 2006 6:21 am Reply with quote

The key is that when the FORM is posted back to the web server (back to PHP), you need to have some way to determine what "function" to perform. In its simplest form, let us say you simply wanted a text link with the word "Delete" and a link on it. So, something like this:

Code:


<a href="modules.php?name=MyModuleName&op2=DeleteMe&itemid=9">Delete</a>


In your module's index.php script, you would check $op2 for "DeleteMe" and do the delete code within there...

Again, that is just one of many possible ways of doing this, but it should get the idea across.[/code]
 
floppydrivez







PostPosted: Thu Sep 14, 2006 7:38 am Reply with quote

So basically I could make a function at the top of my index like so

Code:
function erase($gid) {

    global $prefix, $db;
    $gid = intval($gid);
    $result = $db->sql_query("delete from ".$prefix."_league_games where gid='$gid'");
}


And then call to it here
Code:
<a href=\"modules.php?name=$modulename&erase=delete&gid=$gid\">Delete</a>


I will give that a shot and see how it twerks.
 
montego







PostPosted: Thu Sep 14, 2006 7:49 am Reply with quote

Well, this will not "call" the function. Seems to me that "erase" and "delete" are redundant. I was thinking that you might have something more generic like "op2" (don't use "op") and then you would need an IF statement to check what "op"eration you are needing to "call" and then, yes, you can "call" the appropriate function.
 
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Thu Sep 14, 2006 10:02 am Reply with quote

Oh I give up. I've been trying to post something with a code sample for a form and an action that deletes the record selected. You can use submit buttons with values associated with them if you want a quick (and dirty) way to do buttons. Probably you would be better off with a select drop down box and populate the options in there from the table. Then have the action go to another php program and extract the value with $_POST[nameof button] and then delete the record with a where clause where the value = the value in the name of button.

I hope that's not too cryptic. I can't even post what I want on my own test site where I'm an admin and I'll just have to email it to the Sentinel group.
 
View user's profile Send private message Visit poster's website
floppydrivez







PostPosted: Thu Sep 14, 2006 11:32 am Reply with quote

Yeah I am kinda lost on this part, but I like that drop down box idea. It sounds like I could put my edit option in there too. If you come up with a solution or idea for me fkelly, you can always email it to me.

I am gonna try to work around this inconvience till my brain is more rested.
 
fkelly







PostPosted: Thu Sep 14, 2006 6:16 pm Reply with quote

If you get the book PHP and MYSQL web development by Welling and Thompson (I'm looking at the second edition but there may be one after) but anyway there is a shopping cart application and they have an example of populatiing a select / options with data from a database (it's at page 551 of second edition paperback book). I used that example in a different application (module) that I wrote and it works like a charm.

I am giving up on trying to post code samples here. And they wouldn't make much sense anyway wrenched out of context.
 
floppydrivez







PostPosted: Thu Sep 14, 2006 6:17 pm Reply with quote

roger that, This last part seems to be killing my mojo. I will give that shot.
 
floppydrivez







PostPosted: Sat Sep 16, 2006 1:07 pm Reply with quote

I ended up making this work. Using bits and pieces of the above snipplet from [ Only registered users can see links on this board! Get registered or login! ]

Code:
$result = $db->sql_query("SELECT gid, gname, version, gabbr FROM ".$prefix."_league_games ORDER by gid");

while (list($gid, $gname, $version, $gabbr)=sql_fetch_row($result)) {
echo "<tr><td>$gabbr</td><td>$gname</td><td>$version</td>";
if(!isset($cmd)) {
echo "<td><a href='modules.php?name=$modulename&cmd=delete&gid=$gid'>Delete</a></td></tr>";
}
if($_GET["cmd"]=="delete")
{
    $result = $db->sql_query("DELETE FROM ".$prefix."_league_games WHERE gid=$gid");
    header ("Location: modules.php?name=$modulename");
}
}


It does exactly what I want it to. So for now I am satisfied.
 
floppydrivez







PostPosted: Sun Sep 17, 2006 6:43 pm Reply with quote

Oh, I was just being stubborn about this. Although the code above works it does not deal with multiple rows very well. So I did a little something different that to my knowledge is working great.

Instead of trying to keep the delete action in the same document, I moved it to a new one. This is my admin index code

Code:
$result = $db->sql_query("SELECT gid, gname, version, gabbr FROM ".$prefix."_league_games ORDER by gid");

while (list($gid, $gname, $version, $gabbr)=sql_fetch_row($result)) {
echo "<tr><td>$gabbr</td><td>$gname</td><td>$version</td>";
echo "<td><a href='modules.php?name=$modulename&file=dgame&gid=$gid'>Delete</a></td></tr>";
}


This is the code for dgame.php
Code:
$gid = $_GET['gid'];

$result = $db->sql_query("DELETE from ".$prefix."_league_games WHERE gid='$gid'");
if ($result) {
   echo "<center>Game Deleted Successfully</center>";
} else {
   echo "<center>Could not delete Game</center>";
}


Anyway that seems to work perfect. Thanks for the help.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©