Title: Modify PHP to Return Data from External Db
Last modified: August 21, 2016

---

# Modify PHP to Return Data from External Db

 *  [thenorth](https://wordpress.org/support/users/thenorth/)
 * (@thenorth)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/modify-php-to-return-data-from-external-db/)
 * I built a website sometime ago which uses a drop down search to create a table–
   see here [My Old Website ](http://dukescottages.com/Dukes3Availability.php)
 * I am now trying to replicate this is wordpress. But can’t get my head around 
   how to bring this into WordPress. I’m pretty sure how to connect to my external
   Db using `
    $mydb= new wpdb(‘DbUser’,’PW’,’DBName’,’localhost’);` but no idea
   how to have a combo box and select query on submit (or change)
 * How do I something this simple in WordPress. My PHP code from website is below.
   Really appreciate any advice you have.
 *     ```
       <form method="post" action="Dukes3Availability.php">
       <input type="hidden" name="submitted" value="true"/>
   
       <label>Search Month to See Availability Details and Prices:
   
       <select name="Category" id="Catergory">
   
       <option>Please Choose Month</option>
       <option>February 2014</option>
       <option>March 2014</option>
       <option>April 2014</option>
       <option>May 2014</option>
       <option>June 2014</option>
       <option>July 2014</option>
       <option>August 2014</option>
       <option>September 2014</option>
       <option>October 2014</option>
       <option>November 2014</option>
       <option>December 2014</option>
       <option>January 2015</option>
       </select>
       </label>
       <input type="submit"/>
       </form>
   
       <?php
   
       if (isset($_POST['submitted'])) {
   
       include('Connection.php');
   
       $Category = $_POST['Category'];
       $criteria= $_POST['criteria'];
       $query = "select Date_Format(Start_Date,'%d-%b-%Y') As Start_Date,Day,No_Of_Nights,CONCAT('£', FORMAT(cost, 2)) as Cost ,Status,PageLink from <code>web152-thenorth</code>.Dukes3 WHERE concatc = '$Category' ORDER BY Start_Date";
       $result = mysqli_query($dbcon, $query) or die($query);
       echo "<table>";
       echo "<tr>
       <th>
       Arrival
       </th>
       <th>
       Arr Day
       </th>
       <th>
       No Nights
       </th>
       <th>
       Cost
       </th>
       <th>
       Status
       </th>
       <th>
       Link
       </th>
       </tr>";
   
       while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
   
       echo "<tr><td>";
       echo $row['Start_Date'];
       echo "</td><td>";
       echo $row['Day'];
       echo "</td><td>";
       echo $row['No_Of_Nights'];
       echo "</td><td>";
       echo $row['Cost'];
       echo "</td><td>";
       echo $row['Status'];
       echo "</td><td>";
       echo $row['PageLink'];
       echo "</td></tr>";
       }
   
       echo "</table>";
   
       } // end of If Statement
   
       ?>
       ```
   
 * Thank you.
 * theNORTH

The topic ‘Modify PHP to Return Data from External Db’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * 0 replies
 * 1 participant
 * Last reply from: [thenorth](https://wordpress.org/support/users/thenorth/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/modify-php-to-return-data-from-external-db/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
