[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Breaking out of a function loop when querying a database that returns multiple rows of data
- From: Sean Conner <sean@...>
- Date: Mon, 21 Sep 2015 18:28:13 -0400
It was thus said that the Great Jonathan Hunter once stated:
> Hi Guys,
>
> Im quite new to Lua and Im having an issue with extracting particular data
> where there a multiple rows in a database I want to deal with so was
> wondering if someone could help?
>
> Basically using a function, Im extracting data from a Mysql table that has
> multiple rows, and its looping through the rows as expected.
>
> Now I have setup a number of entries for Time of day and I want to stop the
> loop (exit it) as soon as there is a match, and Id like to know how to
> achieve this.
>
> Basically I want to perform a query such as;
>
> select priority,dayofmonth,month,year,dayofmonth from timeofday_new where
> todname='sales' order by priority;
> +----------+------------+-------+------+------------+
> | priority | dayofmonth | month | year | dayofmonth |
> +----------+------------+-------+------+------------+
> | 1 | 20 | 9 | 2015 | 20 |
> | 2 | 14-17 | 9 | 2015 | 14-17 |
>
What's wrong with this? (and please excuse the SQL, I'm not terribly
familiar with it and you would generally need to either bind the values you
want to search to a prepared statement or build the SQL on the fly)
t = os.date("*t")
SELECT prority /* and other required fields */
FROM timeofday_new
WHERE
todname = 'sales'
AND year = t.year
AND month = t.month
AND dayofmonth = t.day
ORDER BY priority
Let SQL do the work for you. Or am I missing something?
-spc