PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 9th, 2002, 10:16 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Multiple variables in "search engine"

Well, I'm trying to create a page that would have non-mysql database. It works somehow when there is only single variable, but when I want to use multiple variables, it goes badaboom. I have no idea what is proper way to create such thing.

For example, I have url items.php?foo=x. I can make it now display items where foo is x, but when I put items.php?foo=x&bar=y, it displays all items with foo as x and bar as y, when I want it to display only items with foo as x and bar as y.

I know I could do it with using if-elseif-else, but there are multiple variables (11) so it would be preeeetty hard code to follow. :/

If it's of anyhelp, the database is located in a file with ; as separator. An item in it could be: Foo;Bar;1;0;3;0;0;0;1;0;0

Hopefully someone even has an idea what I'm talking about...

Reply With Quote
  #2  
Old August 9th, 2002, 11:39 AM
greggory greggory is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Reims, France
Posts: 82 greggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Multiple variables in

Try this:
php Code:
Original - php Code
  1.  
  2. <?php
  3. // Array containing the name of parameters
  4. $params = Array( 0 => 'foo', 'bar', 'par3', 'par4' );
  5. $nb_params = count( $params );
  6.  
  7. // Read database file
  8. $lines = file( 'data.txt' );
  9. $nb_lines = count( $lines );
  10.  
  11. // According results
  12. $res = Array();
  13.  
  14. // Go thru each line
  15. for ( $i = 0; $i < $nb_lines; $i++ ) {
  16.     // Flag that knows if the line is ok
  17.     $ok = true;
  18.  
  19.     // Explode line
  20.     $line = explode( ";", $lines[$i] );
  21.  
  22.     // Check each parameter
  23.     $j = 0;
  24.     while ( $j < $nb_params && $ok ) {
  25.         // If the param number $j has been given
  26.         if ( isset( $_GET[$params[$j]] )) {
  27.            // But if the line does not match
  28.            if ( $_GET[$params[$j]] != $line[$j] ) {
  29.                $ok = false;
  30.            }
  31.         }
  32.         $j++;
  33.     }
  34.    
  35.     // Add line if ok
  36.     if ( $ok ) $res[] = $lines[$i];
  37. }
  38. ?>


If you have questions (Or if it doesn't work or whatever) ask me

Reply With Quote
  #3  
Old August 9th, 2002, 10:32 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: RE: Multiple variables in

NOTE: there is a ' missing in the beginning previous post. corrected code (beginning) follows:
php Code:
Original - php Code
  1.  
  2. <?php
  3. // Array containing the name of parameters
  4. $params = Array( 0 => 'foo', 'bar','par3', 'par4' );
  5. $nb_params = count( $params );


Reply With Quote
  #4  
Old August 10th, 2002, 02:04 PM
greggory greggory is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Reims, France
Posts: 82 greggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Multiple variables in

've edit it so there is no more :p

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Multiple variables in "search engine"


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway