problem with a function i have built

guys well i have built a function which suppose to output a specific column from a table by a query i gave to it:
here is the code:
[php]
$content_query = $db->query(“SELECT * FROM tms_pages WHERE id = ‘{$page_id}’;”);

function page_content($input){
global $content_query;
if($input != NULL){
$content = mysql_fetch_array($content_query);
return $content[$input];
}
}
[/php]
now when i will try to output the function for example by calling the column name via the function i am using something like that:
[php]echo page_content(“name”)[/php]
everything is working excellent until this point, but when in the same file i try to output another column via the function it won’t.
for example:[php]echo page_content(“content”)[/php]
if i erase the page_content(“name”) the second one with the content will work.
soo… what’s the problem guys :(… why can’t i use the function twice? :-X

It’s moving the internal array pointer, once you call mysql_fetch_array or fetch_assoc (or anything like that), the internal pointer moves to the next row of results. To always use the first row, change to this:

[php]mysql_data_seek($content_query,0);
$content = mysql_fetch_array($content_query); [/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service