Greetings everyone,
I have been using PHP and MySQL for a little over a year for some simple database retrieval and display on a webpage. I recently tried to do something different and the return was partially successful.
I have a simple church membership database that contains the fields: surname (text), given (text), fam_num (text), remarks (text) and stsp-p_memID (int, non zero, auto increment, primary). The fam_num field was created to have a unique family ID so that families with the same surname could be easily distinguished. The HTML coding is set so that when you click on a surname, the code passes the fam_num value, connects to the database and then returns all surnames that have the same fam_num value. The intent is to display all members of the same household. Sample data is as follows:
ADOMAITIS Antanas 00002 0000000002
ADOMAITIS Jonas 00003 0000000003
ADOMAITIS Agnieska 00003 0000000004
ADOMAITIS Alena 00003 0000000005
ADOMAITIS Jeronimas 00003 0000000006
ADOMAITIS Kastas 00004 0000000007
ADOMAITIS Ona 00004 0000000008
ADOMAITIS Rudolfas 00004
Using the above, Antanas is one family; Jonas, Agnieska, Alena, Jeronimas is another family, etc. Thus, when someone clicks Antanas on the webpage, it should just return his listing. However, I get a listings for all familes that have the value of '2' in it. Meaning, the script is returning all familes with a fam_num of 2, 12, 20-29, 32, 42...102...112...120-129...etc. I tried turning the field into a tiny integer but get the same problem. The solution is probably staring me in the face.
I am including the HTML code that passes the fam_num variable and the php code that is supposed to return the correct results:
<?php
include("");
$dbh=@mysql_connect ("$dbhost", "$dbuser", "$dbpass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbname");
//Set the number of columns for the page
$columns = 3;
$qrySurname__letter = "%";
// Output letters as links: (Ascii range from 65 to 90 are letters A to Z!)
// Trying to do this automatically without having to resort to hand coding // of every single link
for($x=65;$x<=90;$x++)
{
if ($x==ord($subsel)) echo "<b>".chr($x)."</b>";
else
echo "<a href=\"index2.html?letter=".chr($x)."\">".chr($x)."</a> ";
}
echo "<a href=\"index2.html\">Original View</a>";
$letter = $_GET["letter"];
if (isset($letter))
{
$qrySurname = "SELECT FROM 1929_mem WHERE surname LIKE '$letter%' ORDER BY surname";
} else {
$qrySurname = "SELECT FROM 1929_mem ORDER BY surname";
}
$result = mysql_query($qrySurname);
//Need to know the number of rows, so use this line
$num_rows = mysql_num_rows($result);
echo "<BR>(<em><strong>Total Number of Records in Database</strong></em><strong>:</strong>
<font color=\"#FF0000\"><strong>$num_rows</strong></font>)<br><br>";
//Set a new variable called $rows
$rows = ceil($num_rows / $columns);
//For this vertical display, need to run another loop, which will populate an array with our values
while($row = mysql_fetch_array($result)) {
$surname[] = $row['surname'];
$given[] = $row['given'];
$fam_num[] = $row['fam_num'];
$remarks[] = $row['remarks'];
}
echo "<TABLE BORDER=1 cellpadding=5 align=center>\n";
for ($i = 0; $i < $rows; $i++) {
echo "<tr>";
for ($j = 0; $j <$columns; $j++) {
if(isset($fam_num[$i + ($j $rows)])) {
echo "<td><li> <A HREF=\"JavaScript:newWindow('addinfo2.php?addinfo2=".$fam_num[$i + ($j $rows)]."','popup',420,320,'')\">".$surname[$i + ($j $rows)].", ".$given[$i + ($j $rows)]."</a></li> ";
}
}
echo "</tr>";
}
echo "</TABLE>";
$today = date("l dS of F Y h:i a");
print "<CENTER>Today is $today (server time)</CENTER>";
?>
PHP script
<?php
include("");
$dbh=@mysql_connect ("$dbhost", "$dbuser", "$dbpass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbname");
$addinfo2 = $_GET["addinfo2"];
echo "$addinfo2";
if (isset($addinfo2))
{
$qryHousehold = "SELECT surname,given,fam_num,remarks FROM 1929_mem WHERE fam_num LIKE '%$addinfo2%'";
}
$result = mysql_query($qryHousehold);
echo "<TABLE BORDER=0 cellpadding=5>";
echo "<tr bgcolor=\"#9999CC\">";
echo "<td width=45%><strong>Additional Information</strong></td>";
echo "</tr>";
echo "<tr><td><strong>Household members:</td></tr>";
echo "<tr><td>";
while ($row = mysql_fetch_array($result))
{
echo "<LI><b>{$row['surname']}</B>, {$row['given']} ({$row['remarks']})</em><br>";
}
echo "<tr><td><center><A HREF=\"Javascript:self.close();\">Close Window</A></center></td></tr>";
echo "</TABLE>";
?>
Anyone have any ideas?
TIA!