开发者

Having trouble echoing different data using the function method

I'm writing a PHP file which will putt from multiple table rows, data which it must echo on one page.

I wrote a function command because I a loop wont work as the information isn't output开发者_StackOverflow中文版ting in the same manner every time.

here is how it looks so far.

include("dbconnect.php");
function get_table_data($id)
{
    $row = mysql_query('SELECT row FROM table WHERE id = '.$id.'');
    $row2 = mysql_fetch_array($row);
};
$sss = 18; // this is the ID
echo get_table_data($sss);

My issue is that nothing echos and I have no errors


first of all, you need to return something:

function get_table_data($id) {
    $row = mysql_query('SELECT row FROM table WHERE id = '.$id.'');
    return mysql_fetch_array($row);
}

then, you need to access the row:

$result = get_table_data($sss);
echo $result['row'];

Hope this helps!


Your function get_table_data should return some value to be echoed in your statement echo get_table_data($sss);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜