[ Kondenzator @ 21.01.2013. 15:59 ] @
Pozdrav, Radim na jednom malom projektu i došao sam do jednog dijela gdje sam "zaribao" i ne mogu nikako da rijesim ovo. Mozda imam pogrešan pristup, ne znam.. Nisam pametan :) list.php Code: <?php Class User { public $id; public $first_name; public $last_name; public $comments; public function __construct($Id,$name, $secondName, $comment){ $this->id=$Id; $this->first_name=$name; $this->last_name=$secondName; $this->comments=$comment; } public function getID(){ return $this->id; } public function getFirstName(){ return $this->first_name; } public function getLastName(){ return $this->last_name; } public function getComment(){ return $this->comments; } public function save(){ } public static function getAllUsers(){ $upit="SELECT * FROM user"; if($querry_run=mysql_query($upit)) { while($querry_row=mysql_fetch_assoc($querry_run)) { $niz[]= new User($querry_row['id'],$querry_row['FirstName'],$querry_row['LastName'],$querry_row['Comment']); } return $niz; } else { echo 'Ne moRe'; } } public function if_delete(){ ->>>>>>> OVDJE JE POTENCIJALNO PROBLEM if($_GET['run_func'] == yes) { delete(); } } public function delete(){ ->>>>>>> OVDJE JE POTENCIJALNO PROBLEM if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; $result = mysql_query("DELETE FROM user WHERE id=$id") or die(mysql_error()); } } } a sada nastavak list.php gdje ce biti hyperlnik preko kojeg zelim da pozovem metod delete() Code: require 'db.php'; $Nestoo =new User(0,'admin','admin','neki admin'); $harko=$Nestoo->getAllUsers(); $max = sizeof($harko); $result = mysql_query("SELECT * FROM user") or die(mysql_error()); echo "<table border='1'> <tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Comment</th> </tr>"; // //while($row = mysql_fetch_array( $result )){ for($i=0;$i<$max;$i++){ echo "<tr>"; echo "<td>" . $harko[$i]->getID(). "</td>"; echo "<td>" . $harko[$i]->getFirstName() . "</td>"; echo "<td>" . $harko[$i]->getLastName() . "</td>"; echo "<td>" . $harko[$i]->getComment() . "</td>"; echo "<td>" . '<form action="update-user.php" method="POST" > <input name="custom" type="hidden" value="$harko[$i]->getID()" /> <input type="submit" value="Update"> </form>' . "</td>"; echo "<td>" . '<a href="delete.php?id=' . $harko[$i]->getID() . '">Link to First</a>' . "</td>"; ->>> OVDJE JE POTENCIJALNO PROBLEM echo "</tr>"; } // zatvaram tabelu echo "</table>"; ?> Objašnjenje problema: U list.php imam ispisanu tabelu koja pored ID,FIRSTNAME,LASTNAME,COMMENT ima polje DELETE za brisanje korisnika. Zanima me kako da implementiram da preko linka: '<a href="delete.php?id=' . $harko[$i]->getID() . '">Link to First</a>' . "</td>"; ->>> OVDJE JE POTENCIJALNO PROBLEMio pozovem metod delete() i da obrišem user-a iz tabele. Da li je pristup pogrešan? Napomena: Mora mi sve biti u ovom fajlu dakle nemam dozvolu da pravim dodatni fajl npr. delete.php. Nadam se da ste skontali da nisam bio previse konfuzan... |