Ok, i'm a nOOb to php, but i imagine this is a fairly simple script that i just don't know how to write...any help is appreciated.
I'm using DWMx2004 on a .php page with mysql, dislaying a dynamic table-repeating region, of members, in which the phone number is optional.
my issue is the database has 3 fields for the phone number, area code, suffix and prefix...and i would like to format them in the standard (xxx)xxx-xxxx, now i did just insert a "(" before the dynamic info and a ")" after and so on, but it will still show up if the user doesn't include the info. What i need is a script that will see if there is 3 numbers there, and if so put () around them, and if not but and "N/A" or something like it.
SO, that being said, i think what i need is a preg_replace script or it might be a simple if/else statment, but like i said, i'm a noob! And i'm not too sure...i also am having the same trouble with my dates...its three fields also...ANY HELP is greatly appreciated!
here is some of the script:
<?php require_once('Connections/hero.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
?>
<?php
$maxRows_members = 10;
$pageNum_members = 0;
if (isset($_GET['pageNum_members'])) {
$pageNum_members = $_GET['pageNum_members'];
}
$startRow_members = $pageNum_members * $maxRows_members;
mysql_select_db($database_hero, $hero);
$query_members = "SELECT * FROM members ORDER BY `State` ASC";
$query_limit_members = sprintf("%s LIMIT %d, %d", $query_members, $startRow_members, $maxRows_members);
$members = mysql_query($query_limit_members, $hero) or die(mysql_error());
$row_members = mysql_fetch_assoc($members);
if (isset($_GET['totalRows_members'])) {
$totalRows_members = $_GET['totalRows_members'];
} else {
$all_members = mysql_query($query_members);
$totalRows_members = mysql_num_rows($all_members);
}
$totalPages_members = ceil($totalRows_members/$maxRows_members)-1;
mysql_select_db($database_hero, $hero);
$query_cleandate = "SELECT monthCD, dayCD, yearCD FROM members";
$cleandate = mysql_query($query_cleandate, $hero) or die(mysql_error());
$row_cleandate = mysql_fetch_assoc($cleandate);
$totalRows_cleandate = mysql_num_rows($cleandate);
mysql_select_db($database_hero, $hero);
$query_Birthday = "SELECT monthBD, dayBD, yearBD FROM members";
$Birthday = mysql_query($query_Birthday, $hero) or die(mysql_error());
$row_Birthday = mysql_fetch_assoc($Birthday);
$totalRows_Birthday = mysql_num_rows($Birthday);
mysql_select_db($database_hero, $hero);
$query_phonenumber = "SELECT * FROM members";
$phonenumber = mysql_query($query_phonenumber, $hero) or die(mysql_error());
$row_phonenumber = mysql_fetch_assoc($phonenumber);
$totalRows_phonenumber = mysql_num_rows($phonenumber);
mysql_select_db($database_hero, $hero);
$query_Recordset1 = "SELECT * FROM members";
$Recordset1 = mysql_query($query_Recordset1, $hero) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_hero, $hero);
$query_Recordset2 = "SELECT monthCD, dayCD, yearCD FROM members";
$Recordset2 = mysql_query($query_Recordset2, $hero) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td height="10" class="style7"><strong>Name</strong></td>
<td class="style9">City</td>
<td class="style9">State</td>
<td class="style9">Email</td>
<td width="50" class="style9">Phone Number</td>
<td class="style9">Clean Date</td>
<td class="style9">Birthday</td>
<td class="style9">Comments</td>
</tr>
<?php do { ?>
<tr>
<td height="71" class="style7"><?php echo $row_members['name']; ?></td>
<td class="style7"><?php echo $row_members['City']; ?></td>
<td class="style7"><?php echo $row_members['State']; ?></td>
<td class="style7"><?php echo $row_members['Email']; ?></td>
<td width="50" class="style7"><p> <?php echo $row_members['areacode']; ?>
<?php echo $row_members['exchange']; ?>
<?php echo $row_members['phonenum4']; ?></p>
</td>
<td class="style7"></p>
<?php echo $row_members['monthCD']; ?>
<?php echo $row_members['dayCD']; ?>
<?php echo $row_members['yearCD']; ?></td>
<td class="style7"><?php echo $row_members['monthBD']; ?><?php echo $row_members['dayBD']; ?><?php echo $row_members['yearBD']; ?> </td>
<td class="style7"><?php echo $row_members['Comments']; ?></td>
</tr>
<?php } while ($row_members = mysql_fetch_assoc($members)); ?>
</table>
<p>
</p>
<!-- InstanceEndEditable --></td>
</tr>
</table>
<?php
mysql_free_result($Recordset1);
mysql_free_result($Recordset2);
mysql_free_result($members);
mysql_free_result($cleandate);
mysql_free_result($Birthday);
mysql_free_result($phonenumber);
?>