RE: output formatting question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



1. Get the result set in an array: $result

Now, do this:

<?php
foreach($result as $row) {
  $first = $row['first_name'];
  $last = $row['last_name'];
  $phone = $row['phone'];
/*
 I'm assuming, perhaps incorrectly, that your phone is stored in the
database without any dashes, e.g. 2135551212, which is the most
efficient way. You'll need to assure that the area code is always
entered, though.
*/
    echo '
      <TR><TD>' . $first . ' ' . $last . '</td>
          <TD>(' . substr($phone,0,3) . ') ' . substr($phone,3,3) . '-'
. substr($phone,6,4) . '</td></TR>';

}

?>

That will give you in HTML:
<TR><TD>John Smith</TD><TD>(213) 555-1212</TD></TR>


Some other formatting hints for this:

$first = ucfirst(strtolower($first));

will give you "John" even if the DB has "JOHN" or "john" 

Gary Every
Sr. UNIX Administrator
Ingram Entertainment Inc.
2 Ingram Blvd, La Vergne, TN 37089
"Pay It Forward!"

-----Original Message-----
From: redhat [mailto:redhat@xxxxxxxxxxxxxxx] 
Sent: Tuesday, March 09, 2004 9:24 AM
To: phplist
Subject:  output formatting question

I have a small database of employee names and phone extensions that I
have put together.  I have also put together a very simple php page that
enables endusers to pull up this directory listing.  My question is
simple, the output right now is in one long column (actually, three,
first name, last name, extension) and I would like to break the page
down into two columns (consisting of the three database columns each). 
I am not a php programmer and would appreciate any help.  If there is a
good article out there that someone could point me to that would be
great - that is how I figured out how to do the other.
thanks,
DF

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux