php - MySQL data crunching. How to get the values after the slash from database -
i'm crunching info mysql database on towns , regions within town.
the database looks this
id | name 1 | manchester 2 | manchester/north 3 | manchester/south 4 | manchester/east 5 | manchester/west
i've tried php script find words come after /
, produce number based on count variable$j
far not working. later on plan write json file variable $data
comes from.
my ideal output north south east west
4
here script
$j=0; foreach($data->objects->layer->geometries &$h) { foreach($result $row) { preg_match("/[^\/]+$/", $row['name'], $matches); // town/region $no_slash = $matches[0]; // part if(strtolower($h->properties->name) == $no_slash) { $h->properties->id = $row['id']; $j++; echo $j . " " . $no_slash . "<br />"; } } } echo "number of matches: " . $j;
my output @ moment number of matches: 0
have thought why?
if understand question correctly, utilize mysql query:
select substring_index(name, '/', 1) city, group_concat(substring_index(name, '/', -1) separator ' ') districts, count(*) cnt tablename name '%/%' grouping city
please see fiddle here.
php mysql json
No comments:
Post a Comment