• Hello,

    I’m trying to create an e-commerce solution and I am trying to call the title of a post inside some other php that calls data from a database. Here is the code now.

    $query = “SELECT product_name, product_quantity FROM transaction_detail WHERE product_name=’the_title();‘”;

    How do I call the title of each post? Thanks very much.

    Chris
    Rabbit Pack

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try this:

    $query = "SELECT product_name, product_quantity FROM transaction_detail WHERE product_name='" . get_the_title() . "';";

    I’m using ‘get_the_title()’ here because you’re not echoing the title out to the browser, just storing it in the $query variable. This should work for what you need. Let me know if it doesn’t.

    $query = "SELECT product_name, product_quantity FROM transaction_detail WHERE product_name='the_title();'"; won’t work because only variables, not callbacks, can be used inline.

    @live627 – That’s the entire reason I made my suggestion. It uses a simple variable return appended to an existing string to create the query.

    Thread Starter kilika77

    (@kilika77)

    thanks for the help. sorry i didn’t get back here sooner. for some reason im not getting the rss feeds for any of my topics.

    i figured it out and just created a variable for a custom field and then sorted using that custom field.

    thanks for the help ericmann and live627

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using PHP inside PHP’ is closed to new replies.