db table column name to table header name

This is a discussion on db table column name to table header name within the PHP General forums, part of the PHP Programming Forums category; Hello all, Listed below is the code I currently working on. In the foreach where I echo the <th&...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-16-2006
George Mills
 
Posts: n/a
Default db table column name to table header name

Hello all,


Listed below is the code I currently working on.

In the foreach where I echo the <th> and the table column name I would
like to output a more readable name for the table header such as where
the table column name is 'b_date' I would like to output 'Birthday'.

Anyone have any suggestions. Besides a switch statement. I also will
need to reformat some of the values like b_date into something more
friendly. Hopefully I can use the same method for the reformatting as I
do for the name conversion.

To complicate matters the sql is dynamicly created so the third column
this time may not be the same as the third column selected next time.

Thanks in advance,
George

(If Treefrog reads this I took all the globals out of my code by making
the class central to the structure rather than as a referenced object. :) )

....
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($row as $key => $value) {
$arr[$i][$key] = $value;
}
$i++;
}
?>
<form ... >
<br><table border="1"><tr>
<?php
$row = $arr[0];
foreach ($row as $key => $value) {
echo "<th>$key";
}
foreach ($arr as $row) {
echo "<tr>";
foreach ($row as $value) {
echo "<td>$value&nbsp;";
}
}
?>
</table><br>
<button id="red" type="submit" name="foo"
value="1">Update</button><br><br>
</form>
....
Reply With Quote
  #2 (permalink)  
Old 05-18-2006
Drakazz
 
Posts: n/a
Default Re: db table column name to table header name

$names=array("b_date"=>"Birthdate"); // Add more!!

foreach ($row as $key => $value) {
echo "<th>".$names[$key]."</th>";
}

anyway, your coding is not very nice in both HTml and PHP:|

Reply With Quote
  #3 (permalink)  
Old 05-18-2006
George Mills
 
Posts: n/a
Default Re: db table column name to table header name

Drakazz wrote:
> $names=array("b_date"=>"Birthdate"); // Add more!!
>
> foreach ($row as $key => $value) {
> echo "<th>".$names[$key]."</th>";
> }
>
> anyway, your coding is not very nice in both HTml and PHP:|
>


Thanks Drakazz.

If your still looking for a host jaguarpc has php5 but you have to ask
for it by name, which I haven't yet. They're version of mysql is also a
little behind but they have been superb at granting requests so you
should be able to get a never version.

You think my html and php are not very nice, you should see my not very
nice sql statements, my not very nice javascript, and my not very nice
css. And if you think that is something you should see my html input
that dynamicly creates the sql statement that dynamicly creates the
javascript that dynamicly creates the css which dynamicly shows the
html. (Actually I haven't had to write that yet but I am getting closer
every day.)

You seem like a smart person to my Drakazz. If you have the free time
could you write an object-oriented scripting language for me that
transparently generates html and css and seamlessly queries databases
and you can run server side of client side with tags like <?php_server
foo(); ?> <?php_client bar(); ?>. Next week would be great. ;P

Just kidding,
George

Thanks for the coding tips I will try to clean up my code a little. At
one point I made sure all my html was xhtml compliant but it was a pain
and I got to the point where I didn't believe I was getting anything for
all the extra dotting i's and crossing t's.
Reply With Quote
  #4 (permalink)  
Old 05-18-2006
Drakazz
 
Posts: n/a
Default Re: db table column name to table header name

hm, again - do not use XHTML, because you do not know what you are
doing; Your pages will break.
HTML 4.01 is the standard that everyone should use.

And hey, I already throught you was joking there ;)

Bit of my code:
$user = User::FromPost($registerData);
if ( $user === false ) {
$site->setView("register.invalid");
}
else {
$r=$user->register(&$site);
if ( $r === false ) {
$site->setView("register.error");
}
else {
$site->setView("register.success");
}
}

Well if you really want something to make easily, there's a good
solution - Plone or something like that.
Currently, I am doing both the back (ugly bits) and front (the pretty
bits, like i pasted) on the site.
Though the back bits are not coded nicely at all because I do not
currently have any kind of framework based upon myself, to create SQL
queries etc.
There is a painful job, which was madce by Iain at
http://rocketsled.iaindooley.com/ (google it if you've got any problems
with the site, probably incorrect link). He is a good coder and knows
Java and PHP very well and is applying his Java OOP skills in ugly PHP
world :) A big thanks for the guy, working on enterprise technologies
:)

Just make sure that your HTML pages validate HTML 4.01 strict in w3's
validator. That'll be the best thing :)


Thank you :)

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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



All times are GMT +1. The time now is 05:29 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0