I have a database having the following structure:
<table border="2">
<tbody>
<tr>
<td>ID</td>
<td>numbering</td>
<td>country</td>
<td>operator</td>
<td>rate</td>
</tr>
<tr>
<td>1</td>
<td>12345</td>
<td>country1</td>
<td>operator1</td>
<td> </td>
</tr>
<tr>
<td>2</td>
<td>12345</td>
<td>country1</td>
<td>operator1</td>
<td> </td>
</tr>
<tr>
<td>3</td>
<td>12345</td>
<td>country1</td>
<td>operator1</td>
<td> </td>
</tr>
<tr>
<td>4</td>
<td>12345</td>
<td>country1</td>
<td>operator2</td>
<td> </td>
</tr>
<tr>
<td>5</td>
<td>12345</td>
<td>country1</td>
<td>operator2</td>
<td> </td>
</tr>
<tr>
<td>6</td>
<td>12345</td>
<td>country1</td>
<td>operator2</td>
<td> </td>
</tr>
</tbody>
</table>
I am first querying the operators based on the country selected by the user, and display them, however I also want to display the corresponding set of numbering for each operator. This is the code I implemented so far :
<?php
$operator_rates= $wpdb->get_results("SELECT DISTINCT operator, rate FROM database WHERE country='$_GET[country]'");
foreach ( $operator_rates as $operator_rate ) {
$numbering = $wpdb->get_results("SELECT numbering FROM database");
echo '
<strong>'.$operator_rate->operator.'</strong><br/>'.$numbering;
} ?>
The Result I am getting is as per the below:
Operator 1
Array
Operator 2
Array
Operator 3
Array
The result I am expecting is having each operator and exactly underneath it the set of numbering for each operator:
Operator 1
12345, 12345, 12345, 12345
Operator 2
12345, 12345, 12345, 12345
Operator 3
12345, 12345, 12345, 12345
$_GETdata directly in your query. NEVER do this. Instead, use the WordPress prepared statements feature to properly escape all data parameters.