Jump to content

Recommended Posts

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



Link to comment
https://forums.phpfreaks.com/topic/10345-for-loop-nested-with-if/
Share on other sites

Here is the code for the page

[code]

<?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>";
        }

?>
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.