|
Posted by Jerry Stuckle on July 4, 2008, 4:59 pm
Please log in for more thread options 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....only 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....and 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<func_num_args();$I++){
> $param = func_get_arg($I);
> if($param <> NULL){
> switch($I){
> case 0: $result_id = mysql_query($param) or die("Query error:" .
> mysql_error());
> $column_count = mysql_num_fields($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_field_name($result_id,
> $column_num)."</TH>";
> }else
> foreach($param as $key=>$value)
> $header .= "<TH>".$value."</TH>";
> $header .= "</TR>";
> break;
> case 3: if(is_array($param)){
> $linecolors = $param;
> $linesplit = array_count_values($param);
> }
> break;
> case 4: if(array_count_values($param)=0){
> for ($column_num = 0; $column_num < $column_count; $column_num++)
> array_push($arrayfields,mysql_field_name($result_id,
> $column_num));
> }else
> foreach($param as $key=>$value)
> array_push($arrayfields,$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_object($result_id)){
> echo("<TR ALIGN=LEFT VALIGN=TOP>");
> foreach($arrayfields 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@attglobal.net
==================
|