0

I have a loop that displays documents in a table with a radio button. Once selected I want it to display reset of the data. Right now when I click the radio button it will only display the first row of the documents how can I get my switch to switch between the radio values.

<?php
   while( $row1 = mysql_fetch_array($myQ1) ) 
    {
     echo "<td><input type='radio' name='tog' id='tog' onClick='gtdoc()'       value='$row1[2]'>$row1[3]</input></td></tr>"; 
    $tog = $row1[2]; $ObjIndex = $tog[$i];
     }

for ($i = 0; $i <= $tog; $i++) 
{ 
   if($tog[$i] != '0') 
   { 
    switch ($ObjIndex[$i]) 
    {
      case $tog:
      echo $row1[3];
      break;
    }
   }
}
$myQ9 = mysql_query("SELECT `iDocuments`.`File`.`FileIndex`, `iDocuments`.`File`.`FileName`, `iDocuments`.`Object`.`ObjectIndex`, `iDocuments`.`Object`.`ObjectName`, `iDocuments`.`Version`.`Version`, `iDocuments`.`File`.`UploadDate` FROM `iDocuments`.`Version` INNER JOIN `iDocuments`.`Object` ON `iDocuments`.`Object`.`ObjectIndex` = `iDocuments`.`Version`.`ObjectIndex` JOIN `iDocuments`.`File` ON `iDocuments`.`Version`.`FileIndex` = `iDocuments`.`File`.`FileIndex` WHERE `Object`.`ObjectStatus` = '1' AND `Version`.`Version` = ( SELECT MAX(`Version`) FROM `iDocuments`.`Version` WHERE `Version`.`ObjectIndex` = `Object`.`ObjectIndex` ) AND `Object`.`ObjectIndex` = '$ObjIndex'");
if (!$myQ9) 
   {  
      echo 'Could not run query 9: ' . mysql_error(); 
   }
else 
   { 
      $row9 = mysql_query($myQ9);
   }
    while( $row9 = mysql_fetch_array($myQ9) ) 
   {
      echo "<table name='doclist'>           
      <tr><td>FileID</td><td><input name='DocFileID' type='text' readonly='true' value='$row9[0]'></input></td></tr> 
      <tr><td>File Name</td><td><input name='DocFileName' type='text' readonly='true' value='$row9[1]'></input></td></tr> 
      <tr><td>ObjectID</td><td><input name='DocID' type='text' readonly='true' value='$row9[2]'></input></td></tr>  
      <tr><td>Object Name</td><td><input name='DocName' type='text' readonly='true' value='$row9[3]'></input></td></tr>  
      <tr><td>Current Version</td><td><input name='CurrVer' type='text' readonly='true' value='$row9[4]'></input></td></tr>
      <tr><td>Update Date</td><td><input name='lstupdate' type='text' readonly='true' value='$row9[5]'></input></td> </tr>
      </table>";
   }
?>
  • No idea, but maybe [an answer to *PHP file cannot enter some part of code*](http://stackoverflow.com/a/11580420/367456) is helpful for you. – hakre Jan 16 '13 at 15:02
  • $ObjIndex = $tog[$i]; $i is undefined here so you're just consistently making $ObjIndex equal the last rows value – Doug McK Jan 16 '13 at 15:05
  • What is `$tog` (or more accurately, what does `$row1[2]` return)? – Gareth Cornish Jan 16 '13 at 15:05
  • How do I define $tog[$i], tog is the name of the radio button so I put $tog = $row1[2] which is the value of the radio button – Alvina Reed Jan 16 '13 at 15:09

1 Answers1

0

I suggest that your first cleanup effort should be separating the html from the php, and only passing the variables that need to be passed to a template section.

This will also serve you well later when you're working on code that you want to be consumed by the public, and thus need to be secure, as just echoing out variables into html tends to have problematic security implications.

A really simple implementation which allows you to separate template code from business logic might be:

// do all your logic, and prepare variables here
include('formtemplate.php'); // With all the html in here.

You're really upping the complexity by having all this stuff mixed together, I know, I've been there.

Also, html booleans don't use ='true', you're looking for readonly or else readonly='readonly'

Kzqai
  • 22,588
  • 25
  • 105
  • 137