Jump to content

One query for all?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
I have one table and I need to read records of this table but with one query and where I want to recod number one just I put one function.
(i think I need one class)

#2
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
    public function get($tname)
    {
        global $db;
        $query = $db->query("SELECT * FROM `templates` WHERE sid='{$this->sid}' AND `tname`='{$tname}' LIMIT 1;");
        if($db->num_rows($query) != '0')
        {
            $t = $db->fetch_array($query);
            $tname = $t['tname'];
            $codes = $this->replace($t['codes']);
            //$codes = "<!-- start: $tname : {$this->sid} -->\n{$codes}\n<!-- end: $tname : {$this->sid} -->";
            $codes = str_replace("\\'", "'", addslashes($codes));
            return $codes;
        }
        else
        {
            die("TPLClass:We do not have ".$tname." in our templates table.!");
        }
    }
Look I use this function to read my template code, when I read one template i will have one more query Now I want to read all templates at the 1st time and after that I use another function to read one of them??
It is possible?

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
easiest is to fetch all and store the one you're looking for with further use
i.e no where and no limiting and fetch them in a while loop instead.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall