Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Wstawianie parametru do funkcji ... porblem i brak wiedzy :D
szachor
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 9.11.2004
Skąd: Jaworzno

Ostrzeżenie: (0%)
-----


Witam mam taki oto problemik mam funkcję ( jedną z kilku w każdej mam ten sam problemik) :

Kod
function removeCalendar($id ){
  $ret = array();
  try{
    $db = new DBConnection();
    $db->getConnection();

    $sql = "delete from  Kalendarz_1  where `id`=" . $id;
        if(mysql_query($sql)==false){
      $ret['IsSuccess'] = false;
      $ret['Msg'] = mysql_error();
    }else{
      $ret['IsSuccess'] = true;
      $ret['Msg'] = 'Succefully';
    }
    }catch(Exception $e){
     $ret['IsSuccess'] = false;
     $ret['Msg'] = $e->getMessage();
  }
  return $ret;
}


Która dokonuje usunięcia z bazy i wszystko gula pod warunkiem że nazwa tabeli jest zapisana bezpośrednio czyli Kalendarz_1 ja niestety potrzebuje wstawiać nazwę tabeli dynamicznie w zależności od zalogowanego do systemu user i jak bym nie kobinował nie umiem sobie z tym poradzić np robie tak :

Kod
$jakasnazwatabeli = 'Kalendarz_11';
function removeCalendar($id ){
  $ret = array();
  try{
    $db = new DBConnection();
    $db->getConnection();

    $sql = "delete from $jakasnazwatabeli  where `id`=" . $id;
        if(mysql_query($sql)==false){
      $ret['IsSuccess'] = false;
      $ret['Msg'] = mysql_error();
    }else{
      $ret['IsSuccess'] = true;
      $ret['Msg'] = 'Succefully';
    }
    }catch(Exception $e){
     $ret['IsSuccess'] = false;
     $ret['Msg'] = $e->getMessage();
  }
  return $ret;
}


i nie che mi to działać proszę o pomoc (IMG:style_emoticons/default/smile.gif)

Z góry dziękuje
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
mortus
post
Post #2





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

Ostrzeżenie: (0%)
-----


Jednym z rozwiązań jest podanie nazwy tabeli jako parametru:
  1. function removeCalendar($id, $table) {
  2. // ...
  3. $sql = "DELETE FROM `" . $table . "` WHERE `id` = " . $id;
  4. // ...
  5. }
  6.  
  7. $id = 12; // przykładowe id
  8. $tabela = 'Kalendarz_1';
  9. $rezultat = removeCalendar($id, $tabela);

Innym sposobem jest użycie słowa global - poczytaj.
Co do Twojego kodu, to pamiętaj, że funkcję trzeba wywołać.
Go to the top of the page
+Quote Post
Fifi209
post
Post #3





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

Ostrzeżenie: (0%)
-----


Cytat(mortus @ 7.06.2011, 19:45:42 ) *
Innym sposobem jest użycie słowa global - poczytaj.

Idź precz z takimi pomysłami!
Go to the top of the page
+Quote Post
szachor
post
Post #4





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 9.11.2004
Skąd: Jaworzno

Ostrzeżenie: (0%)
-----


Chyba jestem za tępy do tego :/ bo nie umiem dać sobie rady
Czy mogę prosić o pomoc jak to zmejkować na podstawie poniższego kodu (IMG:style_emoticons/default/questionmark.gif)

Kod
function listCalendarByRange($sd, $ed){
  $ret = array();
  $ret['events'] = array();
  $ret["issort"] =true;
  $ret["start"] = php2JsTime($sd);
  $ret["end"] = php2JsTime($ed);
  $ret['error'] = null;

  try{
      
    $db = new DBConnection();
    $db->getConnection();
    $sql = "select * from TABELKA1 where `starttime` between '"
      .php2MySqlTime($sd)."' and '". php2MySqlTime($ed)."'";
    $handle = mysql_query($sql);
    //echo $sql;
    while ($row = mysql_fetch_object($handle)) {
      //$ret['events'][] = $row;
      //$attends = $row->AttendeeNames;
      //if($row->OtherAttendee){
      //  $attends .= $row->OtherAttendee;
      //}
      //echo $row->StartTime;
      $ret['events'][] = array(
        $row->Id,
        $row->Subject,
        php2JsTime(mySql2PhpTime($row->StartTime)),
        php2JsTime(mySql2PhpTime($row->EndTime)),
        $row->IsAllDayEvent,
        0, //more than one day event
        //$row->InstanceType,
        0,//Recurring event,
        $row->Color,
        1,//editable
        $row->Location,
        ''//$attends
      );
    }
    }catch(Exception $e){
     $ret['error'] = $e->getMessage();
  }
  return $ret;
}
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 1.10.2025 - 07:43