Jump to content

Pseudo code


JPark

Recommended Posts

I am trying to rework a page written by someone else and there is a function

function generate_click_box($row)
{
$html = <<<HTML

		  <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background:#036; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background:#036; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background:#036; overflow:hidden;"></div>
		  <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background:#036; overflow:hidden;"></div>
		  <div id="%1\$s_toggle" style="height:45px; width:191px; margin:0 auto; background:#036; color:#fff; cursor:pointer; font-size:12px; font-weight:bold; text-align:center; padding:0; margin:0;"><div style="padding:2px; vertical-align:middle;">%2\$s</div></div>
		  <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background:#036; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background:#036; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background:#036; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background:#036; overflow:hidden;"></div>

HTML
;

$html_disabled = <<<HTML

		  <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background: #cccccc; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background: #cccccc; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background: #cccccc; overflow:hidden;"></div>
		  <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background: #cccccc; overflow:hidden;"></div>
		  <div style="height:45px; width:191px; margin:0 auto; background: #cccccc; color:#036; font-size:12px; font-weight:bold; text-align:center; padding:0; margin:0;"><div style="padding:2px; vertical-align:middle;">
		  	<a href="http://factfinder.census.gov/servlet/EconSectorServlet?caller=dataset&sv_name=*&_SectorId=%1\$s&ds_name=EC0700A1&_lang=en&_ts=272288383987" target="_blank" alt="Click for %2\$s data">%2\$s<br />COMPLETED</a><br /></div></div>
		  <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background: #cccccc; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background: #cccccc; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background: #cccccc; overflow:hidden;"></div>
		  <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background: #cccccc; overflow:hidden;"></div>

HTML
;


return ($row[4])
         ? sprintf($html, $row[3], htmlentities( $row[1] ) )
         : sprintf($html_disabled, htmlentities( $row[5] ), htmlentities( $row[1] ) );

}

 

Can someone translate (put into pseudo code) the following piece

 

return ($row[4])

        ? sprintf($html, $row[3], htmlentities( $row[1] ) )

        : sprintf($html_disabled, htmlentities( $row[5] ), htmlentities( $row[1] ) );

 

Thanks!

 

Joe

Link to comment
https://forums.phpfreaks.com/topic/178608-pseudo-code/
Share on other sites

That's called a ternary statement.

 

So if you have something of the form cond ? ifTrue : ifFalse then ifTrue will be returned if cond evalutes to true, and ifFalse will be returned otherwise.

 

You could rewrite it to the following:

if ($row[4]) {
return sprintf($html, $row[3], htmlentities( $row[1] ) );
}
else {
return sprintf($html_disabled, htmlentities( $row[5] ), htmlentities( $row[1] ) );
}

Link to comment
https://forums.phpfreaks.com/topic/178608-pseudo-code/#findComment-942018
Share on other sites

Ok.  Makes a bit of sense...

 

So, why does my page crap out (nothing at all displays) if I change it to

return ($row[4])
         ? sprintf($html, $row[3], htmlentities( $row[1] ) )
         : echo "hello";

 

Isn't this saying that $row[4] is true then do sprintf($html, $row[3], htmlentities( $row[1] ) ) but if $row[4] is false then echo "hello"?

 

Joe

Link to comment
https://forums.phpfreaks.com/topic/178608-pseudo-code/#findComment-942028
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.