Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Why does my code skip this cell?

First, here's a look at the page:

User generated image
I've got a table that consists of 83 cells. The number of rows corresponds to the data that is in a temp table. The idea is to query each cell and see if there's data in it. I'm doing that with this:

for($i=1; $i<=$number_of_rows; $i++)
	for($y=0; $y<=83; $y++) 
		//here is where you define the content, the colspan and the style of the cell. Bear in mind that you'll have to close the cell at this point as well
		$statement = $mssql_pdo->prepare("select * from gant_table where DataDisplay_Row='$i' AND DataDisplay_StartCell='$y'");
		if (count($results) > 0)
			//echo "select * from gant_table where DataDisplay_Row='$i' AND DataDisplay_StartCell='$y'";
			foreach($results as $row) 
			//$body.="</td>"; //BTW you're good up to here

			} // this closes your foreach dynamic
		} //this closes your results question

Open in new window

So, my logic is:

Loop through each cell and query the database to see if there's data that corresponds to that cell / row number
If there's data, print the background color
If there's no data, simply print an empty cell

I'm having trouble in that if you look at my graphic, just below the two big, black errors, you'll notice the sequence of my $y variable "skips." It goes from 31 to 33 and on the same row it skips again from 66 to 68.

Why? Why doesn't cell 32 or 67 show up?

Here's the data as it appears in the database:

User generated image
You see two entries, both on row one. One has a data start cell of 0, the other has a start cell of 33. I can't understand why my "logic" skips right over cells 32 and 67.

Any ideas?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust


Ray! Your comment about the "TotalCellSpan" inspired me to go and take a second look at what was there. While a greater mind than my own could've figured things out quicker, after some pondering it became apparent that the TotalCellSpan was accurate given the fact that the first cell was accounted for as a 0. But then the $y value had to be adjusted to be 1 LESS than the TotalCellSpan in order for things to come out correctly.

Once that epiphany was applied, the sun broke through the clouds and we are gold.

If you're so inclined, sir, I've got another question that represents the last little "hump" on this project. I've got everything in place in terms of display, but I've got to interact with a MSSQL database and I'm using a MSSQL stored procedure. I've done this before, but in this instance I've got to pass some variables into the proc and it's laughing at me....