Question: **EDIT:**  

If the number of occurrences of Keyword1 and Keyword2 does not match, then the solutions provided does not work. I have updated the dataframe and code below to reflect a similar mismatch.

**ORIGINAL POST:**   

I have a dataframe of strings and I am trying to choose all the rows between two specific string values [Keyword1 and Keyword2].

I am using the code below:

```
import pandas as pd 
import numpy as np

df=pd.DataFrame(['A', 'B', 'C1', 'D', 'A', 'B', 'C2','C3', 'D','C4', 'B', 'C5'])
df.columns = ['Col1']

Keyword1= 'B'
Keyword2= 'D'

#Filter and delete file mode deliveries
a=df.index[df['Col1'] == Keyword1].tolist()
b=df.index[df['Col1'] == Keyword2].tolist() 
b=np.add(b, 1).tolist() 

index=[]
for i in range(len(b)):
    index_temp=np.arange(a[i],b[i]).tolist()
    index=index+index_temp

df_keep= df[df.index.isin(index)]   
df_del= df[~df.index.isin(index)]

```

While this does the work, I am wondering if there a more efficient way to perform the same task.

Answer: 
So the reason is that a **variable** that is on that line is being converted to a string for the purposes of `echo`. The only variables on that line are `$id` and `$name`.

Since `id` is the `array key` to `name` it's not likely to be that!

That leaves us with `$name`:

* The way you're getting the data means you're returning an array **OF** arrays...
* Which means each `$name` will be an array in the format:

```
  $name = [
      'id' => SOME_ID,
      'name' => 'Some name'
  ];

```
* ...i.e. not in the format it looks as though you're assuming.
* With multiple results `$categories` will look something like:

```
  $categories = [
      0=>[
          'id'=>1,
          'name'=>'Name number 1'
      ],
      1=>[
          'id'=>2,
          'name'=>'Name number 2'
      ],
      2=>[
          'id'=>3,
          'name'=>'Name number 3'
      ],
      3=>[
          'id'=>4,
          'name'=>'Name number 4'
      ]
  ];

```
* Notice that the index you're using as `$id` is actually the array key and not the `id` from the query? (`$name` then is the sub array)

**Code**

```
<div class="dropdown">
 <?php
  mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);  // Turn on error reporting
  $db = new mysqli('localhost', 'root', 'password', 'db');

  $query = "SELECT id, name FROM category";                   // SQL statement
  $statement = $db->prepare($query);                          // Prepare the query
  $statement->execute();                                      // Run the query
  $statement->store_result();                                 // Store the returned results set
  $statement->bind_result($id, $name);                        // Bind returned fields (id & name) to variables
?>
    <p class="dropdownSelect">Select Category</p>
       <div class="dropdownContent">
       <?php
           while($statement->fetch()) {                                     // Loop through result set
              echo "<p><a href=\"category.php?id={$id}\">{$name}</a></p>";  // Print the line you want to print
           }
       ?>
            </div>
        </div>
    </div>

```
change this line

```
 <p><a href=\"category.php?categoryId=$id\"> $name</a></p>

```

with

```
 echo "<p><a href="'category.php?categoryId='$id"> '"$name"'</a></p>";

```