Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 4th, 2008, 01:15 PM
Bob Bedford
Guest
 
Posts: n/a
Default 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($query,fieldname1,fieldname2,fieldname 3,[fieldname4,fieldname5]);

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.


  #2  
Old July 4th, 2008, 04:35 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: mysql to html table php function or class

Bob Bedford wrote:
Quote:
Hi all,
>
wondering if does exists a mysql to html table function or class written in
PHP.
>
something like.
>
createtable($query,fieldname1,fieldname2,fieldname 3,[fieldname4,fieldname5]);
>
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@attglobal.net
==================

  #3  
Old July 4th, 2008, 05:05 PM
Bob Bedford
Guest
 
Posts: n/a
Default Re: mysql to html table php function or class

Nope, nothing like that in PHP. Personally, I wouldn't find a lot of use
Quote:
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_i d,
$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....


  #4  
Old July 4th, 2008, 10:05 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: mysql to html table php function or class

Bob Bedford wrote:
Quote:
Quote:
>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_i d,
$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
==================

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles