Welcome! Log In Create A New Profile

Advanced

how to call a method from hreff?

Posted by 42609852 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
how to call a method from hreff?
April 15, 2013 10:30PM
Ok, first off I am not doing this course,
but after reading a post from another student asking about classes in 2613... well my ego got the best of me and I decided to rewrite my web page in a more OOP way.

(and I know its not needed in year 2, but I like learning this and am impatient, so please help me)

My Question:
so I have a person class...
with methods...

a constructor method and a display method that does something like this...

Language: PHP
echo "<td>"".$this->Username . "</td><td><a href=PHP/deleteP.php?player_id=".$this->ID.">Delete</a></td></tr>";

but I have a method to delete this person from the db...

Language: PHP
Person->Delete();

but as this is sitting server side... how do I call this method in the hreff... is it possible, can I do it with a button?
should I even have a method like this?
or just use my previous code: (that works?)

Language: PHP
deleteP.php?player_id=".$this->ID
avatar
Mac
Re: how to call a method from hreff?
April 16, 2013 08:24AM
You do not call the method in the a href - you merely send the id to the delete page with th a href. There the id is caught and used in the method. It appears a bit of an overkill - I'll just have a simple delete statement since the query is specific i.e. to delete a player. Why write a 4 line function when a one line delete query can do the same job? Not to say you must not.... but OO is not always better. A delete method that can be used with more than one table is useful.
Re: how to call a method from hreff?
April 16, 2013 09:02AM
Thanks Mac, appreciate the help
Header or include... can switch statement be rerun?
April 19, 2013 08:43PM
sorry for stupid question previously...
might have another though...
I have a action page...
and depending on the action it will include diffrent things...


Language: PHP
switch($_REQUEST['Action']){ case "ViewAll" : //some code here $page = "otherPage"; case "Delete": $Fixtures[0]=new Fixture('','','',''); $Fixtures[0]->ID=$ID; $Fixtures[0]->Delete(); //what to do here... I need to refresh the entire page or table.. so would like to jump to the above code "Viewall" action... header ("Location: ?Controller=Fixtures&Action=ViewAll"); //this does not work (guessing its because of me including this into another page??   break;}   include( 'Views/' . $page . '.php');

can someone help?
avatar
Mac
Re: how to call a method from hreff?
April 22, 2013 08:32AM
Either headers already sent, or remove space between location: and ?, but add full page URL

Else try:

Language: PHP
echo "<meta http-equiv='refresh' content='0;url=http://........'>";
Sorry, only registered users may post in this forum.

Click here to login