Solved

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

Posted on 2014-02-25
6
210 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
6 Comments
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 34

Accepted Solution

by:
Dan Craciun earned 250 total points
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now