i am displaying the top 5 results from a sql query using the following code;
<?php
$query = "SELECT location, COUNT(location) AS qty FROM ecmt_memberlist GROUP BY location ORDER BY qty DESC LIMIT 0,5";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<span class='graphValue'>x".$row['qty']."</span> " . $row['location'] . "<br />";
} ?>
this is displaying my result strings as follows:
how can i trim down the $row['location'] to show the words before the first "-" for example;
echo explode('-', $row['location'])[0];
OR
echo preg_replace('/\-\s.+/i', '', $row['location']);