How cotrol Font size and color?

I have a line of code that places the word “New” in a form

<? } else if ($item_details[‘item_condition’]==1) { ?>New

it works…but!

I would like to be able to control the Font size and color of the word “New”

how do I code it?

all help appreciated :slight_smile:

More info, the complete code is:

<tr class=“c1”>
<td><b>Item Condition</b></td>
<td>
<? if ($item_details[‘item_condition’]==0) { ?>See description
<? } else if ($item_details[‘item_condition’]==1) { ?>New
<? } else if ($item_details[‘item_condition’]==2) { ?>Used
<? } else if ($item_details[‘item_condition’]==3) { ?>Good
<? } else if ($item_details[‘item_condition’]==4) { ?>Fair
<? } else if ($item_details[‘item_condition’]==5) { ?>Poor
<? } else if ($item_details[‘item_condition’]==6) { ?>Defective<? } ?></td>
</tr>

I would like to add a color and Font size: for example: font color="#FF0000

How add the code?

Hi,

I don’t do php but I assume you could output a span with a class around the word new and then target it with css.


<span class="highlight">New</span>


.highlight{color:#f00}

Hello Paul

thank you for your reply/idea

Am I in the wrong Forum!? I will move to the php forum.

yet I will try your idea also :slight_smile:

best wishes :slight_smile:

Moved to PHP forum :slight_smile:

More info, the complete code is:

<tr class=“c1”>
<td><b>Item Condition</b></td>
<td>
<? if ($item_details[‘item_condition’]==0) { ?>See description
<? } else if ($item_details[‘item_condition’]==1) { ?>New
<? } else if ($item_details[‘item_condition’]==2) { ?>Used
<? } else if ($item_details[‘item_condition’]==3) { ?>Good
<? } else if ($item_details[‘item_condition’]==4) { ?>Fair
<? } else if ($item_details[‘item_condition’]==5) { ?>Poor
<? } else if ($item_details[‘item_condition’]==6) { ?>Defective<? } ?></td>
</tr>

I would like to add a color and Font size: for example: font color="#FF0000

How add the code?

Can I wrap the New with a <b>New</b>

<b>New</b>

<b>Used</b>

I’m surprised no one from PHP has answered yet but I believe you can output html as per normal in your structure above (someone correct me if I’m wrong) so you should be able to add the extra tag and then target it through css. Try it and see :slight_smile:

Hello Paul, thank you for your reply, and idea.

could you give me more details on “add the extra tag and then target it through css”

:slight_smile:

Hi,


<tr class="c1">
<td><b>Item Condition</b></td>
<td clas[B]s="test">[/B]
<? if ($item_details['item_condition']==0) { ?>See description
<? } else if ($item_details['item_condition']==1) { ?>[B]<b>New</b>[/B]
<? } else if ($item_details['item_condition']==2) { ?>Used
<? } else if ($item_details['item_condition']==3) { ?>Good
<? } else if ($item_details['item_condition']==4) { ?>Fair
<? } else if ($item_details['item_condition']==5) { ?>Poor
<? } else if ($item_details['item_condition']==6) { ?>Defective<? } ?></td>
</tr>


.td.test b{color:red}

Or if you have more than one b element add a class.


<tr class="c1">
<td><b>Item Condition</b></td>
<td>
<? if ($item_details['item_condition']==0) { ?>See description
<? } else if ($item_details['item_condition']==1) { ?>[B]<b class="highlight">New</b>[/B]
<? } else if ($item_details['item_condition']==2) { ?>Used
<? } else if ($item_details['item_condition']==3) { ?>Good
<? } else if ($item_details['item_condition']==4) { ?>Fair
<? } else if ($item_details['item_condition']==5) { ?>Poor
<? } else if ($item_details['item_condition']==6) { ?>Defective<? } ?></td>
</tr>


.highlight{color:red}

This is a perfect example of something that needs help both in terms of PHP and in terms of it’s markup…

On the markup side, that bold inside the TD probably shouldn’t be a TD/B, but a TH – see, there are other tags that go inside tables besides TR and TD, often helps to use them.

If you store your result in a variable, you could use it for both the text AND the class. (just str_replace spaces with underscores).

The endless if/else/if/else is also poor code, since if you’re checking the SAME variable on all of them, you should be using a CASE statement…


	switch ($item_details['item_condition'])==0) {
		case 0:
			$text='See description';
		break;
		case 1:
			$text='New';
		break;
		case 2:
			$text='Used';
		break;
		case 3:
			$text='Good';
		break;
		case 4:
			$text='Fair';
		break;
		case 5:
			$text='Poor';
		break;
		case 6:
			$text='Defective';
		break;
	}

Though a simpler approach would be to use an array lookup, especially if you make this check more than once on the page.


	$conditionList=new Array(
		'See Description','New','Used','Good','Fair','Poor','Defective'
	);
	$text=$conditionList[$item_details['item_condition']];

There is NO reason I can see to be WASTING an extra tag around the text, put the class on the TD…

Also, I’d have to see the rest of the page, but I would suspect your C1 class (which is uselessly vague) probably isn’t needed either…

So, fixing the rest of that, we come up with:


<?php
	$conditionList=new Array(
		'See Description','New','Used','Good','Fair','Poor','Defective'
	);
	$text=$conditionList[$item_details['item_condition']];
	echo '
		<tr>
			<th scope="row">Item Condition</th>
			<td class="condition_',str_replace(' ','_',$text),'">
				',$text,'
			</td>
		</tr>';
?>

'See Description" would have the class ‘condition_See_Description’, ‘New’ would have the class ‘condition_New’, etc, etc…

So if you wanted say… “See Description” to be red, and ‘new’ to be bold the CSS:


.condition_See_Description {
	color:red;
}

.condition_New {
	font-weight:bold;
}

Much simpler, ja? 99% of the time if you are doing <? ?> on EVERY line, you’re probably doing it wrong making your code slow, hard to follow, and on the whole needlessly compex – same goes for running an if statement over and over again on the same variable… On the HTML side, if you’re going to format it as tabular data, use ALL the tags and attributes that are supposed to go into a table, not just TR and TD. TH (table heading) with SCOPE (to say which direction the heading applies), CAPTION to say what the table is about, THEAD if it has a heading (which should typically be filled with TH SCOPE=“col”), etc, etc…

Though – on the database (or form) side of things I’d probably be storing that as the text value, not the number; uses a bit more disk space and sql overhead, but would be more clear what you are getting back for a result and would simplify the amount of work PHP has to do on it. Old rule, if it comes down to more work for SQL or more work for userland PHP code, choose to make SQL do the work every time.

Hello Paul O’B & deathshadow60,

thank you, thank you :slight_smile:

you have both given me lots of great info to try/work with.

The code I was using came from a Modification code that I found, to add “Item Condition” to my Buy-Sell script,

Below I have pasted the complete code, it works, yet lacks any customizing for Font size,color etc.

Thanks to you both I can now add that customizing :slight_smile:

===============================================================================

IN FILE: templates/sell_item_detail.tpl.php -find

===============================================================================


<tr class="c1">
      <td width="150" align="right"><?=MSG_ITEM_DESCRIPTION;?></td>
      <td><textarea id="description_main" name="description_main" style="width: 400px; height: 200px; overflow: hidden;"><?=$item_details['description'];?></textarea>
       <?=$item_description_editor;?>
      </td>
   </tr>
   <tr class="reguser">
      <td></td>
      <td><?=MSG_ITEM_DESC_EXPL;?></td>
   </tr> 


================================================================================

under it place this code:

================================================================================

<tr class="c1">
<td width="150" align="right">Item Condition:</td>
<td> <SELECT NAME="item_condition">
<OPTION VALUE="0" SELECTED>See description</OPTION>
<OPTION VALUE="1" <? echo ($item_details['item_condition']==1) ? 'selected' : ''; ?>>New</OPTION>
<OPTION VALUE="2" <? echo ($item_details['item_condition']==2) ? 'selected' : ''; ?>>Used</OPTION>
<OPTION VALUE="3" <? echo ($item_details['item_condition']==3) ? 'selected' : ''; ?>>Good</OPTION>
<OPTION VALUE="4" <? echo ($item_details['item_condition']==4) ? 'selected' : ''; ?>>Fair</OPTION>
<OPTION VALUE="5" <? echo ($item_details['item_condition']==5) ? 'selected' : ''; ?>>Poor</OPTION>
<OPTION VALUE="6" <? echo ($item_details['item_condition']==6) ? 'selected' : ''; ?>>Defective</OPTION>
</SELECT></td>
</tr> 

==============================================================================================================

IN FILE: templates/sell_item.tpl.php -find

===================================================================================

<input type="hidden" name="description" value="<?=$item_details['description'];?>" > 


==========================================================================================

under it place this code

===========================================================================================


<input type="hidden" name="item_condition" value="<?=$item_details['item_condition'];?>" >


===================================================================================

IN FILE: includes/class_item.php -find


==================================================================================

creation_in_progress='" . $item_details['creation_in_progress'] . "', state='" . $item_details['state'] . "', 

   is_draft='" . $is_draft . "'

   WHERE auction_id='" . $item_details['auction_id'] . "' AND owner_id='" . $owner_id . "'");  

===============================================================================================================

replace with this code

=========================================================================================================================

creation_in_progress='" . $item_details['creation_in_progress'] . "', state='" . $item_details['state'] . "', 

   is_draft='" . $is_draft . "', item_condition='" . $item_details['item_condition'] . "'

   WHERE auction_id='" . $item_details['auction_id'] . "' AND owner_id='" . $owner_id . "'");  


=======================================================================================================================================

find:

===============================================================================================================


if ($relist_option == 1)
   {
    $sql_relist_auction = $this->query("INSERT INTO " . DB_PREFIX . "auctions
     (name, description, quantity, auction_type, start_price, reserve_price, buyout_price, bid_increment_amount,
     country, zip_code, shipping_method, shipping_int, payment_methods, category_id, owner_id, hpfeat, catfeat,
     bold, hl, hidden_bidding, currency, postage_amount, insurance_amount, type_service, enable_swap,
     addl_category_id, shipping_details, hpfeat_desc, list_in, direct_payment, apply_tax, auto_relist_bids,
     approved, listing_type, is_offer, offer_min, offer_max, auto_relist_nb, state)
     SELECT
     name, description, quantity, auction_type, start_price, reserve_price, buyout_price, bid_increment_amount,
     country, zip_code, shipping_method, shipping_int, payment_methods, category_id, owner_id, hpfeat, catfeat,
     bold, hl, hidden_bidding, currency, postage_amount, insurance_amount, type_service, enable_swap,
     addl_category_id, shipping_details, hpfeat_desc, list_in, direct_payment, apply_tax, auto_relist_bids,
     approved, listing_type, is_offer, offer_min, offer_max, auto_relist_nb, state
     FROM " . DB_PREFIX . "auctions WHERE auction_id=" . $auction_id . " AND owner_id=" . $user_id);  


=======================================================================================================================================

replace with this code:


=========================================================================================================================================



if ($relist_option == 1)
   {
    $sql_relist_auction = $this->query("INSERT INTO " . DB_PREFIX . "auctions
     (name, description, quantity, auction_type, start_price, reserve_price, buyout_price, bid_increment_amount,
     country, zip_code, shipping_method, shipping_int, payment_methods, category_id, owner_id, hpfeat, catfeat,
     bold, hl, hidden_bidding, currency, postage_amount, insurance_amount, type_service, enable_swap,
     addl_category_id, shipping_details, hpfeat_desc, list_in, direct_payment, apply_tax, auto_relist_bids,
     approved, listing_type, is_offer, offer_min, offer_max, auto_relist_nb, state, item_condition)
     SELECT
     name, description, quantity, auction_type, start_price, reserve_price, buyout_price, bid_increment_amount,
     country, zip_code, shipping_method, shipping_int, payment_methods, category_id, owner_id, hpfeat, catfeat,
     bold, hl, hidden_bidding, currency, postage_amount, insurance_amount, type_service, enable_swap,
     addl_category_id, shipping_details, hpfeat_desc, list_in, direct_payment, apply_tax, auto_relist_bids,
     approved, listing_type, is_offer, offer_min, offer_max, auto_relist_nb, state, item_condition
     FROM " . DB_PREFIX . "auctions WHERE auction_id=" . $auction_id . " AND owner_id=" . $user_id);  


===============================================================================================================

find:

===============================================================================================================

$sql_insert_item = $this->query("UPDATE " . DB_PREFIX . "wanted_ads SET
	name='" . $word_filter['name'] . "', description='" . $word_filter['description'] . "',
	duration='" . $item_details['duration'] . "', country='" . $item_details['country'] . "',
        zip_code='" . $item_details['zip_code'] . "', category_id='" . $item_details['category_id'] . "',
	owner_id='" . $owner_id . "', addl_category_id='" . $item_details['addl_category_id'] . "',
	end_time='" . $end_time . "', start_time='" . $start_time . "',
	creation_in_progress='0', state='" . $item_details['state'] . "'
	WHERE wanted_ad_id='" . $item_details['wanted_ad_id'] . "' AND owner_id='" . $owner_id . "'");


===============================================================================================================

Replace with:

===============================================================================================================


$sql_insert_item = $this->query("UPDATE " . DB_PREFIX . "wanted_ads SET
	name='" . $word_filter['name'] . "', description='" . $word_filter['description'] . "',
	duration='" . $item_details['duration'] . "', country='" . $item_details['country'] . "',
        zip_code='" . $item_details['zip_code'] . "', category_id='" . $item_details['category_id'] . "',
	owner_id='" . $owner_id . "', addl_category_id='" . $item_details['addl_category_id'] . "',
	end_time='" . $end_time . "', start_time='" . $start_time . "',
        item_condition='" . $item_details['item_condition'] . "',
	creation_in_progress='0', state='" . $item_details['state'] . "'
	WHERE wanted_ad_id='" . $item_details['wanted_ad_id'] . "' AND owner_id='" . $owner_id . "'");




====================================================================================================================


IN FILE: Themes/your theme/templates/auction_details.tpl.php -find

=========================================================================================================================


<? if ($item_details['quantity']) { ?>
            <tr class="c1">
               <td><b><?=GMSG_QUANTITY;?></b></td>
               <td><?=$item_details['quantity'];?></td>
            </tr>
            <? } ?> 



============================================================================================================

under it place this code

======================================================================================================================================



<tr class="c1">
               <td><b>Item Condition</b></td>
               <td>
            <? if ($item_details['item_condition']==0) { ?>See description
            <? } else if ($item_details['item_condition']==1) { ?>New
            <? } else if ($item_details['item_condition']==2) { ?>Used
            <? } else if ($item_details['item_condition']==3) { ?>Good
            <? } else if ($item_details['item_condition']==4) { ?>Fair
            <? } else if ($item_details['item_condition']==5) { ?>Poor
            <? } else if ($item_details['item_condition']==6) { ?>Defective<? } ?></td>
            </tr> 


====================================================================================================================

Thank Jason he showed the right way to do it :slight_smile:

Are Jason & deathshadow60 the same person ?

Sorry, I keep calling people by their real name - Yes they are one and the same :slight_smile:

Ok good to hear that :slight_smile:

I have not had time to implement any of the suggested code yet,

I will reply again once that is done :slight_smile: