Greetings, I seem to be having some kind of problem and the only
thing I can figure out is that it may have to do with my multiple
query or something with the $session variable.
Purpose: Trying to display membership information after the member logs in. There is a check on the login and if everything matches, it sets some session variables:
session_register('first_name');
$SESSION['first_name'] = $first_name;
session_register('last_name');
$SESSION['last_name'] = $last_name;
session_register('mem_email_addr');
$_SESSION['mem_email_addr'] = $mem_email_addr;
Then there is a redirect to the new page. This new page makes two different queries to two different tables in a single database.
Both queries seem to work as the proper information from the database is displayed and I make a $num variable to query the number of rows for the second query (and have it displayed). The problem is that the $num = mysql_num_rows($result2) displays the correct number of rows matching the users email address, but when I have it list the surnames for that email address, the list is always short by 1 and I cannot figure out why. Here is my code:
session_start();
include("../../../includes/db.inc");
$dbh=@mysql_connect ("$dbhost", "$dbuser", "$dbpass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbname");
echo "Welcome ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."! You have made it to the members area!<br /><br />";
$member = $_SESSION['mem_email_addr'];
if (isset($member))
{
$qryMember = "SELECT * FROM membership WHERE mem_email_addr LIKE '%$member%'";
$qrySurnames = "SELECT nm_email,nm_surname FROM surnames WHERE nm_email LIKE '%$member%' ORDER BY nm_surname";
}
$result1 = mysql_query($qryMember);
$result2 = mysql_query($qrySurnames);
$row1 = mysql_fetch_array($result1);
$row2 = mysql_fetch_array($result2);
$num = mysql_num_rows($result2);
echo "<TABLE BORDER=0 cellpadding=5>";
echo "<tr bgcolor=\"#9999CC\"><td width=45%><strong>Your Membership Information</strong></td></tr>";
echo "<tr><td>Contact email address: <A HREF=\"mailto:$member\">$member</td></tr>";
echo "<tr><td>Mailing address: <BR>{$row1['mem_addr']}<BR>{$row1['mem_city']}, {$row1['mem_state']} {$row1['mem_zip']}<BR>{$row1['mem_country']}</td></tr>";
echo "<tr><td>Membership Level: {$row1['mem_type']}<BR>Expires: {$row1['mem_exp']}</td></tr>";
if (strcmp("No", $row1['mem_directory'])==0) {
echo "<tr><td>You have opted to <em>NOT</em> include your information in our Annual Membership Directory</td></tr>";
}
if (strcmp("Yes", $row1['mem_directory'])==0) {
echo "<tr><td>You have opted to include your information in our Annual Membership Directory</td></tr>";
}
echo "<tr><td>Surnames being researched: ($num)</td></tr>";
echo "<tr><td>";
while ($row2 = mysql_fetch_array($result2))
{
echo "<LI>{$row2['nm_surname']}<br>";
}
echo "</td></tr>";
echo "</TABLE>";
echo "<a href=logout.php>Logout</a>";
Any ideas? It always cuts the top surname from the ordered list.