0

this is the query i want to display

SELECT account_number, consumer_name, bill_amount, due_date, disco_date, bill_status FROM wp_bill_inquiry WHERE account_number = input AND pin_number = input

by inputting the data in a form like this

enter image description here

I hope to get this display as a result

enter image description here

2
  • Just for number 1234? Or does that need to be dynamic? Important detail. Commented Jun 27, 2018 at 8:03
  • actually i want it to be dynamic. where you need to enter an account_number and a pin_number on a form before it runs the query. the account number_number and pin_number has to match or else it doesn't display anything. Commented Jun 27, 2018 at 8:14

1 Answer 1

0
$result = $wpdb->get_results( "SELECT `account_number`,`consumer_name`,`bill_amount`,`due_date`,`disco_date`,`bill_status` FROM {$wpdb->prefix}_bill_inquiry where  `account_number` = '$inputnumber' AND `pin_number` = '$inputpin'", OBJECT );

$wpdb->prefix will automatically print the prefix, then to convert the result in array form you can use the following snippet:

$result = json_decode(json_encode($result),true);

You can either place it in a template or you can create a shortcode in functions.php, you can refer shortcode docs.

10
  • thank you for answering. sorry for this novice question but, where exactly do I place this? Commented Jun 27, 2018 at 8:47
  • I updated my answer, hope it helps.
    – Akshat
    Commented Jun 27, 2018 at 8:57
  • I tried placing it in a template. it just returned it as text. do I have declare anything somewhere for it to work? Commented Jun 28, 2018 at 0:06
  • Jepoy - it needs to be inside the php tags php.net/manual/en/language.basic-syntax.phptags.php If you place it where there is straight html the yes it will appear as text. Surround it with <?php ........ ?> if you are puttingn it in the midst of html.
    – anmari
    Commented Jun 28, 2018 at 3:52
  • Thanks again. I already made it work. I'm facing another problem now. the account number in the database needs to be formatted like this 01-2345-6789. I can't seem to use select query because of the dash. note that account_number is one of the conditions in my query. Commented Jun 28, 2018 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.