Jump to content


Photo

for loop nested with if


  • Please log in to reply
3 replies to this topic

#1 firedrop84

firedrop84
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 24 May 2006 - 01:07 PM

Hi ..

I have a problem with the following code. I got a page that displays some results based on the data that is in the databse. the output it displays in a table.

in that table there are 5 coloums. the the first row it just display the number. the second display the name. The forth coloumn it displays a button and the name of the button is the same name of the customer on that row. the last coloumn it just basically displays another button.

my porblem is with the forth coloumn. that is with the buttons. I want when the employee clicks on that button it should go to another page. I tired to use isset with for loop nested with if but it didn't work. can anybody help me on solving the mistake that I have in my code. I changed the header to just print "Hello";
and that just to test if it is going to display but it didn't.


// The databse result has already been retrieved

// the problem is with this code
$y = 0;
for ($v = 0; $v < $HowMany; $v++)
{
$y++;
if (isset($_POST["$Name[$y]"]))
{
print "Hello";
}
}

// Then I have displayed the table





#2 eves

eves
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 24 May 2006 - 01:19 PM

can you post the codes on the page where it is posted from?
also you might want to check if the checkbox is named as "Name[]"


#3 firedrop84

firedrop84
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 24 May 2006 - 01:30 PM

Here is the code for the page


<?php    

    // connect tot he database
    require ('connection.php');

$GetFollowUp = mysql_query("SELECT p.ProspectID, p.RegDate, p.Title, p.Surname, p.GivenName, p.FlatRoomNumber, p.StreetNumber,   p.StreetName, p.Suburb, p.State, p.PostCode, p.Primary, p.Other, p.Email,  p.EnquiryType, p.Source FROM prospect p, followup f WHERE (f.ProspectID = p.ProspectID)"); 

    $HowMany = mysql_num_rows($GetFollowUp);
    
    $y = 0;
    for ($v = 0; $v < $HowMany; $v++)
    {
        $y++;
        if (isset($_POST["$Name[$y]"])) 
           {
           print "Hello";
        }
        
    }
        
    if ($GetFollowUp && $HowMany != 0)
    {
        $i = 0;
                    
        while($data = mysql_fetch_array($GetFollowUp)) 
        { 
            $ProspectID[$i] = $data["ProspectID"];
            $RegDate[$i] = $data["RegDate"];
            $Title[$i] = $data["Title"];
            $ProspectSearch[$i] = $data["Surname"];
            $ProspectGivenName[$i] = $data["GivenName"];
            $FlatRoomNumber[$i] = $data["FlatRoomNumber"];
            $StreetNumber[$i] = $data["StreetNumber"];
            $StreetName[$i] = $data["StreetName"];
            $Suburb[$i] = $data["Suburb"];
            $State[$i] = $data["State"];
            $PostCode[$i] = $data["PostCode"];
            $Primary[$i] = $data["Primary"];
            $Other[$i] = $data["Other"];
            $Email[$i] = $data["Email"];
            $EnquiryType[$i] = $data["EnquiryType"];
            $Source[$i] = $data["Source"];
                
             $i++;
          } 
    }
        for ($w = 0; $w < $HowMany; $w++)
        {
            $Name[$w] = "$ProspectSearch[$w]" . " $ProspectGivenName[$w]";
        }
        
        
    
        mysql_close();
    
        // Assign the Data that has been retrieved into an array
        if ($GetFollowUp && $HowMany != 0)
        {
            // Dispalay the headings
            print "<form name=\"form1\" method=\"post\" action=\"\">";
              print "<table width=\"500\" border=\"0\" align=\"center\">";
            print "<tr bgcolor=\"#0033FF\">";
              print "<td><div align=\"center\"><span class=\"style3\">No. </span></div></td>";
              print "<td><div align=\"center\"><span class=\"style3\">Follow Ups </span></div></td>";
            print "<td bgcolor=\"#0033FF\"> Quick Add </td>";
            print "<td> Prospect Details </td>";
            print "<td> Completed </td>";
        
            print "</tr>";
        
            $n = 1;
            
        // Display the data 
            for ($x = 0; $x < $HowMany; $x++)
            {
                $BtnCompleted[$n] = "BtnCompleted$n";
                print "<tr bgcolor=\"#EEEEEE\">";
                print "<td>$n</td>";
                  print "<td>$ProspectSearch[$x] $ProspectGivenName[$x] </td>";
            
                print "<td> No</td>";
            
                print "<td> <input type=\"submit\" name=\"$Name[$x]\" value=\"Details\"></td>";
                print "<td> <input type=\"submit\" name=\"$BtnCompleted[$n]\" value=\"Completed\"></td>";
                print "</tr>";
                $n++;
            }
        }
        elseif ($HowMany == 0)
        {
            // Dispalay the headings
            print "<form name=\"form1\" method=\"post\" action=\"\">";
              print "<table width=\"200\" border=\"0\" align=\"center\">";
            print "<tr bgcolor=\"#0033FF\">";
              print "<td width=\"40\"><div align=\"center\"><span class=\"style3\">No. </span></div></td>";
              print "<td width=\"144\"><div align=\"center\"><span class=\"style3\">Follow Ups </span></div></td>";
            print "</tr>";
        
            print "<tr bgcolor=\"#EEEEEE\">";
            print "<td colspan=2> <center> No Follow Ups </center></td>";
            print "</tr>";
            print "</table> </form>";
        }

?>


#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 May 2006 - 05:43 PM

 if (isset($_POST["$Name[$y]"]))
           {
           print "Hello";

that's fine and dandy... except that you have not set $Name anywhere, so the condition will never be true.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users