Supportnet Computer
Planet of Tech

Supportnet / Forum / Skripte(PHP,ASP,Perl...)

id auslesen aus tabelle





Frage

hallo, ich hab ein kleines problem, ich hab eine tabelle, mit dem primärschlüssel id... wenn ich jetzt einen datensatz in die tabelle einfügen möchte, brauch ich doch die letzte id und ich schaff das nicht diese auzulesen... wer kann mir da helfen? Lg, Bianca [b] Quellcode:[/b] [code]function temp_save($id){ if($id == ""){ $query_new_temp = "INSERT INTO `process`("; $query_new_temp.= " `process`,"; $query_new_temp.= " `description_ger`,"; $query_new_temp.= " `description_engl`,"; $query_new_temp.= " `used_in`,"; $query_new_temp.= " `contact_person_1`,"; $query_new_temp.= " `in_development`,"; $query_new_temp.= " `contact_person_2`,"; $query_new_temp.= " `documentation`,"; $query_new_temp.= " `program`) VALUES ("; $query_new_temp.= " '".$this->temp_data[process]."',"; $query_new_temp.= " '".$this->temp_data[description_ger]."',"; $query_new_temp.= " '".$this->temp_data[description_engl]."',"; $query_new_temp.= " '".$this->temp_data[used_in]."',"; $query_new_temp.= " '".$this->temp_data[contact_person_1]."',"; $query_new_temp.= " '".$this->temp_data[in_development]."',"; $query_new_temp.= " '".$this->temp_data[contact_person_2]."',"; $query_new_temp.= " '".addslashes($this->temp_data[documentation])."',"; $query_new_temp.= " '".addslashes($this->temp_data[program])."',"; mysql_query($query_new_temp); $id= "SELECT LAST_INSERT_ID() AS id from process"; } else{ $query_update_temp = "UPDATE `process` SET "; $query_update_temp.= " `pocess` = '".$this->temp_data[process]."',"; $query_update_temp.= " `description_ger` = '".$this->temp_data[description_ger]."',"; $query_update_temp.= " `description_engl` = '".$this->temp_data[description_engl]."',"; $query_update_temp.= " `used_in` = '".$this->temp_data[used_in]."',"; $query_update_temp.= " `contact_person_1` = '".$this->temp_data[contact_person_1]."',"; $query_update_temp.= " `in_development`='".$this->temp_data[in_development]."',"; $query_update_temp.= " `contact_person_2`='".$this->temp_data[contact_person_2]."',"; $query_update_temp.= " `documentation`='".addslashes($this->temp_data[documentation])."',"; $query_update_temp.= " `program`='".addslashes($this->temp_data[program])."',"; mysql_query($query_update_temp); } return $id; }[/code]

Antwort 1 von EbiEbiEbi

Moin!

mysql_insert_id() gibt die letzte ID der letzten INSERT-Funktion zurück! Google sonst mal


Sonst einfach:


$res = mysql_query("SELECT * FROM table ORDER BY id ASC");
$res = mysql_fetch_assoc[$res];

$letzteid_in_tabelle = $res['id];


(einfach aufsteigend sortieren; das letzte element ist das größte, deren id wird gelesen .....)