WordPress.org

Ready to get started?Download WordPress

Forums

Custom Fields on Category Page PHP SQL (5 posts)

  1. adambeaumont1
    Member
    Posted 2 years ago #

    After many hours and many variations of code I am stuck!!.

    So on the Category Page I want to get the minimum price from a table which stores the price. The following code is placed inside the loop. I have tried Sessions etc but no joy, where am I going wrong!!

    - The SQL Statement works when the "Product X" is declared
    - Doesn't work when trying to get the value from variable $test

    <? /// LOWEST PRICE QUERY ?>

    mysql_select_db($database_tickets, $tickets);
    $test = "Product X";

    $colname_lowestprice = "-1";
    if (isset($_GET['$eventpricename'])) {
    $colname_lowestprice = $eventpricename;
    }
    $query_lowestprice = sprintf("SELECT MIN(wp_events.price) AS lowestticketprice FROM wp_events, wp_merchants
    WHERE eventname = 'Product X'");
    //WHERE eventname = '".$test."'");

    ?>

    Any help appreciated..

  2. Danny de Haan
    Member
    Posted 2 years ago #

    Try this one:

    global $wpdb;
    $items = $wpdb->get_results( $wpdb->prepare( "SELECT MIN(wp_events.price) AS lowestticketprice FROM wp_events, wp_merchants WHERE eventname = '%s'", $test ) );
  3. adambeaumont1
    Member
    Posted 2 years ago #

    Thanks for putting me on the right track. I cannot seem to get the prices to display, I try to echo $items but returns back with the value Array.

    Il keep digging but if you know of my hand then that would be great.

  4. Danny de Haan
    Member
    Posted 2 years ago #

    ok, you have to put the $items in a foreach loop.

    <?php
    foreach( $items as $item ) {
      echo $item['lowestticketprice']
    }
    ?>
  5. adambeaumont1
    Member
    Posted 2 years ago #

    Returns back an error but if I put the echo $item in comments the page loads normally, without the prices of course. hit another wall. This code is inside the loop on the category page.

    mysql_select_db($database_tickets, $tickets);
    $test = 'Plane Ticket';
    global $wpdb;
    $items = $wpdb->get_results( $wpdb->prepare( "SELECT MIN(wp_events.price) AS lowestticketprice FROM wp_events, wp_merchants WHERE eventname = '%s'", $test ) );
    foreach( $items as $item ) {
     echo $item['lowestticketprice']
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.