I have a database table:
ID name 15 name1 27 name2 39 name3
I need to assign the indices of these strings, for example: name1 should have index 0, name2 - index 1, name3 - index 2:
ID name index 15 name1 0 27 name2 1 39 name3 2
I am trying to do this with a loop:
$sub = $wpdb->get_results("SELECT t.* FROM $wpdb->terms AS t, $wpdb->term_taxonomy AS tt WHERE tt.parent = $termID AND tt.term_id = t.term_id "); $i=-1; foreach ($sub as $key) { $i++; $number[$i]=$i; }
The result of this loop:
$number[0]=0; $number[1]=1; $number[2]=2;
Now I have, for example, a row for which ID is 27. How do I get the index of this row? (must be 1)
source share