homepage Welcome to WebmasterWorld Guest from 54.198.148.191
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Make text bold if criteria is met
biru32




msg:4289143
 6:21 pm on Mar 29, 2011 (gmt 0)

Hi, what I believe I'm trying to do is fairly simple, except I'm not a programmer, so I simply don't know. I have information stored on a MySQL server. When that information is pulled, I would like to have a script that says format (bold) the output text if a field is populated with the word "YES".

Simple right? Therefore:

If column onr_sponsored = "YES", THEN bold all output text for that record.

I can send .php file that currently pulls information into table if needed.

Thanks!

 

Matthew1980




msg:4289147
 6:32 pm on Mar 29, 2011 (gmt 0)

Hi there biru32,

Welcome to WebmasterWorld!

Well, posting what you have so far would be advantageous, as this means that we can see which direction to point you in, though posting HUGE code dumps isn't really advised as this puts people off offering advice/help/suggestions.

What your asking isn't too difficult at all, it's just a matter of setting a variable to change the fount-weight: value directly in the attributes opening tag (using CSS term there otherwise it's just <b></b> tags around your text :)).

So just post the relevant parts and we'll see where your at :)

But just to set you thinking:- (pseudo code)

$BoldText = "Bold";

if($BoldText == "Bold"){
echo "<b>This is bolded text</b>";
echo "<br>";
echo "<div style="font-weight: bold;">This is bolded text</div>";
exit;
}
else{
echo "<i>This isn't bolded text it's italic!</i>";
echo "<br>";
echo "<div style="text-decoration: underline;">This is underlined text</div>";
exit;
}

Hope that you get the gist anyway.

[EDIT:] @ IntegrityWebDev it's tired and I'm late, probably is deprecated, t'was the thought that counted :)

You made me wonder: Here is what I found [w3schools.com] if that's wrong please tell me :)

Cheers,
MRb

[edited by: Matthew1980 at 7:07 pm (utc) on Mar 29, 2011]

IntegrityWebDev




msg:4289164
 6:45 pm on Mar 29, 2011 (gmt 0)

Except you probably want to use <strong> and not <b> as <b> is depreciated if I remember correctly. :-)

biru32




msg:4289217
 7:52 pm on Mar 29, 2011 (gmt 0)

Hi! and thanks for the superfast response!

Here is my php code. I hope it's not too long...500 lines.




<?php



class GridView extends GridBuilder{

function beforeQuery() {
//for frontent rows per page selection
$this->queryStart = $this->page*$this->rpp; //for frontent rows per page selection
$this->queryLimit = $this->rpp;
}

function build() {

$conf_edit = "0";
$conf_headers = "1";

$field;
$input;

$grid_url = $_SERVER['PHP_SELF']."?option=com_grid&gid=".$this->_ID;
$grid_url2 = $_SERVER['PHP_SELF']."?option=com_grid";

$images_url = JURI::base().'components/com_grid/images/';

$input['get_action'] = "";
$input['post_action'] = "";
if (isset($_GET["a"])) {
$input['get_action'] = $_GET["a"];
}
if (isset($_POST["a"])) {
$input['post_action'] = $_POST["a"];
}
if ("$input[get_action]"=="") {
$input['get_action'] = $input['post_action'];
}
$field['get_action'] = mysql_escape_string($input['get_action']);
$field['post_action'] = mysql_escape_string($input['post_action']);

$this->_config->hColor = "#".$this->_config->hColor;
$this->_config->sColor = "#".$this->_config->sColor;
$row_colora1 = $this->_config->rColor1;
$this->_config->rColor1 = "#".$this->_config->rColor1;
$row_colora2 = $this->_config->rColor2;
$this->_config->rColor2 = "#".$this->_config->rColor2;
$row_colora_selected = $this->_config->row_color_selected;
$this->_config->PBColor = "#".$this->_config->PBColor;

$conf_edit = explode("|",$conf_edit);

$field['search_menu'] = "";

$field['search_menu'] .= "<option value=\"0\"";

if ("$this->searchField"=="0") {

$field['search_menu'] .= " selected";

}

$field['search_menu'] .= ">All Fields";


$field['output_script'] = "<form action=\"$grid_url2\" method=\"GET\" name=\"form\" style=\"margin:0px\">
<input type=\"hidden\" id=\"img_url\" value=\"".$images_url."\">
<input type=\"hidden\" name=\"gid\" value=\"".$this->_ID."\">
<table width=\"100%\" border=0 cellpadding=4 cellspacing=0>
";

$column_captions = explode("|",$this->_config->columnCaptions);
$conf_columns = $this->_config->columnNames;
$conf_columns_count = count($column_captions);
$conf_order = $this->_config->default_order;
$links = @explode('|',$this->_config->link);
$linkTypes=Array();
$linkCols=Array();


if ("$conf_headers"=="1") {


$field['output_script'] .= "<tr>";

//line numbers
if($this->_config->lineNr){
$field['output_script'] .="<td style=\"width:10px;background-color:".$this->_config->hColor.";\">#</td>";
}

if ("$conf_edit[0]"=="1") {

if ("$conf_edit"=="2") {

$field['output_script'] .= "<td style=\"background-color:".$this->_config->hColor."\"><input type=\"checkbox\" name=\"CheckAll\" value=\"\" onClick=\"checkAll(document.form.data_input,this)\"></td>
";

} else {

$field['output_script'] .= "<td style=\"background-color:".$this->_config->hColor."\"><span class=\"field\">&nbsp;</span></td>
";

}
}
}

for ($i = 0; $i < $conf_columns_count; $i++) {

$linkTypes[$i]=substr($links[$i],0,1);
$linkCols[$i]= substr($links[$i],2);

$field['search_menu'] .= "<option value=\"$conf_columns[$i]\"";

if ("$this->searchField"=="$conf_columns[$i]") {

$field['search_menu'] .= " selected";

}

$field['search_menu'] .= ">".$column_captions[$i]; //ucwords(str_replace("_"," ",$conf_columns[$i]));

$field['order_direction'] = "DESC";

if ("$this->orderBy"=="$conf_columns[$i]") {

if ("$this->direction"=="ASC") {

$field['order_direction'] = "DESC";

} else {

$field['order_direction'] = "ASC";

}

}

if ("$conf_headers"=="1") {

if ("$this->orderBy"=="$conf_columns[$i]") {

$field['order_bgcolor'] = $this->_config->sColor;

} else {

$field['order_bgcolor'] = $this->_config->hColor;

}


$field['output_script'] .= "<td nowrap style=\"background-color:$field[order_bgcolor]\"";
if($this->_config->columnWidth[$i]!=0) $field['output_script'] .= " width=\"".$this->_config->columnWidth[$i]."\" ";
$field['output_script'] .= " ><span class=\"field\">&nbsp;<b><a href=\"javascript:;\" onclick=\"SimpleAJAXCall('$grid_url&o_b=$conf_columns[$i]&o_d=$field[order_direction]&p=$this->page&s_f=$this->searchField&data_search=$this->searchStr&rpp=$this->rpp&ajax=1',SimpleAJAXCallback, '', 'data_listings$this->_ID');\" class=\"field\">";
if($column_captions[$i]=="")$field['output_script'] .= ucwords(str_replace("_"," ",$conf_columns[$i]));
else $field['output_script'] .= $column_captions[$i];

$field['output_script'] .= "</a></b>";


if ("$this->orderBy"=="$conf_columns[$i]") {
if ("$this->direction"=="ASC") {
$field['output_script'] .= "&nbsp;<img src=\"".$images_url."asc.gif\" style=\"border:none;margin:0px;\">";

} else {
$field['output_script'] .= "&nbsp;<img src=\"".$images_url."dsc.gif\" style=\"border:none;margin:0px;\">";

}
}

else{
$field['output_script'] .= "&nbsp;<img src=\"".$images_url."x.gif\" style=\"border:none;margin:0px;\">";
}

$field['output_script'] .= "</span></td>
";

}

}

if ("$conf_headers"=="1") {

if ("$conf_edit[0]"=="2") {

if ("$conf_edit[1]"=="2") {
$field['output_script'] .= "<td style=\"background-color:".$this->_config->hColor."\" align=right><input type=\"checkbox\" name=\"CheckAll\" value=\"\" onClick=\"checkAll(document.form.data_input,this)\"></td>
";

} else {

$field['output_script'] .= "<td style=\"background-color:".$this->_config->hColor."\"><span class=\"field\">&nbsp;</span></td>
";

}
}

$field['output_script'] .= "</tr>
";

}


///////////////////////////////////////////////



///////////////////////////////////////////////////////////

$field['total_pages'] = ceil($this->rows/$this->rpp);
$field['total_pages'] = round($field['total_pages']);


##### HEADER AND SEARCH MENU LAYOUT #####

$title = "<table cellpadding=0 cellspacing=0 border=0><tr><td valign=\"bottom\" style=\"border:none;\"><a name=\"$this->_ID\"></a>";
if($this->_config->showTitle)$title.="<span class=\"grid_title \">".$this->_config->tableCaption."</span>";
$title.="</td><td style=\"border:none;\"><div style=\"width:25px; height:25px;\" id=\"data_listings$this->_ID-showimg\"></div></td></tr>";
$title.="<tr><td style=\"border:none;\" colspan=\"2\">";

$title.=JXHelper::searchForm($this->_config, $this, $field[search_menu], $grid_url);

if($this->_config->nrRecords){
$title.="(".$this->rows." Records)";
}

$title.= "</td></tr></table>";



$field[output_script]=$title.$field[output_script];

if (!isset($field['row_color'])) {
$field['row_color'] = "";
}


///////////////////////////////////DiISPLAYING ROW BY ROW////////////////////////////////////////////////////////////////////



$nr;
for ($i = 0; $i < $this->queryRows; $i++) {

if ("$field[row_color]"==$this->_config->rColor2) {

$field['row_color'] = $this->_config->rColor1;
$field['row_colora'] = $row_colora1;
$nr=1;


} else {

$field['row_color'] = $this->_config->rColor2;
$field['row_colora'] = $row_colora2;
$nr=2;
}

$field['output_script'] .= "<tr class=\"jxrow$nr\" id=\"row".$this->_ID."_$i\" style=\"background-color:$field[row_color];\" onmouseover=\"checktoggle_over('row".$this->_ID."_$i','".$this->_config->rColorMO."');\" onmouseout=\"checktoggle('row".$this->_ID."_$i','$field[row_colora]',$nr);\">
";

if($this->_config->lineNr){
$lnr=$this->page*$this->rpp+$i+1;
$field['output_script'] .="<td style=\"width:10px;\" >".$lnr."</td>";
}


for ($j = 0; $j < $conf_columns_count; $j++) {

$colName=$conf_columns[$j];
$podatek=$this->_data[$i][$colName];
$linkType = $this->_config->link[2*$j];

$field['output_script'] .= "<td ";
if($this->_config->columnWidth[$j]!=0) $field['output_script'] .= " width=\"".$this->_config->columnWidth[$j]."\" ";
if($this->_config->lineHeight!=0) $field['output_script'] .= " height=\"".$this->_config->lineHeight."\" ";
$field['output_script'] .= "><span class=\"field\">&nbsp;";
if($linkType=='0'){
$field['output_script'] .= $podatek;
}
else{
$link=$this->_data[$i][$this->_config->link[2*$j+1]];
$field['output_script'] .=JXHelper::createLink($linkType,$link, $podatek);

}
$field['output_script'] .= "</span></td>";


}

$field['output_script'] .= "</tr>
";
}

if ("$this->rows"=="0") {

$conf_columns_count2 = $conf_columns_count;

if ("$conf_edit[0]"!="0") {

$conf_columns_count2 = $conf_columns_count + 1;

}

$field['output_script'] .= "<tr><td colspan=$conf_columns_count2 align=center><span class=\"field\">&nbsp;<br><b>No records found.</b><br>&nbsp;</span></td></tr>
";

}

$colspan=$conf_columns_count+$this->_config->lineNr;

if(($this->_config->searchF['submitFirst']==1 && "$this->isAjax"!="1")){
// display data only after search submit
$field['output_script'] .="<tr><td colspan=$colspan align=\"center\">Please enter a search phrase.</td></tr>";
}
/////////////////////////////// pagination ////////////////////////////////////////////////////////////////////////////////


if ($this->_config->paging) {

$field['output_script'] .="<tr><td colspan=$colspan>";

if ("$field[total_pages]"=="0") {

$field['total_pages'] = 1;

}

$field['output_script'] .= "
<table width=\"100%\" border=0 cellpadding=3 cellspacing=0 style=\"width:100%;margin-top: 0.5em ;\"><tr style=\"background-color:".$this->_config->PBColor."\"><td style=\"border:none;margin:0px;width: 9em ;\">";

$field['output_script'] .= "Page ".($this->page+1)." of $field[total_pages]";
$field['output_script'] .= "</td><td style=\"border:none;margin:0px;padding:0px;\" >";

if($this->rows > $this->rpp){

$field['output_script'] .="<table border=0 cellpadding=0 cellspacing=0 style=\"border:none;margin:0px;padding:0px;\">
<tr style=\"border:none;margin:0px;padding:0px;\">";

if ($this->page>0) {

$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px;\">
<a href=\"javascript:;\" onclick=\"SimpleAJAXCall('$grid_url&o_b=$this->orderBy&s_f=$this->searchField&data_search=$this->searchStr&o_d=$this->direction&p=0&rpp=$this->rpp&ajax=1',SimpleAJAXCallback, '', 'data_listings$this->_ID');\">
&lt;&lt;First</a></td>
";
$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px 0px 0px 3px;\">
<a href=\"javascript:;\" onclick=\"SimpleAJAXCall('$grid_url&o_b=$this->orderBy&o_d=$this->direction&s_f=$this->searchField&data_search=$this->searchStr&p=".($this->page-1)."&rpp=$this->rpp&ajax=1',SimpleAJAXCallback, '', 'data_listings$this->_ID');\" >
&lt;Prev</a></td>
";

}
else{
$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px;\"><span class=\"pageButtonsDisabled\">
&lt;&lt;First</span></td>
";
$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px 0px 0px 3px;\"><span class=\"pageButtonsDisabled\">
&lt;Prev</span></td>
";
}

if ($this->_config->nrPages > 0){

$start;
$half = ceil($this->_config->nrPages/2);

if($this->page + 1 < $half || $this->_config->nrPages >= $field['total_pages']){
$start=0;
}
elseif($this->page+1 >= $half && $this->page+1 <= ($field['total_pages']-$half)){
$start = $this->page-$half+1;
}else{
$start = $field['total_pages']-$this->_config->nrPages;
}



$k = 0;

for ($i = $start; $i<$field['total_pages']; $i++) {
$k++;

if (($i)==$this->page) {

$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px;width: 1.5em ;text-align:center;padding:0px 1px 0px 1px;\">";
$field['output_script'] .= "<a href=\"javascript:;\" onclick=\"SimpleAJAXCall('$grid_url&o_b=$this->orderBy&s_f=$this->searchField&data_search=$this->searchStr&o_d=$this->direction&p=".($i)."&rpp=$this->rpp&ajax=1',SimpleAJAXCallback, '', 'data_listings$this->_ID');\" class=\"currentPageNum\" >";
$field['output_script'] .= "<b>".($i+1)."</b>";
$field['output_script'] .= "</a></td>";


} else {

$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px;width: 1.5em ;text-align:center;padding:0px 1px 0px 1px;\">
<a href=\"javascript:;\" onclick=\"SimpleAJAXCall('$grid_url&o_b=$this->orderBy&s_f=$this->searchField&data_search=$this->searchStr&o_d=$this->direction&p=".($i)."&rpp=$this->rpp&ajax=1',SimpleAJAXCallback, '', 'data_listings$this->_ID');\" class=\"pageNum\" >";
$field['output_script'] .= ($i+1);
$field['output_script'] .= "</a></td>";
}


if($k >= $this->_config->nrPages) break;
}

}
else $field['output_script'] .= '<td style="border:none;width: 1em ;"> </td>';

if (($this->page+1)<$field['total_pages']) {

$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px;\">
<a href=\"javascript:;\" onclick=\"SimpleAJAXCall('$grid_url&o_b=$this->orderBy&o_d=$this->direction&s_f=$this->searchField&data_search=$this->searchStr&p=".($this->page+1)."&rpp=$this->rpp&ajax=1',SimpleAJAXCallback, '', 'data_listings$this->_ID');\" >Next&gt;</a>
</td>";
$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px 0px 0px 3px;\">
<a href=\"javascript:;\" onclick=\"SimpleAJAXCall('$grid_url&o_b=$this->orderBy&s_f=$this->searchField&data_search=$this->searchStr&o_d=$this->direction&p=".($field['total_pages']-1)."&rpp=$this->rpp&ajax=1',SimpleAJAXCallback, '', 'data_listings$this->_ID');\" >
Last&gt;&gt;</a></td>
";

}
else{
$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px;\">
<span class=\"pageButtonsDisabled\">Next&gt;</span>
</td>";
$field['output_script'] .= "<td style=\"border:none;margin:0px;padding:0px 0px 0px 3px;\">
<span class=\"pageButtonsDisabled\">
Last&gt;&gt;</span></td>
";
}
$field['output_script'] .="</tr></table>";
}


$field['output_script'] .= "</td></tr></table></td></tr>
";

}


$field['output_script'] .= "</table></form>
";
if($this->_config->showtime){
$time= (microtime(true)-$this->starttime)*1000;
$pointpos=strpos($time,'.');
if ($pointpos >= 3)
$field['output_script'] .= "<div>Query took ".substr($time,0,$pointpos+1)." miliseconds.</div>";
else
$field['output_script'] .= "<div>Query took ".substr($time,0,4)." miliseconds.</div>";
}
if($this->_config->poweredBy){
$field['output_script'] .= "<div style=\"font-size:6px;float:right;\">Powered by <a href=\"http://www.toolsjx.com/\">Tools JX</a></div>";
}

$output = '<div id="data_listings'.$this->_ID.'">'.$field[output_script].'</div>
<noscript>For proper performance enable JavaScript. Pages:';
$output .="&nbsp;<a href=\"$grid_url&p=0\">1</a>";
for($i=1; $i<$field['total_pages']; $i++){
$output .=",&nbsp;<a href=\"$grid_url&p=$i\">".(1+$i)."</a>";
}
$output .='<br>Powered by <a href=\"http://www.toolsjx.com/\">Tools JX</a>.</noscript>';


if ("$this->isAjax"=="1") {
header("Content-Type: text/css; charset=utf-8");
echo $field['output_script'];
exit;

}

return $output;

}

function createLink($type, $link, $datum){
$output="";
switch($type){
case '0':{
$output = $datum;
}break;
case '1':{
$output = '<a href="'.$link.'">'.$datum.'</a>';
}break;
case '2':{
$output = '<a href="?option=com_content&view=article&id='.$link.'">'.$datum.'</a>';
}break;
default:{
$link = str_replace('@ID', $link, $type);
$output = '<a href="'.$link.'">'.$datum.'</a>';
}
}
return $output;
}

function searchForm($grid_url, $search_menu, $data_search){
$search_form = '<form action="javascript:;" name="asearch_form" onsubmit="searchjx(\''.$grid_url.'\', \''.$this->_ID.'\')" style="margin:0px;">
<span class="searchForm">';
if($this->_config->searchF){
$search_form .='Search: <select id="sf'.$this->_ID.'" name="s_f" class="input searchField">'.$search_menu.'</select> <input id="ds'.$this->_ID.'" type="text" name="data_search" size=20 value="'.$data_search.'" class="input searchData">
<input type="submit" name="submit" value="Search" class="input searchSubmit">';
}
if($this->_config->nrRecSelect){
$search_form.='&nbsp;&nbsp;Records per Page:
<select id="rpp'.$this->_ID.'" name="rpp" onchange="searchjx(\''.$grid_url.'\', \''.$this->_ID.'\')" style="margin:0px;">
<option value="'.$this->_config->nrRows.'">&nbsp;</option>
<option value="5" '; if($this->rpp == 5)$search_form .='selected'; $search_form .='>5</option>
<option value="10" '; if($this->rpp == 10)$search_form .='selected'; $search_form .='>10</option>
<option value="20" '; if($this->rpp == 20)$search_form .='selected'; $search_form .='>20</option>
<option value="30" '; if($this->rpp == 30)$search_form .='selected'; $search_form .='>30</option>
<option value="50" '; if($this->rpp == 50)$search_form .='selected'; $search_form .='>50</option>
<option value="70" '; if($this->rpp == 70)$search_form .='selected'; $search_form .='>70</option>
<option value="100" '; if($this->rpp == 100)$search_form .='selected'; $search_form .='>100</option>
</select>';
}
$search_form.= '</span></form>';
return $search_form;
}

}

[1][edited by: biru32 at 7:54 pm (utc) on Mar 29, 2011]

biru32




msg:4289219
 7:54 pm on Mar 29, 2011 (gmt 0)

Oh, and here is the actual table if you would like to have a look:

[offnrunningsports.com...]

rocknbil




msg:4289329
 1:29 am on Mar 30, 2011 (gmt 0)

Bold and strong are visually the same, it's an endless argument, however, I prefer strong because of it's semantic meaning. I don't think it's deprecated.

That is too big of a code dump. You can do something like this. Get the value of your field and do

$boldstart = ($row['onr_sponsored'] == "YES")?'<strong>':null;
$boldend = ($row['onr_sponsored'] == "YES")?'</strong>':null;

Then add $boldstart and $boldend for **every** output.

$output .= $boldstart . $yourtext . $boldend;

TheMadScientist




msg:4289387
 6:22 am on Mar 30, 2011 (gmt 0)

I love semantic arguments ... I believe <b> will be deprecated when HTML5 (which may simply be HTML) becomes the recommendation, but to date, I'm fairly certain html5 is not the w3c recommendation since HTML5 is technically still in dev while the semantics are argued, so technically, afaik bold (<b>) tags are not deprecated, and even when they are, since HTML gets updated once in a decade or three (slight exaggeration) and backward compatibility is a must for browsers, imo you can safely use either until 2020, give or take a few years ... And, of course, when they are deprecated, the technically, semantically correct replacement is actually <span style="font-weight:bold">, not <strong>.

IntegrityWebDev




msg:4289470
 12:45 pm on Mar 30, 2011 (gmt 0)

My bad, it was my understanding <b> was depreciated. I stand happily corrected. :-)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved