This topic is locked

Calculating field value when adding - few options - rookie question

8/25/2015 5:09:42 PM
PHPRunner General questions
C
cicatl author

Hi all, new to php runner, but found few interesting article about a related challenge.

I am trying to have a value prepopulate when adding a record, the value is nothing else than the current date (20080825) concatenated with a count result from a query.

I got the query right where I get the total value I need, and off course the current date, but I am having some doubts about where to place the action
I am placing the code into the "the field default value" into the add page, but the actual function to process the query does not return anything here, or I am doing something really wrong.
Here is my piece of code
$actual_deliveries = mysqli_query("SELECT

COUNT(id) AS Deliveries

FROM MYtable

WHERE (Month(delivery_date) = MONTH(CURDATE())) AND (YEAR(delivery_date) = YEAR(CURDATE()))");
$aName1 = mysqli_fetch_assoc($actual_deliveries);
$values ['delivery_number'] = $aName1
When I do that, I get a mysqli is missing a 2nd parameter, asssuming that was the connection to the database, i included that, and then it just does not open at all.

The value I want is on the "Deliveries" variable that I have included in the query, I now that I should use a mysqli_fetch to retrieve that value, but like I said I am missing something that I cannot see anymore after many trials.

That is the basic, in reality, I would what the delivery_number value to be the current date + that count value, for example if the count was 5, then the value should be 201508255, that is it.
I found similar cases, but do not seem to get it to work just yet.

http://xlinesoft.com/articles/how_to_use_calculated_fields.htm

C
cicatl author 8/25/2015

Found this

http://www.asprunner.com/forums/topic/14732-generate-a-custom-transaction-number-for-example-so20100700001/
which could work if i could only get the value from the SQL count.