7 Replies - 747 Views - Last Post: 09 August 2008 - 09:54 AM Rate Topic: -----

#1 PHP_noob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-June 08

What's wrong with this piece of code?

Post icon  Posted 05 August 2008 - 11:25 PM

Hi folks pls refer to the following piece of code

<table width="200" border="0">
					  <tr>
						<th scope="col"><u><span class="style2">Uses of Atrium Ballroom (%) </span></u></th>
					  </tr>
					</table>
					<br />
					<table width="198" border="0">
					  <tr>
						<th width="77" scope="col"><span class="style2">Conferences</span></th>
		<?php 
		$con = connect();
		$rs2= mysql_query("Select count(*) as 'count' from event_meetings_reservation where Function='conference' ");
		$row2= mysql_fetch_array($rs2);
		$conference=$row2['count'];
		$rs4= mysql_query("Select count(*) as 'count' from event_meetings_reservation");
		$row4= mysql_fetch_array($rs4);
		$total= $row4['count'];
		$cpercent= ($conference/$total)*100;
						echo "<th width="111" scope="col">&nbsp;".$cpercent."</th>";
		?>
					  </tr>
					  <tr>
						<th scope="col"><span class="style2">Meetings</span></th>
						<th scope="col">&nbsp;</th>
					  </tr>
					  <tr>
						<th scope="col"><span class="style2">Others</span></th>
						<th scope="col">&nbsp;</th>
						</
					  </tr>
					</table>




That is just a portion of my codes in the webpage, when i run the page, this error message appear

Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in C:\xampp\htdocs\paradigm_new\meetings-atrium-reserve.php on line 205

The line 205 is referring to this line:
echo "<th width="111" scope="col">&nbsp;".$cpercent."</th>";

Anyone knows what's wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: What's wrong with this piece of code?

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,889
  • Joined: 10-May 07

Re: What's wrong with this piece of code?

Posted 05 August 2008 - 11:41 PM

This is how PHP evaluates this line of code...

echo " <-- PHP sees the command echo, & the double quote, start outputting from here.
<th width=" <-- PHP sees the end double quote, stop outputting.
111 <-- PHP sees plain text that is not a command, PHP is expecting to see a command or a semi colon at this point.
" scope="col">&nbsp;".$cpercent."</th>";



To fix this, use the following two options for outputting quotes in echo.

#1, escape the quote.
echo "<th width=\"111\" scope=\"col\">&nbsp;".$cpercent."</th>";



The slash tells PHP that the next character is a command character. \" says ignore the quote as an evaluation quote, & simply use it as regular text in the echo command.

#2, use single quotes & double quotes combined.

echo '<th width="111" scope="col">&nbsp;'.$cpercent.'</th>';



This allows the echo command to echo double quotes as if they were regular text, because PHP will continue to echo text until the 2nd, or ending, single quote is found.

I hope this helps explain the quote usage & common errors a little bit.
Was This Post Helpful? 1
  • +
  • -

#3 rjolitz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 110
  • Joined: 17-May 08

Re: What's wrong with this piece of code?

Posted 05 August 2008 - 11:49 PM

View PostPHP_noob, on 5 Aug, 2008 - 11:25 PM, said:

That is just a portion of my codes in the webpage, when i run the page, this error message appear

Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in C:\xampp\htdocs\paradigm_new\meetings-atrium-reserve.php on line 205

The line 205 is referring to this line:
echo "<th width="111" scope="col">".$cpercent."</th>";

Anyone knows what's wrong?


At first glance you need to put an escape character in front of your "

echo is reading "<th width=" and is expecting an ; after the quote.

Try this:


echo "<th width=\"111\" scope=\"col\">".$cpercent."</th>";




This might solve your dilema.
Was This Post Helpful? 0
  • +
  • -

#4 PHP_noob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-June 08

Re: What's wrong with this piece of code?

Posted 05 August 2008 - 11:52 PM

Hey bro thanks for the reply man, now everything works as desired

But do you know how to round up the output of :
$cpercent= ($conference/$total)*100;

to 2 decimal points?
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,889
  • Joined: 10-May 07

Re: What's wrong with this piece of code?

Posted 05 August 2008 - 11:57 PM

As per php.net

<?php
echo round(3.4);		 // 3
echo round(3.5);		 // 4
echo round(3.6);		 // 4
echo round(3.6, 0);	  // 4
echo round(1.95583, 2);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2);	// 5.05
echo round(5.055, 2);	// 5.06
?>


Was This Post Helpful? 0
  • +
  • -

#6 sankarshana  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-August 08

Re: What's wrong with this piece of code?

Posted 06 August 2008 - 05:11 AM

View PostPHP_noob, on 5 Aug, 2008 - 11:25 PM, said:

Hi folks pls refer to the following piece of code

<table width="200" border="0">
					  <tr>
						<th scope="col"><u><span class="style2">Uses of Atrium Ballroom (%) </span></u></th>
					  </tr>
					</table>
					<br />
					<table width="198" border="0">
					  <tr>
						<th width="77" scope="col"><span class="style2">Conferences</span></th>
		<?php 
		$con = connect();
		$rs2= mysql_query("Select count(*) as 'count' from event_meetings_reservation where Function='conference' ");
		$row2= mysql_fetch_array($rs2);
		$conference=$row2['count'];
		$rs4= mysql_query("Select count(*) as 'count' from event_meetings_reservation");
		$row4= mysql_fetch_array($rs4);
		$total= $row4['count'];
		$cpercent= ($conference/$total)*100;
						echo "<th width="111" scope="col">&nbsp;".$cpercent."</th>";
		?>
					  </tr>
					  <tr>
						<th scope="col"><span class="style2">Meetings</span></th>
						<th scope="col">&nbsp;</th>
					  </tr>
					  <tr>
						<th scope="col"><span class="style2">Others</span></th>
						<th scope="col">&nbsp;</th>
						</
					  </tr>
					</table>




That is just a portion of my codes in the webpage, when i run the page, this error message appear

Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in C:\xampp\htdocs\paradigm_new\meetings-atrium-reserve.php on line 205

The line 205 is referring to this line:
echo "<th width="111" scope='col'>&nbsp;".$cpercent."</th>";

Anyone knows what's wrong?



echo "<th width="111" scope="col"> ".$cpercent."</th>";

at this line please replace with single quotions

like this <th width='111' scope='col'> ".$cpercent."</th>

try it may i think it will solves your problem
Was This Post Helpful? 0
  • +
  • -

#7 PHP_noob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-June 08

Re: What's wrong with this piece of code?

Posted 09 August 2008 - 07:53 AM

View Postno2pencil, on 5 Aug, 2008 - 11:57 PM, said:

As per php.net

<?php
echo round(3.4);		 // 3
echo round(3.5);		 // 4
echo round(3.6);		 // 4
echo round(3.6, 0);	  // 4
echo round(1.95583, 2);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2);	// 5.05
echo round(5.055, 2);	// 5.06
?>



Is it like this?

echo '<th width="111" scope="col"> '.round ($cpercent, 2).'</th>';
Was This Post Helpful? 0
  • +
  • -

#8 chili5  Icon User is offline

  • D.I.C Lover

Reputation: 19
  • View blog
  • Posts: 1,144
  • Joined: 28-December 07

Re: What's wrong with this piece of code?

Posted 09 August 2008 - 09:54 AM

I think that would work. It's a little hard to read with all the different quotations though.

<?php
$percent_rounded = round($cpercent,2);
?>
<th width="111" scope="col"><?=$percent_rounded;?></th>



Is a little more neat :D

Note: You can use ceil and floor to round as well. :)

This post has been edited by chili5: 09 August 2008 - 09:55 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1