patchwolf wrote in php

Hi guys,



I'm having some trouble with this one. I've got a table generator on step one with is working just fine... Step two, which is to pull entries from an ODBC query, and populate every cell with the same select form, is falling over after the first cell.



print ("<h1 style=\"border-bottom: 2px solid #999999;\">Step 2: Select Deals</h1>\n");


require_once (
'../../../sql_connect.php');

$sql = "Select * From RedHot WHERE (ValidFrom <= '".date("m")."/".date("d")."/".date("y")."' AND ValidTo >= '".date("m")."/".date("d")."/".date("y")."')";


$result = odbc_exec($dbc, $sql);

if (
odbc_num_rows($result) == 0) { // if $count is 0, then there were no deals found.

    
print ("<p style=\"font-weight: 700;\">Error: No records found.</p>");


} else {

    print (
"<form method=\"POST\" name=\"tilelist\" action=\"".$_SERVER['PHP_SELF']."?step=3\">\n");

    print (
"<table>

<tbody>"
);


    for (
$i = 1; $i <= $_POST['height']; $i++) {

print (
"<tr>");


for (
$j = 1; $j <= $_POST['width']; $j++) {

    print (
"<td style=\"border: 1px dotted #999999;\"><select name=\"r".$i."c".$j."\">");


    
$l = 0;

    while (
$rows = odbc_fetch_array ($result)) {

print (
"<option value=\"".$rows['HotID']."\">".$rows['Caption']."</option>\n");


$l++;

    }

    print (
"</select></td>");

}

print (
"</tr>");

    }

    print (
"</tbody>


    </table>"
);

}

odbc_close($dbc);

include_once (
'./footer.inc.php');

break;


Any ideas how I can run the while loop on each iteration? I think I might need to use the reset function, but I can't work out how or where.



EDIT: Fixed.



print ("<h1 style=\"border-bottom: 2px solid #999999;\">Step 2: Select Deals</h1>\n");


require_once (
'../../../sql_connect.php');

$sql = "Select * From RedHot WHERE (ValidFrom <= '".date("m")."/".date("d")."/".date("y")."' AND ValidTo >= '".date("m")."/".date("d")."/".date("y")."')";


$result = odbc_exec($dbc, $sql);

if (
odbc_num_rows($result) == 0) { // if $count is 0, then there were no deals found.

    
print ("<p style=\"font-weight: 700;\">Error: No records found.</p>");


} else {

    
$optionloop = array();

    
$rows = array();

    while (
odbc_fetch_into ($result, $optionloop)) {

        
array_push($rows, $optionloop);


    }

    print ("<form method=\"POST\" name=\"tilelist\" action=\"".$_SERVER['PHP_SELF']."?step=3\">\n");

    print (
"<table>

        <tbody>"
);


    for (
$i = 1; $i <= $_POST['height']; $i++) {

        print (
"<tr>");


        for (
$j = 1; $j <= $_POST['width']; $j++) {

            print (
"<td style=\"border: 1px dotted #999999;\"><select name=\"r".$i."c".$j."\">");


            foreach (
$rows as $fieldnum) {

                print (
"<option value=\"".$fieldnum[0]."\">".$fieldnum[1]."</option>\n");


            }

            print ("</select></td>");

        }

        print (
"</tr>");

    }

    print (
"</tbody>


    </table>"
);

}

odbc_close($dbc);

include_once (
'./footer.inc.php');

break;