Why does my code skip this cell?

First, here's a look at the page:

my page
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'");
		$statement->execute();
		$results=$statement->fetchAll(PDO::FETCH_ASSOC);
		if (count($results) > 0)
		{
			//echo "select * from gant_table where DataDisplay_Row='$i' AND DataDisplay_StartCell='$y'";
			foreach($results as $row) 
			{ 
			include("multi_row.php");
			//$body.="</td>"; //BTW you're good up to here

			} // this closes your foreach dynamic
		} //this closes your results question
		else
		{
			$body.="<td>";
			$body.=$y;	
			$body.="</td>";
		}
		if($y==83)
		{
			$body.="</tr><tr>";
		}
	}
} 

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:

database
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?
brucegustPHP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Unless we have your data we can't make any tests, so that would be the first thing you might want to post - so we can load the database table with the same data you're using.

But that aside, just looking at the image of the data gives me pause.  It does not appear to be logically consistent.  Subtract DataDisplay_StartCell from DataDisplay_EndCell.  TotalCellSpan does not make sense to me.

Also, you might want to go into the PHP script and create your query strings in a separate variable.  Since you're not really using "prepared" queries, you can do this.  It will enable you to print out the query string so you can see what is actually getting sent to the SQL engine.  Var_dump() is your friend!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brucegustPHP DeveloperAuthor Commented:
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.

Thanks!
0
Ray PaseurCommented:
:-)
0
brucegustPHP DeveloperAuthor Commented:
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....

http://www.experts-exchange.com/questions/28737412/How-to-I-use-PDO-to-pass-variables-into-a-MSSQL-Stored-Procedure.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.