Posted By

kilrizzy on 06/02/09


Tagged

mysql database php data row


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

vali29
umang_nine
farondomenicgmailcom
scottwf


PHP/MySQL - Get Row Data


 / Published in: PHP
 

URL: http://www.jeffkilroy.com

Use this function to pull all columns from a single database field. getrowdata(tablename,rowid,prefix);

You would call this function like: getrowdata("users",$SESSION['user'],"user");

The prefix is the prefix you want for the array names, so if I have a field in my "users" table called "username", the example above would output the variable "$user_username = 'data';"

  1. function getrowdata($tablename,$rowid,$prefix){
  2. $field_query = mysql_query("SELECT * FROM ".$tablename." WHERE id = ".$rowid."");
  3. if(mysql_num_rows($field_query) > 0){
  4. //Get field data
  5. $field_array = mysql_fetch_array($field_query);
  6. foreach($field_array as $field_key=>$field_value){
  7. //Setup a global variable name for this data based on prefix
  8. global ${"{$prefix}$field_key"};
  9. ${"{$prefix}$field_key"} = stripslashes($field_value);
  10. }
  11. }
  12. }

Report this snippet  

You need to login to post a comment.