employee directory
Moderator: General Moderators
employee directory
I have been asked to create an online employee directory. The only probem I am having is I can not get the email address that I retrive from the database to be to be mailto links. I have been able to get it grab the first address in the database but then it just sends that address to everyother row instead of continuing to grab emails and placing them next to each persons name.
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
if they're indexed, you can use
Code: Select all
for($i=0;$i<$rows;$i++){
$sql = "SELECT email FROM table WHERE id = '$i' LIMIT 1";
$email = mysql_result(mysql_query($sql), 0,0);
echo <<<EOT
<a href="mailto:$email">$email</a><br>
EOT;
}pickle wrote:Hmm, not sure exactly what your problem is. Maybe a code example would help.
Header code
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_empdirdb, $empdirdb);
$query_Recordset1 = "SELECT employeedir.FullName, employeedir.Title, employeedir.PhoneNum, employeedir.EmailAddress, employeedir.Department, employeedir.Program FROM employeedir ORDER BY employeedir.Department, employeedir.Program, employeedir.FullName";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $empdirdb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . implode("&", $newParams);
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
$Email=$row_Recordset1['EmailAddress'];
?>
body code
<tr>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['FullName']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['Title']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['PhoneNum']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo "<a href="mailto:" . $Email . "">" . $Email . "</a>";?> </div>
</td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['Department']; ?></div></td>
<td width="15%"> <div class="dir"><?php echo $row_Recordset1['Program']; ?></div></td>
</tr>
Your code is as follows, but inside PHP delimiters for easier reading:
I'm assuming the table is output in a loop for each person? If so, is it possible that $Email isn't being reset on every iteration of the loop? The rest of the user's attributes would be updated as the row changes. If that's not the case, try unsetting the $Email variable just before it is set:
Code: Select all
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_empdirdb, $empdirdb);
$query_Recordset1 = "SELECT employeedir.FullName, employeedir.Title, employeedir.PhoneNum, employeedir.EmailAddress, employeedir.Department, employeedir.Program FROM employeedir ORDER BY employeedir.Department, employeedir.Program, employeedir.FullName";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $empdirdb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . implode("&", $newParams);
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
$Email=$row_Recordset1['EmailAddress'];
?>
body code
<tr>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['FullName']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['Title']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['PhoneNum']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo "<a href="mailto:" . $Email . "">" . $Email . "</a>";?> </div>
</td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['Department']; ?></div></td>
<td width="15%"> <div class="dir"><?php echo $row_Recordset1['Program']; ?></div></td>
</tr>Code: Select all
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_empdirdb, $empdirdb);
$query_Recordset1 = "SELECT employeedir.FullName, employeedir.Title, employeedir.PhoneNum, employeedir.EmailAddress, employeedir.Department, employeedir.Program FROM employeedir ORDER BY employeedir.Department, employeedir.Program, employeedir.FullName";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $empdirdb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . implode("&", $newParams);
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
//***************
// Change here
//***************
unset($Email);
$Email=$row_Recordset1['EmailAddress'];
?>
body code
<tr>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['FullName']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['Title']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['PhoneNum']; ?></div></td>
<td width="17%"> <div class="dir"><?php echo "<a href="mailto:" . $Email . "">" . $Email . "</a>";?> </div>
</td>
<td width="17%"> <div class="dir"><?php echo $row_Recordset1['Department']; ?></div></td>
<td width="15%"> <div class="dir"><?php echo $row_Recordset1['Program']; ?></div></td>
</tr>Have you tried not putting the email address in a variable, but rather just echoing $row_Recordset1['Email'] ? To reset the variable, just call unset($Email) at the beginning of every iteration of the loop.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
I took out the $email var and just did this to the body:
Code: Select all
<?php echo "<a href="mailto:" . $row_Recordset1['EmailAddress'] . "">" . $row_Recordset1['EmailAddress'] . "</a>";?>