Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- for loops with select option


jd01 - 8:59 am on Oct 6, 2009 (gmt 0)


<?php

/* This is what your code looks like 'straight through'. I removed the function and made the changes I suggested, then pasted the code straight through, because sometimes it's easier to trouble shoot. I cannot find an issue based on what you requested compared to how the code is written, until possibly in the bottom section where I made a note, so either: A.) I'm just plain missing something. B.) I do not understand your project well enough. C.) There is an error in some other portion of the code causing it to behave unexpectedly. NOTE: You will have to POST data to the page for the code (all the way down to the for ($c=1; $c <=$col; $c++) line) to run correctly, becuse there is nothing to stop it from running in the absence of POST data. It will try to run and connect to your database and complete the loops every time the page is loaded. I don't know enough about how you are doing things to make much of a suggestion beyond: Make sure there is data posted before attempting to run the top section of code... KEEP IN MIND: This code will not work as posted. You will ned to make adjustments to it, but the adjustments should be simple and minor and have to be specific to the rest of your code, so I can't really help you there. */

if(isset($_POST["SQuery"]))
{
$value = count($_POST["value"]);

for($i=0; $i<$value; $i++)
{
$PackTye[$i] = $_POST["packTy"][$i];
echo '.$PackTye[$i].';
}
}

<form method="POST" action="SaveProduction.php">
$row = 3;
$col = 6;
for ($r=1; $r<=$row; $r++)
{
echo '<table>';
echo '<tr>';
?>

<td width="285" id="info" NOWRAP="NOWRAP">
<table>
<tr>

</select></td>
<td width="44" height="30" valign="top">

<?php
$resultz = mssql_query("select PackTypeID,PackType,Market from PackType where Market ='China'");
$limitz = mssql_num_rows($resultz);

if($limitz > 0)
{

echo '<select name="packTy" value="'.$PackTye[$r].'">';

for ($v = 0; $v < $limitz; $v++)
{
$PackType = mssql_result($resultz, $v, "PackType");
$PackTypeID = mssql_result($resultz, $v, "PackTypeID");

echo '
<option value='.$PackTypeID.'>'.$PackType.'</option>
';

}
echo '</select>';

}
else
{

echo 'Pag Sure oi';
}

}
?>

<input type="hidden" size="6" name="value[]" value="<?=$r?>">
</td>

</tr>

</table>
</td>

<?php

/* EDITED: I found where $col comes from, but it looks like you mean something like $col rather than what you have... col[] will set the name of the text input to col[] and try to pass that in the POST as POST[col[]]... Other than that I have no idea what this section of code does, so there's no way for me to know if this is where the issue is or not. ADDED: I think part of the issue is your Form Field Names... value[] and col[]. I don't understand what they are supposed to do? It's not something I've seen / used, so maybe they should be something different? Possibly col[$col]? */

for ($c=1; $c <=$col; $c++)
{
echo'<td><input type="text" size="6" name="col[]"></td>';
}
echo '</tr>';
echo '</table>';
}
</form>
<tr>
<td><input type="submit" name="SQuery" value="Submit" /></td>
</tr>
?>


Thread source:: http://www.webmasterworld.com/php/4001916.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com