I have developed an address book using php and mysql.I have all the contacts list in a table with check boxes.Now that i want to create mailing labels for the checked contacts...i.e. ,the arrangements of addresses should be modified in such a way that there should be 5 addresses in a row of the table...I have done some coding but just dont know how to retrieve the checked contacts..Also. .i have some problem in creating labels in which some contacts are missing while listing out row-wise.My code is as follows:
and the code for label page is:
Code:
<?php
$label=mysql_query("select * from address_book where Name LIKE '%$_POST[searchfields]%' or Company LIKE '%$_POST[searchfields]%'") or die("Query failed ".mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contacts List</title>
<SCRIPT LANGUAGE="JavaScript">
function CheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}
function UnCheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
</script>
</head>
<body>
<table width="95%" border="0" align="center" cellpadding="4" cellspacing="0" id="t3_tblbg">
<tbody>
<tr>
<td align="center">
<h3 class="tr1">Create Labels</h3>
</td>
</tr>
<tr>
<td>
<form method="post" name="managecontact" action="labelpage.php">
<table cellspacing="0" cellpadding="4" align="center" width="100%">
<tr>
<th></th>
<th align="left" class="tr" width="25%">Name</th>
<th align="left" class="tr" width="25%">Company</th>
<th align="left" class="tr" width="20%">Mobile Number</th>
<th align="left" class="tr" width="20%">City</th>
</tr>
<?
$count=mysql_num_rows($label);
if($count>0)
{
while($resultset=mysql_fetch_array($label)) {?>
<TR>
<td><input type="checkbox" name="checkbox" id="checkbox"></td>
<td width="10%" align="left" class="tr">
<a href="result.php?nameID=<? echo $resultset['id'];?>"><? echo $resultset['Name']; ?></a></td>
<td align="left" class="tr"><? echo $resultset['Company']; ?></td>
<td align="left" class="tr"><? echo $resultset['Mobile']; ?></td>
<td align="left" class="tr"><? echo $resultset['off_City']; ?></td>
</tr>
<? } } ?>
<tr><td colspan="5" align="center"><input type="submit" name="label" id="label" value="Create Label" />
<input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.managecontact.checkbox)">
<input type="button" name="Un_CheckAll" value="Uncheck All" onClick="UnCheckAll(document.managecontact.checkbox)"></td></tr>
</table>
</form>
</td>
</tr>
</tbody>
</table>
</body>
</html>
and the code for label page is:
Code:
<?php
include "connection.php";
$label=mysql_query("select * from address_book") or die("Query failed ".mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table cellspacing="20" cellpadding="20" align="center" width="100%" cols="5">
<tr>
<?
$i=1;
while($resultset=mysql_fetch_array($label)) {
if($i<=5) {
?>
<td>
<? echo $resultset['Name']; ?><br />
<? echo $resultset['Company']; ?><br />
<? echo $resultset['off_Street']; ?><br />
<? echo $resultset['off_Location']; ?><br />
<? echo $resultset['off_City']; ?><br />
<? echo $resultset['off_State']; ?><br />
<br />
</td>
<? }
else
{
$i=0;
?>
<tr>
<?
}
$i++;
} ?>
</tr>
</table>
</body>
</html>
Comment