473,468 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

question about embeded PHP

51 New Member
Hi, all

I tried to set a default value on a 'select' object. Anyway, it seems the 'if' always return false. No one option is selected as I traced it. And I'm pretty sure there should be one value equals to the terms. Please help!

[PHP]<tr>
<td>Terms:</td>
<td><SELECT style="width:100%" id="terms">
<?php foreach($tes_terms as $desc => $val):?>
<?php if($terms == $val):?>
<?php $_my_selected = 'selected';?>
<?php else:?>
<?php $_my_selected = '';?>
<?php endif;?>
<?php echo "<option value='$val' $_my_selected> $desc</option>";?>
<?php endforeach;?>
</SELECT></td>
<td class="err_red"></td> [/PHP]


jack
Oct 23 '08 #1
3 1093
Atli
5,058 Recognized Expert Expert
Hi Jack.

What is the value of $terms? I don't see you set it anywhere.

Also, if I may make a suggestion:
[PHP]<tr>
<td>Terms:</td>
<td><SELECT style="width:100%" id="terms">
<?php
foreach($tes_terms as $desc => $val) {
$_my_selected = ($terms == $val ? 'selected' : '');
echo "<option value='$val' $_my_selected> $desc</option>";
}
?>
</SELECT></td>
<td class="err_red"></td> [/PHP]
It's exactly like your code, except without all the opening and closing <?php ?> tags and I replaced the if statement with a so called "ternary conditional operator" (read about that here)
That is; a: "bool ? true : false" statement, where the "bool" is an expression, and if it is evaluated as true, the "true" part is executed. Otherwise the "false" part is executed.

Much easier to read, don't you agree?
Oct 23 '08 #2
datactrl
51 New Member
I changed like the following. The problem is the same. It created Z="" as an attribute for all options.

$tes_terms is an array ('a'=>'1', 'b'=>2, 'c'=>3)
terms's value is 2
I use CI framework. so following is used to send it out
$this->parser->parse('my_view', $ar);
$ar, associative array, contains $tes_terms and terms

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.     <td>Terms:</td>
  3.     <td><SELECT style="width:100%" id="terms">
  4.     <?php foreach($tes_terms as $desc => $val):?>
  5.         <?php $_my_selected = ($terms == $val? 'selected': 'Z');?>
  6.         <?php echo "<option value='$val' $_my_selected >$desc</option>";?>
  7.     <?php endforeach;?>
  8.     </SELECT></td>
  9.     <td class="err_red"></td>
  10. </tr>
Oct 24 '08 #3
datactrl
51 New Member
HI, Atli

Ok, I found the problem where is the value of $terms is followed by a CR I didn't realize before. Anyway thank you for your advice which is much easier to code and read.

Jack
Oct 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jens Thiede | last post by:
I want to use python heavily on my embeded linux. What would the best way be to slim down Python. Only keep those modules you would acctually need, and not imparing Python's capabilities? ...
7
by: John Ortt | last post by:
Hi there, I am trying to do a two level embeded query but it is causing Dr Watson errors. The line which is causing the problem is: CFCDeci: (Select sum (FlexChangeDeci) FROM as WHERE (....
3
by: Viorel Ghilas | last post by:
Hi all, I have an assembly, that contain some embeded resources, How can I add in runtime, data to my embeded resources. is it posible with best regard Viorel Ghilas
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
6
by: Dominique | last post by:
Hi all, I'm using .NET v1.1 and the scenario I have is as follows... I have IE as an ActiveX control embedded in may C# App. I generate a HTML file dynamically and within the HTML file I embed a...
11
by: A.M-SG | last post by:
Hi, I understand that be default VS2005 uses the ASP.NET development server to run and test ASP.NET applications. Is it possible that we use IIS for ASP.NET application debugging in new IDE...
2
by: DotNetDev | last post by:
Hi I have a control (child2.ascx). Which I place in a repeater in another controls (child1.ascx). Child2.ascx is again placed in a repeater on a Page(Page1.aspx). What will be a good way to...
4
by: EmeraldShield | last post by:
(Dot Net 2 C# application - using Encoding.UTF8 with a StreamReader) I have a very strange problem that I cannot explain with a UTF8 Readline() although this could exist in other types of encoding,...
4
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Just wondering if someone can help me out. I'm building a web app that uses UserControls for different forms etc. I have a few UserControls that are embeded and I want to be able to call/pass data...
0
by: Pitaridis Aristotelis | last post by:
I know how to extract an embeded resource from a file but does anyone how to import an embeded resource to a file?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.