Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP MySQL - Code generator using different table records
    primarykey
    data
    text
    <p>Me again,</p> <p>In this case I have an accountingcode table [ACCOUNTINGCODE] with the fields:<br /> ACC1CUST (example: IVMA)<br/> ACC2DATE (example: 12)<br/> ACC3NROFPROJ (example: 05)<br/> ACC4USER (example: JD)<br/></p> <p>Let me explain.<br/> These is the example of an accountingcode:<br/> IVMA-12-01-JD<br/> IVMA-12-02-RP<br/> IVMA-12-03-WD<br/> IVMA-12-04-JD<br/></p> <p>ACC1CUST is filled with a NAMECODE of a [CUSTOMER].<br/> ACC2DATE are the 2 end numbers of the year the [ACCOUNTINGCOE] is made by the user.<br/> ACC3NROFPROJ is the number of projects of the same [CUSTOMER] in the same year. So ACC1CUST, ACC2DATE and ACC3NROFPROJ depend on each other.<br/> ACC4USER is the NAMECODE of the [EXECUTOR] so this is not so important here.<br/></p> <p>I made a generator query. This generator counts +1 on the MAX projects which he has in the [ACCOUNTINGCODE]. But my code isn't depending on the the year (ACC2DATE). So if I already have IVMA-12-01-JD and next I place IVMA-13 it won't start over at 01, but continues at 02. Ofcourse, because my code is checking the amount of projects of the ACC1CUST.</p> <p>My query is: <br/></p> <pre><code>$projectcount=" SELECT accountingcode.custid, customer.custid, MAX(acc3nrofproj) as 'projects' FROM accountingcode, customer WHERE accountingcode.custid= customer.custid AND customer.custid = '$custid' "; $result3=mysql_query($projectcount) or die("query fout " . mysql_error() ); while( $record3=mysql_fetch_array($result3) ) { $projectcount=$record3['projects']; $projectcount = $projectcount+1; $format = '%1$03s'; $formatprojectcount = sprintf($format, $projectcount); } </code></pre> <p>But this doesn't make any difference if you start a new year which doesn't exists already in ACC2DATE.<br/></p> <p>Anyone any idea how I can make this work?<br/></p> <p>Thank you alot in advance!<br/><br/></p> <p>FOUND IT<br/></p> <pre><code> $projectcount=" SELECT accountingcode.custid, accountingcode.acc2date, MAX(acc3nrofproj) as 'projects' FROM accountingcode, customer WHERE accountingcode.custid= customer.custid AND customer.custid = '$custid' AND acc2date = '$formatdatefrom' "; $result3=mysql_query($projectcount) or die("query fout " . mysql_error() ); while( $record3=mysql_fetch_array($result3) ) { $projectcount=$record3['projects']; $projectcount = $projectcount+1; $format = '%1$03s'; $formatprojectcount = sprintf($format, $projectcount); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload