0

I need a little bit of help. I am pretty new to PHP so this might be an easy one for you guys. I have a while loop that is in a table. The problem I have is when the while loop returns no value, it does not build the rest of the table so row 1 might have 13 columns and row 2 might have 11 and I have no ides how to fix it. Here is the code I am using right now. Thanks for the help.

$num = 0;
while ($r2 = oci_fetch_array(results2))
{
echo "<td>" .$r2['VARIABLE1_DESC']. ": " .$r2['VARIABLE2_COMMENT']. "</td>";
$num++;
}
for (i=6; $i>$num; $i--);
Shane
  • 1
  • And we have very little to go on so we don't either know how to fix it. You could share a json_encoded string of the array or a var_export – Andreas Jan 31 '19 at 17:23
  • May be this is helpful for you. Have a look here https://stackoverflow.com/a/15140178/1138192 – A l w a y s S u n n y Jan 31 '19 at 17:25
  • Maybe I'm not asking the right question. The code runs properly, the problem is it may only have one value so it only builds one column on the table for that row. The next row may have 4 values so it will build 4 columns on that row. I just want it to build a consistent amount of columns for each row. – Shane Jan 31 '19 at 19:12

1 Answers1

0

If you knew the target number of columns, you could add a loop after the while to build $target - $num <td> elements. Some ideas to determine the a target:

  • pick an arbitrary target

  • execute a sql to determine the max number of rows results2 is going to fetch.

DinoCoderSaurus
  • 6,110
  • 2
  • 10
  • 15