Forum Moderators: coopster

Message Too Old, No Replies

Help to clean up this PHP code

         

slimnutty5000

6:32 pm on Jan 23, 2007 (gmt 0)

10+ Year Member



Can someone help me to clean up this PHP code? I was translating it from ASP and this is as close as i could get.

<?php
$txtDynaListRelation.$txtDynaListLabel.$txtDynaListValue.$oDynaListRS;

$txtDynaListRelation = "mttips"; // Name of recordset field relating to parent
$txtDynaListLabel = "model"; // Name of recordset field for child Item Label
$txtDynaListValue = "brand"; // Name of recordset field for child Value
$oDynaListRS = 'selector'; // Name of child list box recordset

$varDynaList = -1;
$varMaxWidth = "1";
$varCheckGroup = $oDynaListRS.$Fields.$Item[txtDynaListRelation].$Value;
$varCheckLength = 0;
$varMaxLength = 0;

while (!oDynaListRS.EOF){

if ($varCheckGroup!= $oDynaListRS.$Fields.$Item[txtDynaListRelation].$Value) {
$varMaxLength = $Math.$max($varCheckLength,($varMaxLength));
$varCheckLength = 0;
}
?>
arrDynaList[<?=($varDynaList+1)?>] = "<?=($oDynaListRS.$Fields.$Item[txtDynaListRelation].$Value)?>";
arrDynaList[<?=($varDynaList+2)?>] = "<?=($oDynaListRS.$Fields.$Item[$txtDynaListLabel].$Value)?>";
arrDynaList[<?=($varDynaList+3)?>] = "<?=($oDynaListRS.$Fields.$Item[$txtDynaListValue].$Value)?>";
<?

if ($oDynaListRS.$Fields.$Item[$txtDynaListLabel].$Value.$length > $varMaxWidth.$length) {
$varMaxWidth = $oDynaListRS.$Fields.$Item[$txtDynaListLabel].$Value;
}
$varCheckLength = $varCheckLength + 1;
$varDynaList = $varDynaList + 3;
$oDynaListRS.MoveNext();
}
$varMaxLength = $Math.$max($varCheckLength,($varMaxLength));

?>

mcibor

10:21 am on Jan 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it will be easier, if you wrote what you need, not to translate from asp.
As I tried to translate I stopped at the while (!oDynaListRS.EOF) - I'm not sure what is that object.

Could you provide the input of data as well?

slimnutty5000

5:06 pm on Jan 24, 2007 (gmt 0)

10+ Year Member



Heres the entire Javascript and PHP code:
( I got this from Adobe's site for Dreamweaver tutorial, but all they had was for ASP)

<script language="JavaScript">
<!--

var arrDynaList = new Array();
var arrDL1 = new Array();

arrDL1[1] = "brands"; // Name of parent list box
arrDL1[2] = "selector"; // Name of form containing parent list box
arrDL1[3] = "models"; // Name of child list box
arrDL1[4] = "selector"; // Name of form containing child list box
arrDL1[5] = arrDynaList;

<?php
$txtDynaListRelation.$txtDynaListLabel.$txtDynaListValue.$oDynaListRS;

$txtDynaListRelation = "mttips"; // Name of recordset field relating to parent
$txtDynaListLabel = "model"; // Name of recordset field for child Item Label
$txtDynaListValue = "brand"; // Name of recordset field for child Value
$oDynaListRS = 'selector'; // Name of child list box recordset

$varDynaList = -1;
$varMaxWidth = "1";
$varCheckGroup = $oDynaListRS.$Fields.$Item[txtDynaListRelation].$Value;
$varCheckLength = 0;
$varMaxLength = 0;

while (!oDynaListRS.EOF){

if ($varCheckGroup!= $oDynaListRS.$Fields.$Item[txtDynaListRelation].$Value) {
$varMaxLength = $Math.$max($varCheckLength,($varMaxLength));
$varCheckLength = 0;
}
?>
arrDynaList[<?=($varDynaList+1)?>] = "<?=($oDynaListRS.$Fields.$Item[txtDynaListRelation].$Value)?>";
arrDynaList[<?=($varDynaList+2)?>] = "<?=($oDynaListRS.$Fields.$Item[$txtDynaListLabel].$Value)?>";
arrDynaList[<?=($varDynaList+3)?>] = "<?=($oDynaListRS.$Fields.$Item[$txtDynaListValue].$Value)?>";
<?

if ($oDynaListRS.$Fields.$Item[$txtDynaListLabel].$Value.$length > $varMaxWidth.$length) {
$varMaxWidth = $oDynaListRS.$Fields.$Item[$txtDynaListLabel].$Value;
}
$varCheckLength = $varCheckLength + 1;
$varDynaList = $varDynaList + 3;
$oDynaListRS.MoveNext();
}
$varMaxLength = $Math.$max($varCheckLength,($varMaxLength));

?>

//-->
</script>

<!-- End of object/array definitions, beginning of generic functions -->

<script language="JavaScript">
<!--

function setDynaList(arrDL){

var oList1 = document.forms[arrDL[2]].elements[arrDL[1]]
var oList2 = document.forms[arrDL[4]].elements[arrDL[3]]
var arrList = arrDL[5]

clearDynaList(oList2);

if (oList1.selectedIndex == -1){
oList1.selectedIndex = 0;
}

populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
return true;
}

function clearDynaList(oList){

for (var i = oList.options.length; i >= 0; i--){
oList.options[i] = null;
}

oList.selectedIndex = -1;
}

function populateDynaList(oList, nIndex, aArray){

for (var i = 0; i < aArray.length; i= i + 3){
if (aArray[i] == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
}
}

if (oList.options.length == 0){
oList.options[oList.options.length] = new Option("[none available]",0);
}

oList.selectedIndex = 0;
}

//-->
</script>