PHP Forum

count only commas outside parenteses

I have a sql table containing
Advertisement
id - query - query name
the first page contains a drop down menu of all the query names. When chosen the user is sent to a page that prints the result of the query in a html table.

Now i nees to find how many rows the table should have.

Advertisement
This counts how many rows i need in the table:

$parts=explode(' FROM ',$query);
$count=explode(",", $parts[0]);
$result=count($count);
Advertisement

But the problem is that here i explode by commas but the query also contains commas like this: substring (***,19,10) as Part1

My question is how do i count only commas outside these parenteses.

something like this:

$var=0;
start counting commas in parts[0],
when ( accures increase $var to 1,
if $var = 1 dont count commas,
but when ) accures set $var to 0,
and start counting again

The reason why im making it this way is that it's suppose to be possible to just add a query to the sql table no matter how many rows this query needs in output.

Any ideas?
Advertisement

0 answers

No answers posted yet. Be the first to answer.

Your answer

Login to answer

Trending today: see what people are reading