Page 1 of 1

employee directory

Posted: Wed Feb 25, 2004 3:42 pm
by babynerd
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.

Posted: Wed Feb 25, 2004 3:50 pm
by pickle
Hmm, not sure exactly what your problem is. Maybe a code example would help.

Posted: Wed Feb 25, 2004 4:03 pm
by d3ad1ysp0rk
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;
}

Posted: Wed Feb 25, 2004 4:18 pm
by babynerd
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>

Posted: Wed Feb 25, 2004 4:36 pm
by pickle
Your code is as follows, but inside PHP delimiters for easier reading:

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>
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);
//***************
// 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>

Posted: Wed Feb 25, 2004 4:43 pm
by babynerd
Pikcle,

You assumption is correct. all of the other fields in the table are changing execpt for the email one.

Posted: Thu Feb 26, 2004 10:04 am
by babynerd
I tried the unset line that you suggested but it still comes up the same. How would I reset $email on every loop?

Posted: Thu Feb 26, 2004 11:11 am
by pickle
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.

Posted: Thu Feb 26, 2004 11:25 am
by babynerd
Thxs for all the help it's working now.

Posted: Thu Feb 26, 2004 11:51 am
by pickle
What exactly fixed your problem? I'm curious to know.

Posted: Thu Feb 26, 2004 11:55 am
by babynerd
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>";?>