Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-02-25
6
Medium Priority
?
217 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 1000 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 500 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Accepted Solution

by:
Dan Craciun earned 1000 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

670 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