修改php的oop mysql查询 [英] modify php oop mysql query

查看:118
本文介绍了修改php的oop mysql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,所以感谢以前的帮助,我现在有一个很棒的功能来查询特定的一行数据。

  class职位{

公共静态函数singleQuery($ table,$ value){

返回mysql_fetch_object(
mysql_query(select * from $ table where id = $ value),__CLASS__);




$ set = Posts :: singleQuery('settings','1');
echo $ post-> title;

我希望修改这个,所以它查询以下内容:

  SELECT * FROM posts ORDER BY id DESC LIMIT 0,3

,然后在我的view / index页面上创建一个echo loop或者一个foreach类型的交易,例如:

  foreach($ a as $ b){
echoyadda
}

我希望这是有道理的。

解决方案

  $ result = mysql_query(SELECT * FROM posts ORDER BY id DESC LIMIT 0,3),__CLASS__); 

while($ object = mysql_fetch_object($ result)){
// //而在$ object中有下一行
$ return [] = $ object;
}

return $ return;
pre

$ p
$ b $ $ $ $ $ $ $ $ $ array = Posts :: multipleQuery (...);
foreach($ array AS $ row){
echo $ row-> title;
}


Hey, so thanks to the help earlier, I now have a great function for querying a specific row of data.

    class Posts{

      public static function singleQuery($table, $value){

        return mysql_fetch_object(
           mysql_query("select * from $table where id=$value"), __CLASS__);

      }

    }

$set = Posts::singleQuery('settings', '1');
echo $post->title;

I was hoping to modify this so it queries the following:

SELECT * FROM posts ORDER BY id DESC LIMIT 0, 3"

and then create an 'echo loop' or a foreach type of deal on my view/index page. Something like:

foreach ($a as $b){  
    echo "yadda"  
}

I hope this makes sense..

解决方案

$result = mysql_query("SELECT * FROM posts ORDER BY id DESC LIMIT 0, 3"), __CLASS__);

while($object = mysql_fetch_object($result)) {
   // each round of while has the next line in $object
   $return[] = $object;
}

return $return;

...

$array = Posts::multipleQuery(...);
foreach($array AS $row) {
   echo $row->title;
}

这篇关于修改php的oop mysql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆