# Asterisk Dial-plan for unidentified number of variables

**URL:** <https://community.asterisk.org/t/asterisk-dial-plan-for-unidentified-number-of-variables/32282>\
**Category:** Asterisk Support\
**Created:** [August 18, 2010, 1:59pm UTC](https://community.asterisk.org/t/asterisk-dial-plan-for-unidentified-number-of-variables/32282 "2010-08-18T13:59:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [August 18, 2010, 1:59pm UTC](https://community.asterisk.org/t/asterisk-dial-plan-for-unidentified-number-of-variables/32282/1 "2010-08-18T13:59:28Z")

</div>

Guys (or gals),

I am pasting my partial script below in hopes of someone might tell me where I am going wrong. The part that is really getting me is that the sql statement returns a differing number of values based on the user it is for.

I was wondering if someone may have an example of a portion of a dialplan which could pull values out of a database (where the select statement could return 1 - 5 values), play back those values to the user and then ask for the user to determine the correct value. It seems that it would be similar to a dialbyname script but can’t find anything.

If I need to clarify let me know. Also, does anyone know if you can embed multiple PlayBacks and SayNumbers into a Read???  
--------------snip--------------  
;\<-------------------Get number of rows returned in select statement  
exten =\> s,13,MYSQL(Query row\_count ${connid} select COUNT(DING) FROM tbl\_del WHERE DRI=${DRI} AND ISNULL(deldep)=1 AND main\_transid\>17000 ORDER BY main\_transid)  
;\<-------------------Place row counts in variable CNT  
exten =\> s,n,MYSQL(Fetch fetchid\_2 ${row\_count} CNT)  
;\<-------------------Set variable incr to row count (CNT)  
exten =\> s,n,SetVar(incr=${CNT})  
exten =\> s,n,PlayBack(custom\youhave)  
exten =\> s,n,SayNumber(${CNT})  
exten =\> s,n,Playback(custom\pendload)  
;\<-------------------Get specific data fron column tbl\_del (this could have 2 - maybe 5 values)  
exten =\> s,n,MYSQL(Query lo\_num ${connid} SELECT DING FROM tbl\_del WHERE DRI=${DRI} AND ISNULL(deldep)=1 AND main\_transid\>17000 ORDER BY main\_transid)  
;\<-------------------While loop to fetch values and put them in their own variables based on how many values were returned  
exten =\> s,n,While($[${incr}\>0])  
exten =\> s,n,MYSQL(FETCH NEXT fetchid\_2 ${lo\_num} billof${incr})  
exten =\> s,n,Set(incr=${incr}-1)  
exten =\> s,n,EndWhile
