Announcement

Collapse
No announcement yet.

$where

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • $where

    Hier habe ich ein script. Meine frage und grosse bitte ist ob mir jemand helfen kann. Ich verstehe den script nicht so richtig. Ich möchte das jemand erklert mir diesen teil mit $where und hilf mir auch zu sagen wie muss ich das script schreiben das ich $where als WHERE status=ACTIVE umwandle.

    Ich hoffe das jemand kann mir helfen wofür ich mich sehr bedanke.

    static function count($table, $where = '', $order = '', $limit = '', $group = '')
    {
    $sql = 'SELECT COUNT(*) ';
    $sql .= 'FROM `' . $table . '` ';
    $sql .= ($where == '' ? '' : 'WHERE ' . $where . ' ');
    $sql .= ($order == '' ? '' : 'ORDER BY ' . $order . ' ');
    $sql .= ($group == '' ? '' : 'GROUP BY ' . $group . ' ');
    $sql .= ($limit == '' ? '' : 'LIMIT ' . $limit . ' ');
    return DB::result($sql);
    }
    static function field($table, $field, $where = '', $order = '', $limit = '', $group = '')
    {
    $sql = 'SELECT `' . $field . '` ';
    $sql .= 'FROM `' . $table . '` ';
    $sql .= ($where == '' ? '' : 'WHERE ' . $where . ' ');
    $sql .= ($order == '' ? '' : 'ORDER BY ' . $order . ' ');
    $sql .= ($group == '' ? '' : 'GROUP BY ' . $group . ' ');
    $sql .= ($limit == '' ? '' : 'LIMIT ' . $limit . ' ');
    return DB::column($sql);
    }
    static function select($table, $where = '', $order = '', $limit = '', $fields = '*', $group = '')
    {
    $sql = 'SELECT ' . (is_array($fields) ? '`' . implode('`,`', $fields) . '`' : $fields) . ' ';
    $sql .= 'FROM `' . $table . '` ';
    $sql .= ($where == '' ? '' : 'WHERE ' . $where . ' ');
    $sql .= ($order == '' ? '' : 'ORDER BY ' . $order . ' ');
    $sql .= ($group == '' ? '' : 'GROUP BY ' . $group . ' ');
    $sql .= ($limit == '' ? '' : 'LIMIT ' . $limit . ' ');
    return DB::all($sql);
    }

  • #2
    Hallo,

    habe es mal hierher verschoben, da es ja offensichtlich kein SQL-Problem ist, sondern eher eine PHP-Verständnissfrage.

    Zum Thema: WAS verstehst du an "diesen teil mit $where" nicht?

    Um ein "WHERE status=ACTIVE" zu erreichen, müsstest du nur eine der Funktionen mit 'status=ACTIVE' für den Parameter $where aufrufen.

    z.B.:
    PHP Code:
    echo count('eineTabelle''status=ACTIVE'); 
    Wobei ich zu bedenken gebe, dass das nur funktioniert wenn es sich bei ACTIVE um einen Bezeichner handelt (also z.B. ein Feld in eineTabelle). Ist ACTIVE jedoch ein Literal, dann sollte es so aussehen:
    PHP Code:
    echo count('eineTabelle'"status='ACTIVE'"); 
    Gruß Falk
    Wenn du denkst du hast alle Bugs gefunden, dann ist das ein Bug in deiner Denksoftware.

    Quellcode ohne ein Mindestmaß an Formatierung sehe ich mir nicht an! Ich leiste keinen Privatsupport per Mail oder PN!

    Comment


    • #3
      http://www.php-resource.de/forum/php...ere-hilfe.html

      Eigentlich gilt hier das Gleiche wie in dem anderen Forum: Formatiere deinen Beitrag
      Zuletzt editiert von Christian Marquardt; 09.12.2010, 14:54.
      Christian

      Comment


      • #4
        Danke Falk

        Meine frage ist wo soll ich echo count('eineTabelle', "status='ACTIVE'"); einfügen?

        Soll das so aussehen?:

        static function count($table, $where = '', $order = '', $limit = '', $group = '')
        {
        $sql = 'SELECT COUNT(*) ';
        $sql .= 'FROM `' . $table . '` ';
        $sql .= ($where == '' ? '' : 'WHERE ' . $where . ' ');
        echo count('eineTabelle', "status='ACTIVE'")
        $sql .= ($order == '' ? '' : 'ORDER BY ' . $order . ' ');
        $sql .= ($group == '' ? '' : 'GROUP BY ' . $group . ' ');
        $sql .= ($limit == '' ? '' : 'LIMIT ' . $limit . ' ');
        return DB::result($sql);
        }

        Danke

        Comment


        • #5
          Hallo,

          1. Bitte meine Signatur beachten:
          Ich leiste keinen Privatsupport per Mail oder PN!
          2. Bitte die Hinweise zur Formatierung beachten!
          3. Crosspostings sind hier absolut unerwünscht!

          Summasumarum => Close!
          Wenn du denkst du hast alle Bugs gefunden, dann ist das ein Bug in deiner Denksoftware.

          Quellcode ohne ein Mindestmaß an Formatierung sehe ich mir nicht an! Ich leiste keinen Privatsupport per Mail oder PN!

          Comment

          Working...
          X