| | |
Complex Query with PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 199
Reputation:
Solved Threads: 0
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:
in combo section:
I cant see anything in Combo
need your guide...
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)
$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 FROM tblBook LEFT JOIN tblDeposit ON tblBook.bookId = tblDeposit.bookId GROUP BY tblDeposit.bookId, tblBook.bookQuantity, tblDeposit.isBookReturn HAVING (((tblDeposit.isBookReturn)=0))"); $qryDepositedBooksForPersonnel = select("SELECT tblDeposit.* FROM $qryDepositedBooks LEFT JOIN tblDeposit $qryDepositedBooks.[Last Deposited Book] = tblDeposit.depositId"); $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 WHERE ((($qryDepositedBooks.[Total Deposited Book])<([tblBook]![bookQuantity]) Or ($qryDepositedBooks.[Total Deposited Book]) Is Null)) OR ((($qryDepositedBooksForPersonnel.isBookReturn)=1)) ORDER BY $qryDepositedBooks.[Total Deposited Book] DESC");
in combo section:
PHP Syntax (Toggle Plain Text)
<td><select name="cboBook" id="cboBook"> <option></option> <?php for($i=0;$i<mysql_num_rows($qryBooksReadyForDeposit);$i++) { $b_code=mysql_fetch_assoc($qryBooksReadyForDeposit); ?> <option value="<?php print($b_code['bookId']); ?>"><?php print($b_code['bookName']); ?></option> <?php } ?> </select></td>
need your guide...
•
•
Join Date: Aug 2007
Posts: 199
Reputation:
Solved Threads: 0
PHP Syntax (Toggle Plain Text)
<body> <?php include ("../../ControlPanel/General/database.php"); connect(); $sqlpersonnel = select("SELECT personnelId, personnelCode, personnelName, personnelFamily FROM tblpersonnel ORDER BY personnelCode"); //$sqlbook = select("SELECT bookId, bookCode, bookName FROM tblbook ORDER BY bookCode"); $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 FROM tblBook LEFT JOIN tblDeposit ON tblBook.bookId = tblDeposit.bookId GROUP BY tblDeposit.bookId, tblBook.bookQuantity, tblDeposit.isBookReturn HAVING (((tblDeposit.isBookReturn)=0))"); $qryDepositedBooksForPersonnel = select("SELECT tblDeposit.* FROM $qryDepositedBooks LEFT JOIN tblDeposit $qryDepositedBooks.[Last Deposited Book] = tblDeposit.depositId"); $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 WHERE ((($qryDepositedBooks.[Total Deposited Book])<([tblBook]![bookQuantity]) Or ($qryDepositedBooks.[Total Deposited Book]) Is Null)) OR ((($qryDepositedBooksForPersonnel.isBookReturn)=1)) ORDER BY $qryDepositedBooks.[Total Deposited Book] DESC"); disConnect(); ?> <form id="frmDefineDeposit" name="frmDefineDeposit" method="post" action="saveDeposit.php"> <table width="1000" border="0" align="center" cellpadding="3" cellspacing="3"> <tr> <td width="256"><label>Select Personnel Info :</label> </td> <td width="523"><select name="cboPersonnel" id="cboPersonnel"> <option></option> <?php for($i=0;$i<mysql_num_rows($sqlpersonnel);$i++) { $p_code=mysql_fetch_assoc($sqlpersonnel); $p_info = $p_code['personnelCode'] . " - " . $p_code['personnelName'] . " - " . $p_code['personnelFamily']; ?> <option value="<?php print($p_code['personnelId']); ?>"><?php print($p_info); ?></option> <?php } ?> </select> <span class="style1">*</span></td> </tr> <tr> <td><label>Select Book Info :</label> </td> <td><select name="cboBook" id="cboBook"> <option></option> <?php for($i=0;$i<mysql_num_rows($qryBooksReadyForDeposit);$i++) { $b_code=mysql_fetch_assoc($qryBooksReadyForDeposit); ?> <option value="<?php print($b_code['bookId']); ?>"><?php print($b_code['bookName']); ?></option> <?php } ?> </select> <span class="style1">*</span></td> </tr> <tr> <td><label>Date Received :</label> </td> <td><input name="txtDateReceived" type="text" id="txtDateReceived" size="40" /> <span class="style1">*</span></td> </tr> <tr> <td><label>Date Returned :</label> </td> <td><input name="txtDateReturned" type="text" size="40" id="txtDateReturned" /></td> </tr> <tr> <td><label>Select Type of Guarantee :</label> </td> <td><select name="cboGuarantee" id="cboGuarantee"> <option></option> <option value="Library Card">Library Card</option> <option value="ID Card">ID Card</option> <option value="Student Card">Student Card</option> <option value="Passport">Passport</option> </select> </td> </tr> <tr> <td><label>Comment :</label> </td> <td><textarea name="txtComment" cols="80" rows="6" id="txtComment"></textarea></td> </tr> <tr> <td><input name="cmdDepositBook" type="button" class="cmd" id="cmdDepositBook" onclick="checkForm();" value="Deposit Book"/> <span class="style1"> <input name="cmdBack" type="button" id="cmdBack" value="Back Main" onclick="window.location.href='../../ControlPanel/main.php';" class="cmd"/> </span></td> <td> </td> </tr> </table> </form> <?php if(isset($_GET['OK'])) { ?> <script language="javascript"> alert('Book deposited successfully...'); </script> <?php } if(isset($_GET['notOK'])) { ?> <script language="javascript"> alert('Sorry, Book did deposited!!!'); </script> <?php } ?> </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
![]() |
Similar Threads
- Sending pic attachments via PHP form (PHP)
- PHP Form, SQL connectivity issues, please help. (MySQL)
- help with php and javascript (PHP)
- Issue with the LIKE expression and php (PHP)
- Please help me out with MySQL query (MySQL)
- Help with a smyql query and php (MySQL)
- php connection to mysql headache (PHP)
- PHP/SQL query help (PHP)
- I had a experience of a website coded in PHP (PHP)
- Retreiving variables from a sql query into a form (PHP)
Other Threads in the PHP Forum
- Previous Thread: 7x7 Forced Matrix Script
- Next Thread: How to insert new line character
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary broken cakephp checkbox class cms code codingproblem combobox cron curl database date display domain dynamic echo email error file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla js limit link load login mail malfunctioning menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset up-to-date update upload url validation validator variable video web webapplications websitecontactform youtube





i m almost donee 