tcollie Posted June 23, 2007 Share Posted June 23, 2007 Basically what I want to do is this. I have table with about 20 fields in it. I want to be able to dynamically pull the data for a certain record and create an array with the keys as the fields names and of course the data as the value. Here's what I have so far (and it's not working ): function get_data($record_id) { $query = mysql_query("SELECT * FROM table where record_id = '$record_id'") or die(mysql_error()); while($row = mysql_fetch_array($query )) { foreach ($row as $key => $value) { $data .= "&$key=$value"; } } return $data; } Now I want to be able to call the function and work with the data I'm trying to call. $record_id = 'xxxxxxxxx'; $test = get_data($record_id); $name = $test['username']; //This would be the username field from the table echo $name; All I get is a blank screen when I run this and I know the problem is in the foreach statement I tried to write. Any suggestions here? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 23, 2007 Share Posted June 23, 2007 function get_data($record_id) { $query = mysql_query("SELECT * FROM table where record_id = '$record_id'") or die(mysql_error()); $row = mysql_fetch_assoc($query ); } } return $row ; } then you get an array result Quote Link to comment Share on other sites More sharing options...
tcollie Posted June 23, 2007 Author Share Posted June 23, 2007 thanks for the help teng. Apparently I've been slamming my head on my desk over nothing. Always have to make a big deal out of everything. Thanks again for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.