943,925 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2419
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 18th, 2007
0

Re: Complex Query with PHP

Thanks very much for doing that...I will test it and will post the result...
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 19th, 2007
0

Re: Complex Query with PHP

Mr. fatihpiristine, thank u much for the attachment, but there is a misunderstanding...I have the below problem...

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:

$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");


// $qryDepositedBooks, $qryDepositedBooksForPersonnel , $qryBooksReadyForDeposit as you see I created these queries, but I dont know how to use them with each other queries

in combo section:

<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>

Just in this combo I want to see the bookName from $qryBooksReadyForDeposit, nothing more...

need your guide...
Last edited by tanha; Oct 19th, 2007 at 4:19 am.
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 19th, 2007
0

Re: Complex Query with PHP

i fixed your code. what happened to that??

it was working.
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Oct 19th, 2007
0

Re: Complex Query with PHP

yeah it is working, but in the combo box it just shows the books which given to deposit, not the books which exist in Library...

if possible please make those above three queries which I posted before, and in the combo just displying the bookName from $qryBooksReadyForDeposit...
Thanks much
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 19th, 2007
0

Re: Complex Query with PHP

change sql query syntax...
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Oct 19th, 2007
0

Re: Complex Query with PHP

could you please be in more detail, because I am not so expert...I am here now...thanks
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 19th, 2007
0

Re: Complex Query with PHP

sorry.. i dont have time to code that pages again. i deleted them already. as far as i remember,
i saved a php file called readytodeposit, it lists the books which are ready to deposit.. ( and drops the numbers of deposited books from the initial quantity... // ig: u have 20 same books. each time it drops one. as you wanted. if the quantity to deposit = 0 then, you will not the name of the book.

i did everything in sql query if you read the codes you will understand.


your sql syntax has many problems... do not try to post such that sql query syntax via php files.. you ll get error..
Last edited by fatihpiristine; Oct 19th, 2007 at 7:36 am.
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Oct 20th, 2007
0

Re: Complex Query with PHP

Ok, thanks anyway...I will go through that hardly, but could u please give the idea how to use one variable which has query result inside it, into another variable same as I did?
I mean how to merge one query inside another query???
That would be very nice of you...
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 21st, 2007
0

Re: Complex Query with PHP

Thanks very much Mr. fatihpiristine for the code, it is working very very good...I will post the code as soon as possible...Thanks again
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 2007
Oct 22nd, 2007
0

Re: Complex Query with PHP

Thanks a world from Mr. fatihpiristine providing this code for me, this is exactly what I wanted to do...Thanks again

PHP Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3. $qryDepositedBooks = select("
  4.  
  5. SELECT
  6. tblbook.bookId,
  7. tblbook.bookCode,
  8. tblbook.bookStore,
  9. tblbook.bookName,
  10. lstsubject.subName,
  11. tblbook.bookQuantity,
  12. tblbook.bookQuantity - (select count(tbldeposit.depositId) from tbldeposit where tblbook.bookId = tbldeposit.bookId ) as Deposited
  13. from tblbook, lstsubject
  14. where
  15. tblbook.bookSubject = lstsubject.subId and
  16. ( tblbook.bookQuantity - (select count(tbldeposit.depositId) from tbldeposit where tblbook.bookId = tbldeposit.bookId ) ) > 0
  17.  
  18.  
  19.  
  20. ");
  21. ?>
Reputation Points: 8
Solved Threads: 1
Posting Whiz in Training
tanha is offline Offline
217 posts
since Aug 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