This is a discussion on Help with browsing db within the PHP Language forums, part of the PHP Programming Forums category; Need some opinions on how best to display in excess of 14K records based on users search criteria. Application Concept: ----------------------- [...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Need some opinions on how best to display in excess of 14K records
based on users search criteria. Application Concept: ----------------------- [1] User enters various search criteria (as many as 13 different fields) AND can select 2 fields to sort on. [2] User can also limit the results displayed per page [3] Once the user presses "Submit", the SQL string is built and the DB is queried. [4] Results are displayed to the user, x records per page with "Next <<->> Previous" link under results. If user did not choose a limit, I limit to 20 records per page. [5] Clicking on the Next or Previous links walks the user through the data. Application Logic ----------------------- PHP Code:
something here I have never done before. In other applications I have developed, I have only used the Next - Previous link idea when I have simply pulled the entire database so that the user could browse the db. This time though I need to allow the user to set parameters before browsing. Here's my problem from a code perspective: PHP Code:
whenever Next or Previous is clicked. Anybody have a suggestion as to how I can get this to work? TIA rk |
|
|||
|
Hi,
redneck_kiwi wrote: > > Need some opinions on how best to display in excess of 14K records > based on users search criteria. > > Application Concept: > ----------------------- > > [1] User enters various search criteria (as many as 13 different > fields) AND can select 2 fields to sort on. > [2] User can also limit the results displayed per page > [3] Once the user presses "Submit", the SQL string is built and the DB > is queried. > [4] Results are displayed to the user, x records per page with "Next > <<->> Previous" link under results. If user > did not choose a limit, I limit to 20 records per page. > [5] Clicking on the Next or Previous links walks the user through the > data. > > Application Logic > ----------------------- > > PHP Code:
> Sounds simple, right? Basically it is, however I am attempting to do > something here I have never done before. In other > applications I have developed, I have only used the Next - Previous > link idea when I have simply pulled the entire database > so that the user could browse the db. This time though I need to allow > the user to set parameters before browsing. > > Here's my problem from a code perspective: > > PHP Code:
> My problem appears to be that my variables are not carrying over > whenever Next or Previous is clicked. Anybody have a suggestion as to > how I can get this to work? Hi, I didn't actually read through all your code, but you should probably validate, then set the validated variables as session variables. Then you can just use the session variables as-is on any subsequent page and use them to build your query. Shawn -- Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com |
|
|||
|
Hi,
redneck_kiwi wrote: > > Need some opinions on how best to display in excess of 14K records > based on users search criteria. > > Application Concept: > ----------------------- > > [1] User enters various search criteria (as many as 13 different > fields) AND can select 2 fields to sort on. > [2] User can also limit the results displayed per page > [3] Once the user presses "Submit", the SQL string is built and the DB > is queried. > [4] Results are displayed to the user, x records per page with "Next > <<->> Previous" link under results. If user > did not choose a limit, I limit to 20 records per page. > [5] Clicking on the Next or Previous links walks the user through the > data. > > Application Logic > ----------------------- > > PHP Code:
> Sounds simple, right? Basically it is, however I am attempting to do > something here I have never done before. In other > applications I have developed, I have only used the Next - Previous > link idea when I have simply pulled the entire database > so that the user could browse the db. This time though I need to allow > the user to set parameters before browsing. > > Here's my problem from a code perspective: > > PHP Code:
> My problem appears to be that my variables are not carrying over > whenever Next or Previous is clicked. Anybody have a suggestion as to > how I can get this to work? Hi, I didn't actually read through all your code, but you should probably validate, then set the validated variables as session variables. Then you can just use the session variables as-is on any subsequent page and use them to build your query. Shawn -- Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com |
|
|||
|
I took your suggestion to use session variables and it "almost"
works.... $_SESSION["sqlqry"]="SELECT * FROM Repair WHERE ALC LIKE '%' AND BP LIKE '$bpc' AND FSC LIKE '$fsc' AND NIIN LIKE '$niin' AND SGM_MMAC LIKE '$mmac' AND IMS LIKE '$ims' AND SMC LIKE '$smc' AND PMS_BUYER LIKE '$PMS_BUYER' AND PMS_SELLER LIKE '$PMS_SELLER' AND Y_VAL_ACT_ROLLUP $val1 AND BY_VAL_ACT_ROLLUP $val2 AND EY_VAL_ACT_ROLLUP $val3 AND Y4_VAL_ACT_ROLLUP $val4 ORDER BY '$orderby1','$orderby2' LIMIT" For whatever reason, the '$orderby1' and '$orderby2' variables are not carrying through. What am I doing wrong? |
|
|||
|
redneck_kiwi wrote:
> I took your suggestion to use session variables and it "almost" > works.... [reformatted] $_SESSION["sqlqry"] = " SELECT * FROM Repair WHERE ALC LIKE '%' AND BP LIKE '$bpc' AND FSC LIKE '$fsc' AND NIIN LIKE '$niin' AND SGM_MMAC LIKE '$mmac' AND IMS LIKE '$ims' AND SMC LIKE '$smc' AND PMS_BUYER LIKE '$PMS_BUYER' AND PMS_SELLER LIKE '$PMS_SELLER' AND Y_VAL_ACT_ROLLUP $val1 <== isn't there AND BY_VAL_ACT_ROLLUP $val2 <== something AND EY_VAL_ACT_ROLLUP $val3 <== missing AND Y4_VAL_ACT_ROLLUP $val4 <== around here? ORDER BY '$orderby1','$orderby2' LIMIT <== and here? " > For whatever reason, the '$orderby1' and '$orderby2' variables are not > carrying through. What am I doing wrong? 1. try verifying the contents your session array: <?php echo '<pre>$_SESSION array:<br>'; print_r($_SESSION); echo '<br></pre>'; ?> 2. And I'd not use globals, nor copy the session to 'normal' variables; but instead I'd use the session array directly to build the query: <?php /* AFAICT there's no need to put the query in the session array */ $sqlqry = <<<SQL_QUERY SELECT column1, col2, col18, col7, ... FROM Repair WHERE ALC LIKE '%' AND BP LIKE '$_SESSION[bpc]' AND ... ... ORDER BY '$_SESSION[orderby1]', '$_SESSION[orderby2]' LIMIT ... SQL_QUERY; ?> 3. Also try to see if you're using undeclared variables, by putting <?php error_reporting(E_ALL); ?> at the very top of your scripts. Happy Coding :-) -- USENET would be a better place if everybody read: http://www.expita.com/nomime.html http://www.netmeister.org/news/learn2quote2.html http://www.catb.org/~esr/faqs/smart-questions.html |
|
|||
|
If you want help with pagination take a look at
http://www.tonymarston.co.uk/php-mysql/pagination.html -- Tony Marston http://www.tonymarston.net "redneck_kiwi" <kf4pfw@gmail.com> wrote in message news:1098209405.802702.235840@f14g2000cwb.googlegr oups.com... > Need some opinions on how best to display in excess of 14K records > based on users search criteria. > > Application Concept: > ----------------------- > > [1] User enters various search criteria (as many as 13 different > fields) AND can select 2 fields to sort on. > [2] User can also limit the results displayed per page > [3] Once the user presses "Submit", the SQL string is built and the DB > is queried. > [4] Results are displayed to the user, x records per page with "Next > <<->> Previous" link under results. If user > did not choose a limit, I limit to 20 records per page. > [5] Clicking on the Next or Previous links walks the user through the > data. > > > Application Logic > ----------------------- > > PHP Code:
> Sounds simple, right? Basically it is, however I am attempting to do > something here I have never done before. In other > applications I have developed, I have only used the Next - Previous > link idea when I have simply pulled the entire database > so that the user could browse the db. This time though I need to allow > the user to set parameters before browsing. > > Here's my problem from a code perspective: > > PHP Code:
> My problem appears to be that my variables are not carrying over > whenever Next or Previous is clicked. Anybody have a suggestion as to > how I can get this to work? > > TIA > > rk > |
|
|||
|
Taking some of your suggestions I get the following results:
[1] Verifying the contents of the session array: First pass: $_SESSION array: Array ( [sqlqry] => SELECT * FROM Repair WHERE ALC LIKE '%' AND BP LIKE '15' AND FSC LIKE '%' AND NIIN LIKE '%' AND SGM_MMAC LIKE '%' AND IMS LIKE '%' AND SMC LIKE '%' AND PMS_BUYER LIKE '%' AND PMS_SELLER LIKE '%' AND AY_VAL_ACT_ROLLUP LIKE '%' AND BY_VAL_ACT_ROLLUP LIKE '%' AND EY_VAL_ACT_ROLLUP LIKE '%' AND Y4_VAL_ACT_ROLLUP LIKE '%' ORDER BY 'FSC','FSC' LIMIT As you can see, all the variables are set as expected. Clicking the next (for the next 20 items): $_SESSION array: Array ( [sqlqry] => SELECT * FROM Repair WHERE ALC LIKE '%' AND BP LIKE '15' AND FSC LIKE '%' AND NIIN LIKE '%' AND SGM_MMAC LIKE '%' AND IMS LIKE '%' AND SMC LIKE '%' AND PMS_BUYER LIKE '%' AND PMS_SELLER LIKE '%' AND AY_VAL_ACT_ROLLUP LIKE '%' AND BY_VAL_ACT_ROLLUP LIKE '%' AND EY_VAL_ACT_ROLLUP LIKE '%' AND Y4_VAL_ACT_ROLLUP LIKE '%' ORDER BY '','' LIMIT As you can see, the two fields to order by are being dropped. Is there a limit to the size of the array here? The reason for the LIMIT being blank is that those values are dynamic and are added when I build the actual sql string. I am going to try using the individual session elements once I figure out what the heck is going on with those order by elements. Thanks rk |
|
|||
|
redneck_kiwi wrote: > > Taking some of your suggestions I get the following results: > > [1] Verifying the contents of the session array: > > First pass: > $_SESSION array: Array > ( > [sqlqry] => SELECT * FROM Repair WHERE ALC LIKE '%' AND BP LIKE > '15' AND FSC LIKE '%' AND NIIN LIKE '%' > AND SGM_MMAC LIKE '%' AND IMS LIKE '%' AND SMC LIKE '%' AND PMS_BUYER > LIKE '%' AND > PMS_SELLER LIKE '%' AND AY_VAL_ACT_ROLLUP LIKE '%' AND > BY_VAL_ACT_ROLLUP LIKE '%' AND EY_VAL_ACT_ROLLUP > LIKE '%' AND Y4_VAL_ACT_ROLLUP LIKE '%' ORDER BY 'FSC','FSC' LIMIT > > As you can see, all the variables are set as expected. Clicking the > next (for the next 20 items): > > $_SESSION array: Array > ( > [sqlqry] => SELECT * FROM Repair WHERE ALC LIKE '%' AND BP LIKE > '15' AND FSC LIKE '%' AND NIIN LIKE '%' > AND SGM_MMAC LIKE '%' AND IMS LIKE '%' AND SMC LIKE '%' AND PMS_BUYER > LIKE '%' AND > PMS_SELLER LIKE '%' AND AY_VAL_ACT_ROLLUP LIKE '%' AND > BY_VAL_ACT_ROLLUP LIKE '%' AND EY_VAL_ACT_ROLLUP > LIKE '%' AND Y4_VAL_ACT_ROLLUP LIKE '%' ORDER BY '','' LIMIT > > As you can see, the two fields to order by are being dropped. Is there > a limit to the size of the array here? The reason for the LIMIT being > blank is that those values are dynamic and are added when I build the > actual sql string. > > I am going to try using the individual session elements once I figure > out what the heck is going on with those order by elements. I'm not sure what the limit is (if any) on session variables, but yo |