SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can visitors modify database table query?

    Imagine a database query that displays a table with information about various countries. You can easily modify the display by replacing the WHERE clause with an echo function that limits the results to countries found in Africa or another continent...

    PHP Code:
    $WHERE 'WHERE table_1.Continent = 'Africa'';
    $WHERE 'WHERE table_1.Continent = 'South_America'';

    (
    "SELECT * FROM table_1

    '.
    $WHERE.'"
    I think I recall seeing a PHP script that allowed visitors to somehow toggle between different WHERE clauses. Of course, it would be nicer to use a JavaScript function to avoid refreshing the page each time.

    Is there a way to do this with JS?

    Thanks.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way to do this with JS?
    js can manipulate any data it gets from a php script. For instance, a php script could write values into a js array:
    Code:
    <script type="text/javascript">
    
    var arr = [ 
    
    <?php>
    echo value1 . ',' ;
    echo value2 . ',' ;
    echo value3;
    ?>
    
    ];
    
    </script>
    php could also insert those values in the html to be displayed on initial page load. Thereafter, depending on what the user clicks, js can retrieve portions of the data in the array.

    A simple scheme might involve using php to insert values in the html with groups of data having the same value for the class attribute(or a custom attribute of your choosing). Then if button1 is clicked, only elements with the class value 'group1' can be made visible. If button2 is clicked, then only elements with the class value 'group2' are made visible, etc.

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the tip, 7stud. I've also downloaded some scripts that let users toggle between alternate style sheets and alternate row colors using JS. Now I'll just have to figure out how to put it all together.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •