Jump to content

count only commas outside parenteses


LMarie

Recommended Posts

 

I have a sql table containing

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.

 

This counts how many rows i need in the table:

$parts=explode(' FROM ',$query);

$count=explode(",", $parts[0]);

$result=count($count);

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?

Link to comment
https://forums.phpfreaks.com/topic/183563-count-only-commas-outside-parenteses/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.