By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Creating mailing labels

P: 40
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:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $label=mysql_query("select * from address_book where Name LIKE '%$_POST[searchfields]%' or Company LIKE '%$_POST[searchfields]%'") or die("Query failed  ".mysql_error());
  3. ?>
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>Contacts List</title>
  10. <SCRIPT LANGUAGE="JavaScript">
  11. function CheckAll(chk)
  12. {
  13.     for (i = 0; i < chk.length; i++)
  14.     chk[i].checked = true ;
  15. }
  16.  
  17. function UnCheckAll(chk)
  18. {
  19.     for (i = 0; i < chk.length; i++)
  20.     chk[i].checked = false ;
  21. }
  22. </script>
  23. </head>
  24. <body>
  25. <table width="95%" border="0" align="center" cellpadding="4" cellspacing="0" id="t3_tblbg">
  26.   <tbody>
  27.     <tr>
  28.    <td align="center">
  29.   <h3 class="tr1">Create Labels</h3>
  30.   </td>
  31.   </tr>
  32.     <tr>
  33.       <td>
  34.       <form method="post" name="managecontact" action="labelpage.php">
  35.       <table cellspacing="0" cellpadding="4" align="center" width="100%">
  36.  
  37.          <tr>
  38.          <th></th>
  39.          <th align="left" class="tr" width="25%">Name</th>
  40.          <th align="left" class="tr" width="25%">Company</th>
  41.          <th align="left" class="tr" width="20%">Mobile Number</th>
  42.          <th align="left" class="tr" width="20%">City</th>
  43.          </tr>
  44.           <? 
  45.          $count=mysql_num_rows($label);
  46.          if($count>0)
  47.          {
  48.          while($resultset=mysql_fetch_array($label)) {?>
  49.           <TR>
  50.           <td><input type="checkbox" name="checkbox" id="checkbox"></td>
  51.           <td width="10%" align="left" class="tr">
  52.           <a href="result.php?nameID=<? echo $resultset['id'];?>"><? echo $resultset['Name']; ?></a></td>
  53.           <td align="left" class="tr"><? echo $resultset['Company']; ?></td> 
  54.           <td align="left" class="tr"><? echo $resultset['Mobile']; ?></td> 
  55.           <td align="left" class="tr"><? echo $resultset['off_City']; ?></td> 
  56.           </tr>
  57.           <?  } }  ?>
  58.          <tr><td colspan="5" align="center"><input type="submit" name="label" id="label" value="Create Label" />
  59.          <input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.managecontact.checkbox)">
  60.          <input type="button" name="Un_CheckAll" value="Uncheck All" onClick="UnCheckAll(document.managecontact.checkbox)"></td></tr>
  61.       </table> 
  62.         </form>
  63.    </td>
  64.    </tr>
  65.    </tbody>
  66.    </table>
  67. </body>
  68. </html>
  69.  


and the code for label page is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include "connection.php";
  3. $label=mysql_query("select * from address_book") or die("Query failed  ".mysql_error());
  4. ?>
  5.  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  10. <title>Untitled Document</title>
  11. </head>
  12. <body>
  13. <table cellspacing="20" cellpadding="20" align="center" width="100%" cols="5">
  14.            <tr>
  15.            <? 
  16.            $i=1;
  17.            while($resultset=mysql_fetch_array($label)) { 
  18.            if($i<=5) {
  19.            ?>
  20.           <td>
  21.             <? echo $resultset['Name']; ?><br />
  22.           <? echo $resultset['Company']; ?><br /> 
  23.           <? echo $resultset['off_Street']; ?><br />
  24.           <? echo $resultset['off_Location']; ?><br />
  25.           <? echo $resultset['off_City']; ?><br />
  26.           <? echo $resultset['off_State']; ?><br />
  27.           <br />
  28.           </td>
  29.           <?  }  
  30.           else
  31.           {
  32.           $i=0;
  33.           ?>
  34.           <tr>
  35.           <?
  36.           }
  37.           $i++;
  38.           } ?>
  39.           </tr>
  40.       </table>
  41. </body>
  42. </html>
  43.  
Sep 18 '08 #1
Share this Question
Share on Google+
2 Replies


ak1dnar
Expert 100+
P: 1,584
I think same question and answer is already posted here .Please post back if its not answered yet.
Sep 19 '08 #2

P: 40
I think same question and answer is already posted here .Please post back if its not answered yet.
No...this is quite different.that was about sending mails and this is related to creating labels
Sep 19 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.