pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP pastebin - collaborative debugging tool View Help


Posted by Binny V A on Sat 21 Mar 17:18
report abuse | download | new post

  1. /**
  2.  * @author hussein
  3.  * @copyright 2009
  4.  */
  5. //$args = array("table" => array("field1", "field2", "field3"));
  6. $args = array("table1" => "field1",
  7.               "table2" => array("field1", "field2", "field3"),
  8.                           "table3" => "field",
  9.                           "table4" => "field",
  10.                           "table5" => array("fiel1", "fiel2", "fiel3"),
  11.               "table6" => "field2",
  12.                           "table7" => "field",
  13.                           "table8" => "field");
  14. //$args = "not array";
  15. echo s($args);
  16. //echo count($args);
  17. function s($vars, $where=''){
  18.         if(!empty($where)){
  19.         $where = " WHERE ".$where;
  20.         }
  21.         if(is_array($vars)){
  22.                 if(count($vars) > 1){
  23.                         foreach($vars as $table => $fields){
  24.                                 $t = substr($table, "0", "2").$x;
  25.                                 $t_arr[] = $table." AS ".$t;
  26.                                 if(is_array($fields)){
  27.                                         foreach($fields as $field){
  28.                                                 $f_arr[] .= $t.".".$field;
  29.                                         }
  30.                                         $x++;
  31.                                         continue;
  32.                                 }
  33.                                 $f_arr[] = $t.".".$fields;  
  34.                                 $x++;
  35.                         }
  36.                         $f_str = implode(", ",$f_arr);
  37.                         $t_str = implode(", ", $t_arr);
  38.                         if(!is_array($fields)){
  39.                         return $qry = "SELECT ".$f_str." FROM ".$t_str.$where;
  40.                         exit();  
  41.                         }
  42.                 }elseif(count($vars) == 1){
  43.                         foreach($vars as $table => $fields){
  44.                                 if(!is_array($fields)){
  45.                                                 $qry = "SELECT ".$fields." FROM ".$table.$where;
  46.                                 }
  47.                                 if(is_array($fields)){
  48.                                                 $fields_str = implode(", ", $fields);
  49.                                                 $qry = "SELECT ".$fields_str." FROM ".$table.$where;
  50.                                 }
  51.                         }
  52.                 }else{
  53.                         $qry = "An undefined error occured!";
  54.                 }
  55.                 return $qry;
  56.         }else{
  57.                 $error = "Is not an array!";
  58.                 return $error;
  59.         }
  60. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post