Hi,
I am trying to write a script that will search a table for a specific part numbers previous part numbers (some have been changed several times). The table has 4 fields (partcodechangeid, partcodechangeoldpartcode, partcodechangenewpartcode, partcodechangedatechange). The result is used to form a new query which searches a stock movement table.
I am using the following function to search the table
[php]function queryoldparts($oldpartcode) {
$oldpartquery="select * from PartCodeChange where PartCodeChangeNewCode='$oldpartcode'";
$oldpartresult=mssql_query($oldpartquery);
$oldpartnumrows=mssql_num_rows($oldpartresult);
if ($oldpartnumrows==0){
//no older parts
} else {
//partcode has previously changed search on all
while ($partrow=mssql_fetch_array($oldpartresult)) {
$oldcode=$partrow['PartCodeChangeOldCode'];
$GLOBALS["qtysql"] .= "StockAuditPartCode='$oldcode' or ";
queryoldparts($oldcode);
}
}
}[/php]
and a similar function to search for any newer part codes
I call the functions from the following snippet
[php]$partquery=“select * from PartCodeChange where PartCodeChangeOldCode=’$mysqlpart’ or PartCodeChangeNewCode=’$mysqlpart’”;
$partresult=mssql_query($partquery);
$partnumrows=mssql_num_rows($partresult);
if ($partnumrows==0){
//no records in partcodechange table sql is simple
$qtysql=“select * from StockAudit where StockAuditPartCode=’$mysqlpart’ order by StockAuditId desc”;
} else {
$qtysql="select * from StockAudit where ";
//partcode has previously changed search for all other partcodes
while ($partrow=mssql_fetch_array($partresult)) {
$oldcode=$partrow['PartCodeChangeOldCode'];
$newcode=$partrow['PartCodeChangeNewCode'];
If ($oldcode==$mysqlpart) {
$qtysql .= "StockAuditPartCode='$newcode' or ";
querynewparts($newcode);
} else {
$qtysql .= "StockAuditPartCode='$oldcode' or ";
queryoldparts($oldcode);
}
}[/php]
The script will not work unless i comment out the two lines calling the functions. Can anyone help? I’m still learning php as its not my first language.