• 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..

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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 ) );
    Thread Starter adambeaumont1

    (@adambeaumont1)

    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.

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

    <?php
    foreach( $items as $item ) {
      echo $item['lowestticketprice']
    }
    ?>
    Thread Starter adambeaumont1

    (@adambeaumont1)

    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']
    }
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Fields on Category Page PHP SQL’ is closed to new replies.