Page 1 of 1

sending a variable

Posted: Wed Dec 03, 2008 12:44 pm
by phpPain
Hi all,

I have the following,

Code: Select all

 
 
    //get values post data to update.php
    printf("<form action=\"%s\" method=\"%s\">\n", 'viewProgram.php', 'post');
    while ($row = mysql_fetch_row($result))
    {
        printf("id  " . $row[0]);
        printf("  Channel:" . $row[1]);
        printf("  Program:" . $row[2]);
        printf("  Time:" . $row[3] . " ");
        printf("<input type=\"submit\" name=\"mysubmit\" value=\"View Comments\" />");
        printf("<br/><br/>");
    }
    print "</form>";  
    ?>
 
 
 
It extracts data from the database, and prints a command button at the end of each row. When I click the button I would the item selected to be displayed on another page any one know now to do this?

Regards.

Re: sending a variable

Posted: Wed Dec 03, 2008 2:43 pm
by requinix
viewProgram.php needs to know which item to display. Once it does then it's easy.

I'd make a modification to your HTML, something like this:

Code: Select all

printf("<input type=\"submit\" name=\"mysubmit[" . $row[0] . "]\" value=\"View Comments\" />");
To retrieve the ID in the other page, use

Code: Select all

$id = key($_POST["mysubmit"]);

Re: sending a variable

Posted: Thu Dec 04, 2008 6:08 am
by phpPain
this is the page that should display the item selected, it wont display th result it comes back with a blank page..

.

Code: Select all

 
 
    //pass checkedvalue
    $id = key($_POST["mysubmit"]);
    //$checkedValue = $_POST['checkValue'];
    
    if ($id =! null)
    {
    $sql = "SELECT programmes WHERE id = $id"; 
    }