Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[SOLVED] Why Is This Inline Statement Php Breaking My Tables?

inline html5

  • This topic is locked This topic is locked
11 replies to this topic

#1 TenLeftFingers

TenLeftFingers

    CC Newcomer

  • Member
  • PipPip
  • 13 posts

Posted 12 July 2012 - 09:46 AM

To make the tables on my webpage more accessible, I wrapped them in
<a name="tableName"> Table goes here </a>
tags.

This works fine, but to make it more dynamic I now have the function that draws the table (when passed an array) figure out the object name and pop it in itself, like so:
<a name="<?php get_class(array_pop($objects))?>"> Table goes here </a>
get_class returns a String so I expect no difference in the output of my funcion.

This has resulted in my tables omitting the last object of the array every time. Or if there is only one element in the array, I get nothing.

I would love to know:
  • What about my current php statement is causing this problem when the plain string was working fine? The php returns a string anyway!, and
  • How can I properly achieve the effect I'm going for?
The full function is posted below.

Many thanks,
Ten

$vendor = new vendor(); //create an object (database table of vendors)
$vendors = $vendor->GetList(); //return the entire database table, each row is an array element
drawTable($vendors); //pass the array to drawTable
function drawTable($objects, $exclusions="")//exclusions isn't implemented yet, but needs
{		 //to take the fields not to print and omit
?>		 <!--them from the table. The counter needs -->
<a name="<?php get_class(array_pop($objects))?>"><html>		 <!--to know to not count them also so that -->
<table>		 <!--headers and footers are measured right -->
<tr>	 <!--Also, we could automatically ignore those ending in-->
<td>	 <!--'Id', or convert to actual values when not listed -->
<table id="rounded-corner" summary="objects"> <!--as exclusions -->
<thead>
	 <tr>
	
	 <?php
	 foreach ($objects as $object)//iterate headers
{
$loopCount = 1;
$vars = get_object_vars($object);
foreach ($vars as $key => $val)
{
	 if ($key == get_class($object) . "Id")
	 {
	 continue;
	 }
	 if ( $loopCount == 1 )
	 {
	 echo '<th scope="col" class="rounded-company">'. ucfirst(pascalSpaces($key)).'</th>';
	 }
	 else if ( $loopCount == count($vars)-1 )
	 {
	 echo '<th scope="col" class="rounded-q4">'.removeId(ucfirst(pascalSpaces($key))).'</th>';
	 }
	 else
	 {
	 echo '<th scope="col">'.removeId(ucfirst(pascalSpaces($key))).'</th>';
	 }
	 $loopCount++;
}
?>
	 <!--html-->
	 </tr>
</thead>
	 <tfoot>
	 <tr>
	 <?php
		 foreach ($objects as $object)
		 {
	 $vars = get_object_vars($object);
		 echo '<td colspan="' . (count($vars)-2) . '" class="rounded-foot-left">
			 The above data represents <u>' . get_class($object) . '</u> records.
			 Blank spaces represent absent values.</td>';
		 break;
		 }
	 ?>
	 <!--
<?php
	 foreach ($objects as $object)//iterate for footers
{
$loopCount = 1;
$vars = get_object_vars($object);
foreach ($vars as $key => $val )
{
	 if ($loopCount < count($vars) -3)
	 {
		 echo '<td></td>';
	 }
	 $loopCount++;
	 }
	 break;//we dont need a footer for each object.
}
?>
-->
		 <td class="rounded-foot-right">&nbsp;</td>
	 </tr>
</tfoot>
<tbody>
	 <tr>
	 <?php
	 foreach ($objects as $object)
	 {
		 $vars = get_object_vars($object);
		 foreach ($vars as $key => $val)
		 {
		 if ($key == get_class($object) . "Id")
	 {
		 continue;
	 }
			 echo '<td>' . $val .'</td>';
		 }
		 echo '</tr>';
	 }
	 ?>
	
</tbody>
</table>
</html></a>
<?php
		 break; //we don't need to get paramaters for other similar objects.
}
echo "<br>";
} //end drawTable function

  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 12 July 2012 - 11:24 AM

what does the html generated look like?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 TenLeftFingers

TenLeftFingers

    CC Newcomer

  • Member
  • PipPip
  • 13 posts

Posted 12 July 2012 - 12:05 PM

what does the html generated look like?

I never thought to look! I've just run a diff on two versions of the page and there are differences. I'm not sure why though.

I've attached the two page sources and a .diff file.

session.php is the normal and working version.
session2.php uses my php 'magic' to make the anchors dynamically, breaking the table.

<edit>The interesting line numbers are 53, 76 and 82.</edit>

Thanks!

The output of diff is below:
25c25
< <div class="rounded-container">Welcome Jarlathreidy</b>. Logging IP address 109.79.216.236</div><br><a href=#patient><span class="small-container">Patients</span></a> &nbsp<a href="#carer"><span class="small-container">Carers</span></a> &nbsp<a href="#vendor"><span class="small-container">Vendors</span></a> &nbsp<a href="#pharmacy"><span class="small-container">Pharmacies</span></a> &nbsp<a href="#doctor""><span class="small-container">Doctors</span></a> &nbsp<a href="#medication"><span class="small-container">Medication</span></a> &nbsp<a href="#discount"><span class="small-container">Discounts</span></a> &nbsp<a href="#compliance"><span class="small-container">Compliance</span></a> &nbsp<br><br>		 <!--them from the table. The counter needs -->
---
> <div class="rounded-container">Welcome Jarlathreidy</b>. Logging IP address 89.100.184.84</div><br><a href=#patient><span class="small-container">Patients</span></a> &nbsp<a href="#carer"><span class="small-container">Carers</span></a> &nbsp<a href="#vendor"><span class="small-container">Vendors</span></a> &nbsp<a href="#pharmacy"><span class="small-container">Pharmacies</span></a> &nbsp<a href="#doctor""><span class="small-container">Doctors</span></a> &nbsp<a href="#medication"><span class="small-container">Medication</span></a> &nbsp<a href="#discount"><span class="small-container">Discounts</span></a> &nbsp<a href="#compliance"><span class="small-container">Compliance</span></a> &nbsp<br><br>		 <!--them from the table. The counter needs -->
53c53
< <a name="test"><html>		 <!--to know to not count them also so that --><!--?php get_class(array_pop($objects)) ?-->
---
> <a name="carer"><html>		 <!--to know to not count them also so that --><!--?php get_class(array_pop($objects)) ?-->
76c76
<	 <td>Barney Gumble</td><td>32 Springfield Grove</td><td>Springfield</td><td>Simpsons Land</td><td></td><td>USA</td><td>bgumble@fox.com</td><td>123456789</td></tr><td>Wiley Coyote</td><td>123 The Place</td><td>Somewhere Out There</td><td></td><td></td><td>England</td><td>wcoyote@gmail.com</td><td>987654321</td></tr>	
---
>	 <td>Barney Gumble</td><td>32 Springfield Grove</td><td>Springfield</td><td>Simpsons Land</td><td></td><td>USA</td><td>bgumble@fox.com</td><td>123456789</td></tr>	
82c82
< <a name="test"><html>		 <!--to know to not count them also so that --><!--?php get_class(array_pop($objects)) ?-->
---
> <a name="medication"><html>		 <!--to know to not count them also so that --><!--?php get_class(array_pop($objects)) ?-->
91,109c91
<	 <th scope="col" class="rounded-company">Name</th><th scope="col">Strength</th><th scope="col">Form</th><th scope="col">Route</th><th scope="col">Signatura</th><th scope="col" class="rounded-q4">Rx Number</th>	 <!--html-->
<		 </tr>
<	 </thead>
<		 <tfoot>
<	 <tr>
<	 <td colspan="5" class="rounded-foot-left">
<			 The above data represents <u>medication</u> records.
<			 Blank spaces represent absent values.</td>	 <!--
< <td></td><td></td><td></td> -->
<		 <td class="rounded-foot-right">&nbsp;</td>
<		 </tr>
<	 </tfoot>
<	 <tbody>
<	 <tr>
<	 <td>Zanex</td><td>10mg</td><td>Pill</td><td>Oral</td><td>1 Daily</td><td>001</td></tr>	
<	 </tbody>
<	 </table>
<	 </html></a>
<	 <br>		 <!--them from the table. The counter needs -->
---
>	 <br>		 <!--them from the table. The counter needs -->
111c93
< <a name="test"><html>		 <!--to know to not count them also so that --><!--?php get_class(array_pop($objects)) ?-->
---
> <a name="pharmacy"><html>		 <!--to know to not count them also so that --><!--?php get_class(array_pop($objects)) ?-->
134c116
<	 <td>Matt O'Flaherty</td><td>Shop Street</td><td></td><td></td><td>Galway</td><td>Ireland</td><td>matt@oflahertypharmacy.com</td><td>091235987</td></tr><td>Hogans Pharmacy</td><td>Father Griffin Road</td><td></td><td></td><td>Galway</td><td>Ireland</td><td>info@hogans.ie</td><td>091234567</td></tr>	
---
>	 <td>Matt O'Flaherty</td><td>Shop Street</td><td></td><td></td><td>Galway</td><td>Ireland</td><td>matt@oflahertypharmacy.com</td><td>091235987</td></tr>	
140c122
< <a name="test"><html>		 <!--to know to not count them also so that --><!--?php get_class(array_pop($objects)) ?-->
---
> <a name="doctor"><html>		 <!--to know to not count them also so that --><!--?php get_class(array_pop($objects)) ?-->
163c145
<	 <td>Martin</td><td>P</td><td>Sheen</td><td>27 The Mews</td><td>Overthere</td><td></td><td></td><td>Ireland</td><td>mps@mailserver.net</td><td>2345246</td></tr><td>Bill</td><td>W</td><td>Murray</td><td>64 Glendara</td><td>Westside</td><td></td><td></td><td>Ireland</td><td>bill@yahoo.co.uk</td><td>34566543</td></tr>	
---
>	 <td>Martin</td><td>P</td><td>Sheen</td><td>27 The Mews</td><td>Overthere</td><td></td><td></td><td>Ireland</td><td>mps@mailserver.net</td><td>2345246</td></tr>	

Attached Files


  • 0

#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 12 July 2012 - 12:17 PM

what is all these <html> tags doing in the middle? the html tag is surrounding the whole page and is only used like that?
also, a complete html source instead of a diff makes it easier to look at, to find html errors, something you can post?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#5 TenLeftFingers

TenLeftFingers

    CC Newcomer

  • Member
  • PipPip
  • 13 posts

Posted 12 July 2012 - 12:24 PM

what is all these <html> tags doing in the middle? the html tag is surrounding the whole page and is only used like that?
also, a complete html source instead of a diff makes it easier to look at, to find html errors, something you can post?

Whenever I switch from php to html I close the php: ?> and open html: <html>, then when I finish the html code, I close the html: </html>, and open the php again: <?php. Is this wrong?

I've attached the html for the page in the previous posts (but I saved the sources as session.php and session2.php). These are the two versions of the html output sources.
  • 0

#6 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 12 July 2012 - 01:30 PM

yes, it is totally wrong. you open php with <?php and closes it with ?> and together it makes one tag (<?php ?>) within the html. the browser don't know about the <?php ?> tags at all, as it's removed by the php script while executing the content between.

upload your html to the html validator here http://validator.w3.org/ and see all the syntax errors you have in your html. (about 90 errors...)
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#7 TenLeftFingers

TenLeftFingers

    CC Newcomer

  • Member
  • PipPip
  • 13 posts

Posted 13 July 2012 - 02:35 AM

yes, it is totally wrong. you open php with <?php and closes it with ?> and together it makes one tag (<?php ?>) within the html. the browser don't know about the <?php ?> tags at all, as it's removed by the php script while executing the content between.

upload your html to the html validator here http://validator.w3.org/ and see all the syntax errors you have in your html. (about 90 errors...)

Thanks Orjan, I can see that the "good" source has 81 errors and the "bad" source has 90 - which is a difference of 9. Hopefully those 9 errors contain a solution. I'll see what I can do today.
  • 0

#8 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 13 July 2012 - 03:58 AM

the first thing to search for is unfinished tags... like
<a href="" </a>
(the start tag isn't closed by a ">") and for unclosed tags, like
<a href=""> ...
those are the most common mistakes according to me. Unfinished quotes might also be a problem...
<a href="http://www.codecall.net>CodeCall</a>

Also, make sure the tags pair up properly,
<div><strong></div></strong>
can make problems. make it
<strong><div></div></strong>
or
<div><strong></strong></div>
instead.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#9 TenLeftFingers

TenLeftFingers

    CC Newcomer

  • Member
  • PipPip
  • 13 posts

Posted 14 July 2012 - 05:53 AM

I have reduced the code considerably to isolate the error. I get 0 errors now when I use:
<p class="patient"></p>
above each table.
But when I add inline php:
<p class="<? echo "patient" ?>"></p>
I get messed up html in the output. It's strange, because if you view the source of www.barryreidy.com/testing/session.php , the <p> is place *inside* the later tables. (all tables are generated with the same function.

The validator points to the problem on line 65 of the source: http://validator.w3....C_Validator/1.3

One thing is for certain, the inline php is causing this. It is obviously not returning a clean string, but has some non-printing characters coming back with it. I have no idea how to debug this further.
  • 0

#10 TenLeftFingers

TenLeftFingers

    CC Newcomer

  • Member
  • PipPip
  • 13 posts

Posted 14 July 2012 - 06:39 AM

I have tried removing the inline php and doing it this way, but I still get the same results:
function drawTable($objects, $exclusions="")//exclusions isn't implemented yet, but needs
{		   //to take the fields not to print and omit
$class = get_class(array_pop($objects));
echo '<p class="' . $class . '"></p>';
?>		 
Beginning Table Print<br />
<table><!--id="rounded-corner" -->
    <thead>
	 <tr>
	 <?php
	 foreach ($objects as $object)//iterate headers to make th's
  {
   $loopCount = 1;
   $vars = get_object_vars($object);
   foreach ($vars as $key => $val)
   {
	 if ($key == get_class($object) . "Id")
	 {
	    continue;
	 }
	 if ( $loopCount == 1 )
	 {
	   echo '<th scope="col" class="rounded-company">'. ucfirst(pascalSpaces($key)).'</th>';
	 }
	 else if ( $loopCount == count($vars)-1 )
	 {
	   echo '<th scope="col" class="rounded-q4">'.removeId(ucfirst(pascalSpaces($key))).'</th>';
	 }
	 else
	 {
	   echo '<th scope="col">'.removeId(ucfirst(pascalSpaces($key))).'</th>';
	 }
	 $loopCount++;
  }
  ?>
	    </tr>
    </thead>
    <tfoot>
	 <tr>
	 <?php
		 foreach ($objects as $object)
		 {
	 $vars = get_object_vars($object);
		   echo '<td colspan="' . (count($vars)-2) . '" class="rounded-foot-left">
			 The above data represents <u>' . get_class($object) . '</u> records.
			  Blank spaces represent absent values.</td>';
		   break;
		    }
	    ?>
	
		 <td class="rounded-foot-right">&nbsp;</td>
	    </tr>
    </tfoot>
    <tbody>
	
	 <?php
	    foreach ($objects as $object)
	    {
   echo '<tr>';
  
		 $vars = get_object_vars($object);
		 foreach ($vars as $key => $val)
		 {
		   if ($key == get_class($object) . "Id")
	   {
		  continue;
	   }
			  echo '<td>' . $val .'</td>';
		    }
		    echo '</tr>';
  
	    }
	    ?>
	   
    </tbody>
    </table>
Ending table print<br />
    <?php
		    break; //we don't need to get paramaters for other similar objects.
  }
}  //end drawTable function 

  • 0

#11 TenLeftFingers

TenLeftFingers

    CC Newcomer

  • Member
  • PipPip
  • 13 posts

Posted 14 July 2012 - 08:53 AM

I've tracked the problem down to a mismatched brace in my php function :rolleyes: . I still don't know why it only caused a problem with the inline php and not in other cases, but the issue is resolved.

Thanks for your help Orjan.
  • 0

#12 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 14 July 2012 - 09:36 AM

You're welcome. If you have any other issues, don't hesitate to ask more!

This topic has been marked as SOLVED. If you have a similar question or topic, go back to the subforum and start a new topic to continue discussions.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download