943,936 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2419
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 10th, 2007
0

Complex Query with PHP

Expand Post »
Hi.
I want to create a program for LIBRARY, I faced to problem on depositing book section (Giving book to someone), in this section there is a combo which should contian the books name, maybe we have from one book two, three (Quantity), if one of them given to some one then one should be less than Book Quantity, and if all of them given for deposit, then in the combo the name of that book must not appear, so I did this in MS ACCESS, now want to have this in PHP and MySQL, so I did the following but I dont know what is the problem:

PHP Syntax (Toggle Plain Text)
  1.  
  2. $qryDepositedBooks = select("SELECT tblDeposit.bookId AS [Book ID], Last(tblDeposit.depositId) AS [Last Deposited Book], Count(tblDeposit.depositId) AS [Total Deposited Book], tblBook.bookQuantity, tblDeposit.isBookReturn
  3. FROM tblBook LEFT JOIN tblDeposit ON tblBook.bookId = tblDeposit.bookId GROUP BY tblDeposit.bookId, tblBook.bookQuantity, tblDeposit.isBookReturn HAVING (((tblDeposit.isBookReturn)=0))");
  4.  
  5. $qryDepositedBooksForPersonnel = select("SELECT tblDeposit.*
  6. FROM $qryDepositedBooks LEFT JOIN tblDeposit $qryDepositedBooks.[Last Deposited Book] = tblDeposit.depositId");
  7.  
  8. $qryBooksReadyForDeposit = select("SELECT tblBook.bookName, tblBook.bookId, $qryDepositedBooks.[Total Deposited Book], $qryDepositedBooksForPersonnel.isBookReturn FROM (tblBook LEFT JOIN $qryDepositedBooks ON tblBook.bookId = $qryDepositedBooks.[Book ID]) LEFT JOIN $qryDepositedBooksForPersonnel ON tblBook.bookId = $qryDepositedBooksForPersonnel.bookId
  9. WHERE ((($qryDepositedBooks.[Total Deposited Book])<([tblBook]![bookQuantity]) Or ($qryDepositedBooks.[Total Deposited Book]) Is Null)) OR ((($qryDepositedBooksForPersonnel.isBookReturn)=1))
  10. ORDER BY $qryDepositedBooks.[Total Deposited Book] DESC");

in combo section:
PHP Syntax (Toggle Plain Text)
  1.  
  2. <td><select name="cboBook" id="cboBook">
  3.  
  4. <option></option>
  5. <?php
  6. for($i=0;$i<mysql_num_rows($qryBooksReadyForDeposit);$i++)
  7. {
  8. $b_code=mysql_fetch_assoc($qryBooksReadyForDeposit);
  9. ?>
  10. <option value="<?php print($b_code['bookId']); ?>"><?php print($b_code['bookName']); ?></option>
  11. <?php
  12. }
  13. ?>
  14.  
  15. </select></td>
I cant see anything in Combo
need your guide...
Similar Threads
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 10th, 2007
0

Re: Complex Query with PHP

I want to know how can I merge three queries together, if u see the above code, I have three queries, which I used one in other, How it is possible, plz some one guide me through this...
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 11th, 2007
0

Re: Complex Query with PHP

anyone plz help me through this problem, please...
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 11th, 2007
0

Re: Complex Query with PHP

Try the UNION function in SQL to merge 3 queries together..
Reputation Points: 28
Solved Threads: 71
Posting Pro
ryan_vietnow is offline Offline
578 posts
since Aug 2007
Oct 12th, 2007
0

Re: Complex Query with PHP

it is not complicated but give more details.
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Oct 17th, 2007
0

Re: Complex Query with PHP

PHP Syntax (Toggle Plain Text)
  1.  
  2. <body>
  3. <?php
  4. include ("../../ControlPanel/General/database.php");
  5. connect();
  6. $sqlpersonnel = select("SELECT personnelId, personnelCode, personnelName, personnelFamily FROM tblpersonnel ORDER BY personnelCode");
  7. //$sqlbook = select("SELECT bookId, bookCode, bookName FROM tblbook ORDER BY bookCode");
  8.  
  9. $qryDepositedBooks = select("SELECT tblDeposit.bookId AS [Book ID], Last(tblDeposit.depositId) AS [Last Deposited Book], Count(tblDeposit.depositId) AS [Total Deposited Book], tblBook.bookQuantity, tblDeposit.isBookReturn
  10. FROM tblBook LEFT JOIN tblDeposit ON tblBook.bookId = tblDeposit.bookId GROUP BY tblDeposit.bookId, tblBook.bookQuantity, tblDeposit.isBookReturn HAVING (((tblDeposit.isBookReturn)=0))");
  11. $qryDepositedBooksForPersonnel = select("SELECT tblDeposit.*
  12. FROM $qryDepositedBooks LEFT JOIN tblDeposit $qryDepositedBooks.[Last Deposited Book] = tblDeposit.depositId");
  13. $qryBooksReadyForDeposit = select("SELECT tblBook.bookName, tblBook.bookId, $qryDepositedBooks.[Total Deposited Book], $qryDepositedBooksForPersonnel.isBookReturn FROM (tblBook LEFT JOIN $qryDepositedBooks ON tblBook.bookId = $qryDepositedBooks.[Book ID]) LEFT JOIN $qryDepositedBooksForPersonnel ON tblBook.bookId = $qryDepositedBooksForPersonnel.bookId
  14. WHERE ((($qryDepositedBooks.[Total Deposited Book])<([tblBook]![bookQuantity]) Or ($qryDepositedBooks.[Total Deposited Book]) Is Null)) OR ((($qryDepositedBooksForPersonnel.isBookReturn)=1))
  15. ORDER BY $qryDepositedBooks.[Total Deposited Book] DESC");
  16.  
  17. disConnect();
  18. ?>
  19. <form id="frmDefineDeposit" name="frmDefineDeposit" method="post" action="saveDeposit.php">
  20. <table width="1000" border="0" align="center" cellpadding="3" cellspacing="3">
  21. <tr>
  22. <td width="256"><label>Select Personnel Info :</label>
  23. &nbsp;</td>
  24. <td width="523"><select name="cboPersonnel" id="cboPersonnel">
  25.  
  26. <option></option>
  27. <?php
  28. for($i=0;$i<mysql_num_rows($sqlpersonnel);$i++)
  29. {
  30. $p_code=mysql_fetch_assoc($sqlpersonnel);
  31. $p_info = $p_code['personnelCode'] . " - " . $p_code['personnelName'] . " - " . $p_code['personnelFamily'];
  32. ?>
  33. <option value="<?php print($p_code['personnelId']); ?>"><?php print($p_info); ?></option>
  34. <?php
  35. }
  36. ?>
  37.  
  38. </select>
  39. <span class="style1">*</span></td>
  40. </tr>
  41. <tr>
  42. <td><label>Select Book Info :</label>
  43. &nbsp;</td>
  44. <td><select name="cboBook" id="cboBook">
  45.  
  46. <option></option>
  47. <?php
  48. for($i=0;$i<mysql_num_rows($qryBooksReadyForDeposit);$i++)
  49. {
  50. $b_code=mysql_fetch_assoc($qryBooksReadyForDeposit);
  51. ?>
  52. <option value="<?php print($b_code['bookId']); ?>"><?php print($b_code['bookName']); ?></option>
  53. <?php
  54. }
  55. ?>
  56.  
  57. </select>
  58. <span class="style1">*</span></td>
  59. </tr>
  60. <tr>
  61. <td><label>Date Received :</label>
  62. &nbsp;</td>
  63. <td><input name="txtDateReceived" type="text" id="txtDateReceived" size="40" />
  64. <span class="style1">*</span></td>
  65. </tr>
  66. <tr>
  67. <td><label>Date Returned :</label>
  68. &nbsp;</td>
  69. <td><input name="txtDateReturned" type="text" size="40" id="txtDateReturned" /></td>
  70. </tr>
  71. <tr>
  72. <td><label>Select Type of Guarantee :</label>
  73. &nbsp;</td>
  74. <td><select name="cboGuarantee" id="cboGuarantee">
  75. <option></option>
  76. <option value="Library Card">Library Card</option>
  77. <option value="ID Card">ID Card</option>
  78. <option value="Student Card">Student Card</option>
  79. <option value="Passport">Passport</option>
  80. </select>
  81. </td>
  82. </tr>
  83. <tr>
  84. <td><label>Comment :</label>
  85. &nbsp;</td>
  86. <td><textarea name="txtComment" cols="80" rows="6" id="txtComment"></textarea></td>
  87. </tr>
  88. <tr>
  89. <td><input name="cmdDepositBook" type="button" class="cmd" id="cmdDepositBook" onclick="checkForm();" value="Deposit Book"/>
  90. <span class="style1">
  91. <input name="cmdBack" type="button" id="cmdBack" value="Back Main" onclick="window.location.href='../../ControlPanel/main.php';" class="cmd"/>
  92. </span></td>
  93. <td>&nbsp;</td>
  94. </tr>
  95. </table>
  96. </form>
  97. <?php
  98. if(isset($_GET['OK']))
  99. {
  100. ?>
  101. <script language="javascript"> alert('Book deposited successfully...'); </script>
  102. <?php
  103. }
  104. if(isset($_GET['notOK']))
  105. {
  106. ?>
  107. <script language="javascript"> alert('Sorry, Book did deposited!!!'); </script>
  108. <?php
  109. }
  110. ?>
  111. </body>

NOTE:
I want from those three queries, just the books which is ready for deposit shown in combo box, I did this in MS Access, but now want to migrate to PHP and MySQL, so plz someone help and guide me through this ...

I want to have the same queries of the attachment in php and MySQL
Attached Files
File Type: zip LIBRARY.zip (69.5 KB, 12 views)
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 17th, 2007
0

Re: Complex Query with PHP

ok. i will work on this tonight and let you know...
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Oct 17th, 2007
0

Re: Complex Query with PHP

Thanks for ur help...
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 17th, 2007
0

Re: Complex Query with PHP

thank you for this kinda question... i needed to refresh my sql knowledge i m almost donee
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Oct 17th, 2007
0

Re: Complex Query with PHP

i did some changes and attached sql dump...
Attached Files
File Type: zip test.zip (4.3 KB, 20 views)
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: 7x7 Forced Matrix Script
Next Thread in PHP Forum Timeline: PHP 4.3.11 and problems with $HTTP_SERVER_VARS['REQUEST_URI']?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC