php query function / class

nnegaztere

New Member
It must be Monday, the heat or me being stupid (prob the latter), but for the life of me I cannot get a simple php function to work.I have a simple query\[code\]$sql = mysql_query("SELECT * FROM table WHERE field_name = '$input'");\[/code\]Which I want to run through a function: say: \[code\]function functionname($input){ global $field1; global $field2; $sql = mysql_query("SELECT * FROM table WHERE field_name = '$input'"); while($row = mysql_fetch_array($sql)) : $field1[] = $row['field1']; $field2[] = $row['field2']; endwhile; mysql_free_result($sql);}\[/code\]So that I can call the function in numerious places with differeing "inputs". Then loop through the results with a foreach loop.Works fine the first time the function is called, but always gives errors there after.As said "It must be Monday, the heat or me being stupid (prob the latter)".Suggestions please as I really only want 1 function to call rather than rewrite the query each and every time.This is the error message\[code\]Fatal error: [] operator not supported for strings in C:\xampp\htdocs\functions.php on line 270\[/code\]
 
Back
Top