ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to use the selected values in Query Module

August 10, 2008 8:34am

Subscribe [3]
  • #1 / Aug 10, 2008 8:34am

    netlinkblueEE

    39 posts

    Hi,

    i have a form with one dropdownlist with dynamic generated text and entry_id, iam sending the selected dropdownlist value to onether search form.in the search form how to write the query module syntax, which will retrive the values according to the selected dropdown list entry_id.

    iam writting the query like this but giving error.

    {exp:query sql="SELECT * FROM exp_weblog_data WHERE entry_id '$_POST["dropdownname"]'"}

    Can anyone help me how to search the records according to the dropdownlist value.

    Thanks.

  • #2 / Aug 11, 2008 5:20pm

    Ingmar's avatar

    Ingmar

    29245 posts

    You can access the variables by using the standard {variable} syntax of EE:

    {exp:query sql="SELECT * FROM exp_weblog_titles"}
    {url_title} 
    
    {/exp:query}

    To avoid a conflict with existing EE variables, you might want to use “AS”, like so:

    {exp:query sql="SELECT title AS my_title FROM exp_weblog_titles"}
    {my_title} 
    
    {/exp:query}
  • #3 / Aug 12, 2008 10:01am

    netlinkblueEE

    39 posts

    Hi,

    Thanks for your reply,you didn’t get my question.Iam going to search the table against the selected dropdown value which iam sending from the search form ie. ” $_POST[“dropdownvalue”] “

    Thanks

  • #4 / Aug 31, 2009 11:20am

    philfreo's avatar

    philfreo

    50 posts

    Hi,

    Thanks for your reply,you didn’t get my question.Iam going to search the table against the selected dropdown value which iam sending from the search form ie. ” $_POST[“dropdownvalue”] “

    Thanks

    You’re trying to mix PHP into both the Query module and the SQL language (this won’t work, naturally).  Try something like:

    <?php $theID = (int) $_POST["dropdownname"]; ?>
    {exp:query sql="SELECT * FROM exp_weblog_data WHERE entry_id=<?php echo theID; ?>"}

    And you’ll have to make sure PHP parsing is enabled for that template, and that it’s parsed before the EE tags.

    [note, you have to watch out for SQL injection (google it) as well; so the (int) should cover that]

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases