This is a discussion on "check query results values" within the PHP Forum section. This forum, and the thread "check query results values are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
check query results values
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
check query results values
Hi guys
i have two tables a customer and package table. a customer can have many packages. how i can i set a status in the customer table to 'complete' if all the packages in the package table that relate to that customer are set to 'paid'? i can do a simple select statement but how will i know if all the status rows returned from packages are set to 'paid'. any help would be great. |
|
|
|
#2
|
|||
|
|||
|
Re: check query results values
This seams a little clunky but it should work. There might be a better way of doing it though
I am assuming you have the two tables that you said and that each customer has a number (id) and each package references that in a field called "cust_id". Also, lets say that "paid" is a field in the packages which is set to 0 if it's not paid and 1 if it is.
Last edited by Steve Mellor; Apr 11th, 2007 at 12:36. Reason: Ammended incorrect variable |
|
#3
|
|||
|
|||
|
Re: check query results values
Ok, this is slightly cleaner. It removed the need for the loop.
|
|
#4
|
||||
|
||||
|
Re: check query results values
Quote:
It may seem counterintuitive to bracket a php variable with single quotes, but doing this in a php/mysql query will output the value of the variable inside literal single quote marks, just as you want it to. This isn't limited to mysql queries. This code
As long as I'm posting on this, I have never liked the unnecessary unscrambling needed for concatenating variables into text sentences. IMO it's far better to enclose echo in double quotes whenever a variable is going to appear. The only perceived difficulty arises when you have an echo of a html expression where you need a lot of internal tag parameters, such as a form insert or img. You might want to enclose the echo in single quotes, because you want to avoid a great mass of escaped double quotes. The solution is actually simple once you think to try it. Single quotes work just fine for tag parameters, whether textual or variable.
Understanding these tricks for echo "..."; will save the coder a fair amount of time and trouble in coding, and the resulting code will be a lot easier to read. Well, as long as I'm editing, here's another trick some people might not know. You can close and reopen php as often as you want, right in the middle of an "if" clause, and the php will work just fine. Simple example:
heredoc is another simplifying method for long masses of echoes/prints, but the syntax can get tricky cross-browser. Last edited by masonbarge; Apr 11th, 2007 at 14:18. |
|
#5
|
|||
|
|||
|
Re: check query results values
thanks for your help guys, all sorted. much appreciated.
|
![]() |
| Tags |
| query results |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Displaying Query Results Aesthtically | chubs | Starting Out | 1 | May 5th, 2008 13:39 |
| Negative values in divs (layout query) | Bocaj | Web Page Design | 1 | Mar 30th, 2008 09:48 |
| Query question - can I return values for records not found? | Donny Bahama | Databases | 5 | Aug 21st, 2006 11:39 |
| VB Code to Calculate Query Results | Imara96 | Databases | 1 | Jun 20th, 2006 22:20 |
| Assign string values to integer values of a session variable | Andy K | Classic ASP | 1 | Jul 13th, 2005 08:29 |