We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36656
    • 21 Posts
    I'm just cutting my teeth on writing MySQL statements and I feel like I'm really close with this one—but it's not quite there.

    I'm essentially trying to query the database to find documents where tv1, tv2, and tv3 are equal to various values. For instance, find all documents where tv1="dessert" tv2="cookies" tv3="chocolate"

    I'd like to be able to get the information about the document (longtitle, contentid, etc) as well as the values of the various TVs if possible.

    SELECT *,GROUP_CONCAT(prefix_site_tmplvar_contentvalues.value) AS tvvalues
    FROM prefix_site_tmplvars
    JOIN prefix_site_tmplvar_contentvalues
    ON prefix_site_tmplvars.id = prefix_site_tmplvar_contentvalues.tmplvarid
    JOIN prefix_site_content
    ON prefix_site_content.id = prefix_site_tmplvar_contentvalues.contentid
    WHERE name IN ("tv1", "tv2", "tv3" )
    GROUP BY prefix_site_tmplvar_contentvalues.contentid
    HAVING tvvalues LIKE ......


    This SELECT statement is close to what I want to accomplish, but I ended up with all of the TV values as:
    [name] => food_type
    [name] => flavor
    [value] => cookies
    [value] => chocolate

    How could I adjust my statement so that I could have:
    [contentid] => 14
    [flavor] => chocolate
    [food_type] => cookies
    [meal] => dessert

    Thank you! [ed. note: bartleby last edited this post 14 years, 2 months ago.]
      • 4172
      • 5,888 Posts
      here's a function which prepares a mysql-statement for multiple TVs:
      https://github.com/Bruno17/bloX-Xedit/blob/master/snippets/blox/inc/blox.class.inc.php#L1200

      hope this helps.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!