Solved

Why does this not work and what do I need to do differently?

Posted on 2014-02-25
6
216 Views
Last Modified: 2014-02-26
Here's my form:

 <tr>
                    <td width='25' align='center' $rclass><input type='Checkbox' name='assignCapX".$i."' value='".$capxlist[$i]["capxid"]. "'></td>
                    <td width='".($leftcol-25-100)."' $rclass><a class='tip_trigger' href=''><span class='text'>".$capxlist[$i]["description"].' '.$capxlist[$i]['capxid']."</span><span class='tip'>
                     <table width='200'><tr><td class='text'>".$capxlist[$i]["shortname"]."</td></tr></table></span></a></td>
                    <td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
                    <td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
                   <input type='hidden' name='shortname' value='".$capxlist[$i]["shortname"]."'>
                    <input type='hidden' name='description' value='".$capxlist[$i]["description"]."'>
                    <input type='hidden' name='totalcost' value='".$capxlist[$i]["totalcost"]."'>
                    <input type='hidden' name='assettypeid' value='".$capxlist[$i]["assettypeid"]."'>
                    <input type='hidden' name='spmodelid' value='".$capxlist[$i]["spmodelid"]."'>
                    <input type='hidden' name='capxid' value='".$capxlist[$i]["capxid"]."'></td>
                </tr>";

Open in new window


The checkbox is "checked" on the other end with this:

for ($i=1; $i<=$capx_assign; $i++) {
    eval("if (isset(\$assignCapX".$i."))
            \$tmp_set = yes;   
        else
            \$tmp_set = no;");
            echo $tmp_set;
           if ($tmp_set == "yes")
            {
            //$capx_temp_assign = cer_capxtempsave($ID, $mID, $capxid, $spmodelid, $assettypeid, $totalcost, cleanstring($description), cleanstring($shortname));
            }
    }   

Open in new window


When I view the way the code is being "seen" by the system, I'll get something like nononoyesnonoyes, but the same variables are being inserted every time. In other words, the same capxid, the same spmodelid. So while the $tmp_set value is being viewed correctly, the only variables that are being inserted are the ones belonging to the last record in the list.

What do I need to do differently to ensure that the right variables are being inserted, rather than the same ones? What am I missing?
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Assisted Solution

by:Dan Craciun
Dan Craciun earned 250 total points
ID: 39886289
Sorry, but I think some code is missing.
On the first snippet you don't have the loop where $i is incremented.
Can you post the full form with the loop?

Dan
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 125 total points
ID: 39886396
Why are you using eval?

for ($i=1; $i<=$capx_assign; $i++) {
	if (isset(${'assignCapX'.$i}))
            $tmp_set = 'yes';
        else
            $tmp_set = 'no';
	echo $tmp_set;
	if ($tmp_set == 'yes'){
		//$capx_temp_assign = cer_capxtempsave($ID, $mID, $capxid, $spmodelid, $assettypeid, $totalcost, cleanstring($description), cleanstring($shortname));
	}
}

Open in new window

0
 

Author Comment

by:brucegust
ID: 39886436
Here's the full form:

    for ($i=1;$i<=$capxlist["count"];$i++) {
                $rc_count++;
                $hlf = floor($rc_count/2);
                $dbl = $hlf*2;
                
                if ($rc_count != $dbl)
                    $rclass = " class=''";
                else
                    $rclass = " class='rcolor'";
                    if($capxcompare["count"]>0)
                    {
        continue;
                    }
                    else
                    {
                echo "
                <tr>
                    <td width='25' align='center' $rclass><input type='Checkbox' name='assignCapX".$i."' value='".$capxlist[$i]["capxid"]. "'></td>
                    <td width='".($leftcol-25-100)."' $rclass><a class='tip_trigger' href=''><span class='text'>".$capxlist[$i]["description"].' '.$capxlist[$i]['capxid']."</span><span class='tip'>
                     <table width='200'><tr><td class='text'>".$capxlist[$i]["shortname"]."</td></tr></table></span></a></td>
                    <td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
                    <td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
                   <input type='hidden' name='shortname' value='".$capxlist[$i]["shortname"]."'>
                    <input type='hidden' name='description' value='".$capxlist[$i]["description"]."'>
                    <input type='hidden' name='totalcost' value='".$capxlist[$i]["totalcost"]."'>
                    <input type='hidden' name='assettypeid' value='".$capxlist[$i]["assettypeid"]."'>
                    <input type='hidden' name='spmodelid' value='".$capxlist[$i]["spmodelid"]."'>
                    <input type='hidden' name='capxid' value='".$capxlist[$i]["capxid"]."'></td>
                </tr>";
                    }
                }

Open in new window

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 35

Accepted Solution

by:
Dan Craciun earned 250 total points
ID: 39886531
I don't understand your need of "continue". This is how the loop should look, in my opinion:
<?php
for ($i=1;$i<=$capxlist["count"];$i++) {
	$rc_count++;
	$hlf = floor($rc_count/2);
	$dbl = $hlf*2;
	
	if ($rc_count != $dbl)
		$rclass = " class=''";
	else
		$rclass = " class='rcolor'";
	if($capxcompare["count"]<=0)
		{
		echo "
		<tr>
			<td width='25' align='center' $rclass><input type='Checkbox' name='assignCapX".$i."' value='".$capxlist[$i]["capxid"]. "'></td>
			<td width='".($leftcol-25-100)."' $rclass><a class='tip_trigger' href=''><span class='text'>".$capxlist[$i]["description"].' '.$capxlist[$i]['capxid']."</span><span class='tip'>
			 <table width='200'><tr><td class='text'>".$capxlist[$i]["shortname"]."</td></tr></table></span></a></td>
			<td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
			<td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
		   <input type='hidden' name='shortname' value='".$capxlist[$i]["shortname"]."'>
			<input type='hidden' name='description' value='".$capxlist[$i]["description"]."'>
			<input type='hidden' name='totalcost' value='".$capxlist[$i]["totalcost"]."'>
			<input type='hidden' name='assettypeid' value='".$capxlist[$i]["assettypeid"]."'>
			<input type='hidden' name='spmodelid' value='".$capxlist[$i]["spmodelid"]."'>
			<input type='hidden' name='capxid' value='".$capxlist[$i]["capxid"]."'></td>
		</tr>";
		}
	}
?>

Open in new window

0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 39886604
You can probably make things a lot easier if you learn about HEREDOC syntax.  There will be a lot less fiddly punctuation.  Heed, but do not be put off by, the warning.
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

As far as eval() goes, it's like goto.  Just don't.  The Apple security bug was caused by a goto statement.  And it's not like we haven't been warned.
http://xkcd.com/292/

To the meat of this question... it appears to be data-dependent.  If you can show us the data and tell us what you want to achieve we can almost certainly give you a tested and working code example.
0
 

Author Comment

by:brucegust
ID: 39889463
I figured it out.

I had some notes from a previous meeting with my team leader and he referenced the importance of "$i" which I didn't really understand until after the fact.

Bottom line: The information is coming as an array so I established some temporary variables and then submitted them to my insert statement based on whether or not the original check box had been selected. So it looks like this:

     eval("\$tmp_capxid = \$capxid".$i.";");
                eval("\$tmp_spmodelid = \$spmodelid".$i.";");
                eval("\$tmp_assettypeid = \$assettypeid".$i.";");
                eval("\$tmp_totalcost = \$totalcost".$i.";");
                eval("\$tmp_description = \$description".$i.";");
                eval("\$tmp_shortname = \$shortname".$i.";");
                eval("\$tmp_allocatedamount = \$allocatedamount".$i.";");
                             
                $capx_temp_assign = cer_capxtempsave($ID, $mID, $tmp_capxid, $tmp_spmodelid, $tmp_assettypeid, $tmp_totalcost, cleanstring($tmp_description), cleanstring($tmp_shortname), $tmp_allocatedamount);

Now, I get the variables I'm needing and all is gold.

Thanks everybody for weighing in!
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question