-1

I have a WordPress site. We want to display a list of students on a page, after taking "Roll Number" as an input from the person searching.

I have created the database on the server and 4 fields in the table: "Roll Number", "Full Name", "Percentage" and "Result".

2 Answers 2

1

You can use simple mysql queries as following

global $wpdb;

$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );

you ca run any select query as above

2
  • Thank you for taking time to answer this, I am very new to Programming and just know HTML. Can you please explain in details where this is to be placed? Commented Dec 1, 2013 at 14:25
  • Have youy used Mysql before?
    – Trishul
    Commented Dec 2, 2013 at 18:11
0

The query returns you the data of student with roll number you search for.

here value refers to the roll number taken as input. And roll_number is the field name in your table.

 <?php

       global $wpdb;

       $rows = $wpdb->get_results( "SELECT * FROM table_name WHERE roll_number = value");

       if( !empty($rows) ) {
          $roll_num = $rows->roll_number;
          $full_name = $rows->full_name;
          $percentage = $rows->percentage;
          $result = $rows->result; 
       }



    ?>

roll_number, full_name, percentage, result are field names in the table. If field names are different then replace these with proper fields in table.

2
  • I have added the below as per your instructions, but I have never used php coding in the past and I am not even sure how to connect these to, so that the Roll Number entered can be picked up for the search. Please help me in the below. I want them to be posted on the same page and not the php in a different .php file. This is something I picked from the internet. Thank you so much for your help. Commented Dec 4, 2013 at 16:06
  • <form action="welcome.php" method="post"> Roll Number: <input type="text" name="name"><br> <input type="submit"> </form> <?php global $wpdb; $rows = $wpdb->get_results( "SELECT * FROM results WHERE Id = value"); if( !empty($rows) ) { $roll_num = $rows->Id; $full_name = $rows->Name; $percentage = $rows->Percentage; $result = $rows->Result; } ?> Commented Dec 4, 2013 at 16:07

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.