开发者

How do I create a function to get value from database

开发者 https://www.devze.com 2023-03-14 02:54 出处:网络
I want to create a function to call a key and value on specific table. Basically my statement like this

I want to create a function to call a key and value on specific table.

Basically my statement like this

$query = 'SELECT SQL_CALC_FOUND_ROWS 
         '.$key.' 
          FROM users 
     开发者_如何学编程     WHERE 
          status="'.$value.'"';

Now I want implement in function

function counter('what to put here') {
    $query = 'SELECT SQL_CALC_FOUND_ROWS 
             '.$key.' 
              FROM users 
              WHERE 
              status="'.$value.'"';
if (!($result = @mysql_query($query))) {
die(mysql_error());
}
$rows = mysql_fetch_assoc(mysql_query('SELECT FOUND_ROWS() AS rows'));
return $rows['rows']; // what to return here
}

And to call the function

<?php echo counter('KEY','VALUE'); ?>

Let me know how to achieve my goal..


So ,I've understand the question , according to poster's comment and I'm posting the answer: You need to define your function like this: function counter($key,$value) and you get the result like this: echo counter('key','value')


This is how you define your function:

function counter($key)

This is how you can call it:

<?php echo counter('KEY'); ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号