mysql to html table php function or class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    mysql to html table php function or class

    Hi all,

    wondering if does exists a mysql to html table function or class written in
    PHP.

    something like.

    createtable($qu ery,fieldname1, fieldname2,fiel dname3,[fieldname4,fiel dname5]);

    the last parameter would be a link (first param = text to show, second param
    = link).
    It would help to have one of those...

    If it doesn't exist, what would you see in such function or class ? Do you
    preffer a class of function ?
    at first, I may think of allowing creating the title line, add link or
    images...but what else ?

    Thanks for helping.


  • Jerry Stuckle

    #2
    Re: mysql to html table php function or class

    Bob Bedford wrote:
    Hi all,
    >
    wondering if does exists a mysql to html table function or class written in
    PHP.
    >
    something like.
    >
    createtable($qu ery,fieldname1, fieldname2,fiel dname3,[fieldname4,fiel dname5]);
    >
    the last parameter would be a link (first param = text to show, second param
    = link).
    It would help to have one of those...
    >
    If it doesn't exist, what would you see in such function or class ? Do you
    preffer a class of function ?
    at first, I may think of allowing creating the title line, add link or
    images...but what else ?
    >
    Thanks for helping.
    >
    >
    >
    Nope, nothing like that in PHP. Personally, I wouldn't find a lot of
    use for it. The code to do such is pretty simple.

    I'm afraid any class like this would be too specialized to be really
    useful (i.e. can't set column widths, text attributes, etc.) or would
    have so many options that it would be more complicated to use the class
    than to write the code.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Bob Bedford

      #3
      Re: mysql to html table php function or class

      Nope, nothing like that in PHP. Personally, I wouldn't find a lot of use
      for it. The code to do such is pretty simple.
      >
      I'm afraid any class like this would be too specialized to be really
      useful (i.e. can't set column widths, text attributes, etc.) or would have
      so many options that it would be more complicated to use the class than to
      write the code.
      Mhhh, thanks for your reply...

      first shot in 15 minutes. Not tested, not debugged....onl y the general idea.
      This is because I help a guy to create a website with quite lot of tables
      and he always loose some code in table formatting....a nd it's pretty hard
      for him to get things right.

      function createtable(){
      //Parameter list. if no value, then use NULL
      //1st: MySQL Query
      //2nd: string containing HTML code of table parameters (width, border,
      cellspacing...)
      //3rd: array containing the titles of columns. If an empty array, uses the
      query field name
      //4th: array containing the line colors (ex: [#FFFFFF;#FFCCCC];
      //5th: array of fields in the table. If NULL show all fields.
      $column_count = 0;
      $table_param = '';
      $header = '';
      $linecolors = array();
      $linesplit = 0;
      $arrayfields = array();
      for($I=0;$I<fun c_num_args();$I ++){
      $param = func_get_arg($I );
      if($param <NULL){
      switch($I){
      case 0: $result_id = mysql_query($pa ram) or die("Query error:" .
      mysql_error());
      $column_count = mysql_num_field s($result_id) or die("num fields
      error:" . mysql_error());
      break;
      case 1: $table_param = $param;
      break;
      case 2: $header = "<TR>";
      if(array_count_ values($param)= 0){
      for ($column_num = 0;$column_num < $column_count;$ column_num++)
      $header .= "<TH>".mysql_fi eld_name($resul t_id,
      $column_num)."</TH>";
      }else
      foreach($param as $key=>$value)
      $header .= "<TH>".$value." </TH>";
      $header .= "</TR>";
      break;
      case 3: if(is_array($pa ram)){
      $linecolors = $param;
      $linesplit = array_count_val ues($param);
      }
      break;
      case 4: if(array_count_ values($param)= 0){
      for ($column_num = 0; $column_num < $column_count; $column_num++)
      array_push($arr ayfields,mysql_ field_name($res ult_id,
      $column_num));
      }else
      foreach($param as $key=>$value)
      array_push($arr ayfields,$value );
      break;

      } //switch
      } //param <NULL
      } // for

      // Here the table attributes from the $table_params variable are added
      echo("<TABLE $table_params >\n");
      echo("$header\n ");
      // print the body of the table
      while ($row = mysql_fetch_obj ect($result_id) ){
      echo("<TR ALIGN=LEFT VALIGN=TOP>");
      foreach($arrayf ields as $key=>$value)
      echo("<TD>$row[$value]</TD>\n");
      echo("</TR>\n");
      }
      echo("</TABLE>\n");
      }

      Maybe it's worthing a try to implement or improve...

      Thanks for advice....


      Comment

      • Jerry Stuckle

        #4
        Re: mysql to html table php function or class

        Bob Bedford wrote:
        >Nope, nothing like that in PHP. Personally, I wouldn't find a lot of use
        >for it. The code to do such is pretty simple.
        >>
        >I'm afraid any class like this would be too specialized to be really
        >useful (i.e. can't set column widths, text attributes, etc.) or would have
        >so many options that it would be more complicated to use the class than to
        >write the code.
        >
        Mhhh, thanks for your reply...
        >
        first shot in 15 minutes. Not tested, not debugged....onl y the general idea.
        This is because I help a guy to create a website with quite lot of tables
        and he always loose some code in table formatting....a nd it's pretty hard
        for him to get things right.
        >
        function createtable(){
        //Parameter list. if no value, then use NULL
        //1st: MySQL Query
        //2nd: string containing HTML code of table parameters (width, border,
        cellspacing...)
        //3rd: array containing the titles of columns. If an empty array, uses the
        query field name
        //4th: array containing the line colors (ex: [#FFFFFF;#FFCCCC];
        //5th: array of fields in the table. If NULL show all fields.
        $column_count = 0;
        $table_param = '';
        $header = '';
        $linecolors = array();
        $linesplit = 0;
        $arrayfields = array();
        for($I=0;$I<fun c_num_args();$I ++){
        $param = func_get_arg($I );
        if($param <NULL){
        switch($I){
        case 0: $result_id = mysql_query($pa ram) or die("Query error:" .
        mysql_error());
        $column_count = mysql_num_field s($result_id) or die("num fields
        error:" . mysql_error());
        break;
        case 1: $table_param = $param;
        break;
        case 2: $header = "<TR>";
        if(array_count_ values($param)= 0){
        for ($column_num = 0;$column_num < $column_count;$ column_num++)
        $header .= "<TH>".mysql_fi eld_name($resul t_id,
        $column_num)."</TH>";
        }else
        foreach($param as $key=>$value)
        $header .= "<TH>".$value." </TH>";
        $header .= "</TR>";
        break;
        case 3: if(is_array($pa ram)){
        $linecolors = $param;
        $linesplit = array_count_val ues($param);
        }
        break;
        case 4: if(array_count_ values($param)= 0){
        for ($column_num = 0; $column_num < $column_count; $column_num++)
        array_push($arr ayfields,mysql_ field_name($res ult_id,
        $column_num));
        }else
        foreach($param as $key=>$value)
        array_push($arr ayfields,$value );
        break;
        >
        } //switch
        } //param <NULL
        } // for
        >
        // Here the table attributes from the $table_params variable are added
        echo("<TABLE $table_params >\n");
        echo("$header\n ");
        // print the body of the table
        while ($row = mysql_fetch_obj ect($result_id) ){
        echo("<TR ALIGN=LEFT VALIGN=TOP>");
        foreach($arrayf ields as $key=>$value)
        echo("<TD>$row[$value]</TD>\n");
        echo("</TR>\n");
        }
        echo("</TABLE>\n");
        }
        >
        Maybe it's worthing a try to implement or improve...
        >
        Thanks for advice....
        >
        >
        >
        If he's going to be doing website updates, he should learn html. Really,
        about all you're doing is changing one syntax for another.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        Working...