Forums

New user question - querying a db from a page (4 posts)

  1. ccb2008
    Member
    Posted 1 week ago #

    Hello,

    I am fairly new to using WordPress.

    I have installed cForms and enabled the tracking option. I would like to be able to display some information from the cForms db on a WP page.

    Could someone point me towards some resources to help me get started? I am familiar enough with SQL to be able to form the query, but I don't know how to submit the query from a page, nor display the results.

    TIA for any pointers...
    CB

  2. ccb2008
    Member
    Posted 1 week ago #

    I think this is what I need -- a new page template:
    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

  3. ccb2008
    Member
    Posted 1 week ago #

    Well, I could use some help forming the query...

    The cformsdata db has this structure:
    f_id
    sub_id
    field_name
    field_val

    When I browse the db, I find records like this;
    f_id sub_id field_name field_val
    1 8 First Name John
    2 8 Last Name Brown
    3 8 Gender Male
    4 9 First Name Molly
    5 9 Last Name Malone
    6 9 Gender Female

    If I want to extract all the men, I need to

    Select * from cformsdata where 'field_name' IS NOT NULL from (select * from cformsdata where 'field_name' = 'Gender' AND 'field_val' = 'Male')
    group by sub_id order by f_id

    Or something like that.
    Any help would be greatly appreciated....

  4. ccb2008
    Member
    Posted 1 week ago #

    I have my query working, I have the page template working, except...
    How do I display the results of the query?
    That is, how do I fill in

    <?php
    $querystr = "
    /* big string here */
    $players = $wpdb->get_results($querystr, OBJECT);

    ?>
    <?php if ($players): ?>
    /* what now? */
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
    <?php endif; ?>

    Thanks for any pointers...

Reply

You must log in to post.

About this Topic

Tags