www.webdeveloper.com
Results 1 to 3 of 3

Thread: script problem

  1. #1
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197

    script problem

    Hi below is code that is supposed to get survey questions from a mysql table and display each question as a table row. I'm having a hard time with the while statements in the middle of the page its preventing the table rows from displaying



    PHP Code:
    <?php
    /* Check User Script */
    session_start();  // Start Session
    include ("../Connections/db.php");
    //check if user is already logged in
    /*if (!isset($_SESSION['user_id'])){
    $ip_address     = $_SERVER['REMOTE_ADDR'];

    $msg = 'You tryed to access a members only page. Login or become a registered member to access that page!';

    header("Location: ../index.php?msg=".$msg); 
    }*/
    if(isset($_POST['Submit'])){

    $query_get_PollData "SELECT `excellent`,`very_good`,`good`,`fair`,`poor`,`id`,`ip_address` FROM `survey`";
    $get_PollData mysql_query($query_get_PollData) or die(mysql_error());
    while(
    $PollData mysql_fetch_assoc($get_PollData)){

    $excellent $_POST['excellent'];
    $very_good $_POST['very_good'];
    $good $_POST['good'];
    $fair $_POST['fair'];
    $poor $_POST['poor'];

    if (
    is_array($excellent) || is_array($very_good) || is_array($good) || is_array($fair) || is_array($poor)){

        if (
    is_array($excellent)) {

        foreach (
    $excellent AS $key=>$value){

    if (
    is_array($excellent)) {
    $excellent $PollData["excellent"] + 1;
    $TotalVotes $PollData["total_votes"]+ 1;

    $query_update_excellent = ("UPDATE `survey` SET `excellent`= '$excellent', `total_votes`= '$TotalVotes'");
     
    mysql_query($query_update_excellent) or die(mysql_error());
        }

    }
     }
     }
      }
      }
    $query_get_survey_questions "SELECT `excellent`,`very_good`,`good`,`fair`,`poor`,`id`, `title`, `question` FROM `survey`";

    $get_vote_data mysql_query($query_get_survey_questions)or die(mysql_error());

    ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title></title>

    <link href="../design/default.css" rel="stylesheet" type="text/css" />

    <style type="text/css">
    <!--
    .style1 {font-size: 10px}
    -->
    </style>
    </head>

    <body>
    <div id="outer">
    <?php include('../design/banner.php'); ?>
        
      <div id="twoColumnRight">
      <form name="enter_data" method="post" action="<?php echo $PHP_SELF ;?>">
        <table class="forms">
        
          <tr>
            
            <td colspan="6" class="header" style="width:16%;">Community Survey </td>
          </tr>
          <?php    
         
          
    while($VoteData mysql_fetch_assoc($get_vote_data)){
          
          if(
    $VoteData["excellent"] != 0) {
        
    $VoteExcellent Round(($VoteData["excellent"] / $VoteData["Votes"]) * 100) . "%";
    } else {
        
    $VoteExcellent ."%";
    }
          if(
    $VoteData["very_good"] != 0) {
        
    $VoteVery_good Round(($VoteData["very_good"] / $VoteData["Votes"]) * 100) . "%";
    } else {
        
    $VoteVery_good ."%";
    }
          if(
    $VoteData["good"] != 0) {
        
    $VoteGood Round(($VoteData["good"] / $VoteData["Votes"]) * 100) . "%";
    } else {
        
    $VoteGood ."%";
    }
          if(
    $VoteData["fair"] != 0) {
        
    $VoteFair Round(($VoteData["fair"] / $VoteData["Votes"]) * 100) . "%";
    } else {
        
    $VoteFair ."%";
    }
          if(
    $VoteData["poor"] != 0) {
        
    $VotePoor Round(($VoteData["poor"] / $VoteData["Votes"]) * 100) . "%";
    } else {
        
    $VotePoor ."%";
    }
       
    ?>
    <?php 
    while ($survey_question mysql_fetch_assoc($get_vote_data)){ ?>
          <tr>
            <td class="left style1" style="width:20%;"><div align="center">Question</div></td>
            <td class="center style1" style="width:16%;"><div align="center">Excellent</div></td>
            <td class="center style1" style="width:16%;"><div align="center">Very Good </div></td>
            <td class="center style1" style="width:16%;"><div align="center">Good</div></td>
            <td class="center style1" style="width:16%;"><div align="center">Fair</div></td>
            <td class="right style1" style="width:16%;"><div align="center">Poor</div></td>
          </tr>
          <tr>
            <td rowspan="2" class="left"><?php echo $survey_question['question'] ;?></td>
            <td height="50" class="center"><div align="center">
              <input name="excellent" type="radio" value="excellent[<?php echo $survey_question['id'] ;?>]" />
            </div></td>
            <td class="center"><div align="center">
              <input name="veryGood" type="radio" value="veryGood[<?php echo $survey_question['id'] ;?>]" />
            </div></td>
            <td class="center"><div align="center">
              <input name="good" type="radio" value="good[<?php echo $survey_question['id'] ;?>]" />
            </div></td>
            <td class="center"><div align="center">
              <input name="fair" type="radio" value="fair[<?php echo $survey_question['id'] ;?>]" />
            </div></td>
            <td><div align="center">
              <input name="poor" type="radio" class="right" value="poor[<?php echo $survey_question['id'] ;?>]" />
            </div></td>
          </tr>
          <tr>
            <td height="50" class="center"><img src="../images/poll_bar.gif" width="<?=$VoteExcellent?>" height="20" title="Votes: <?=$VoteData["excellent"]?>"></td>
            <td class="center"> <img src="../images/poll_bar.gif" width="<?=$VoteVery_good?>" height="20" title="Votes: <?=$VoteData["very_good"]?>"></td>
            <td class="center"><img src="../images/poll_bar.gif" width="<?=$VoteGood?>" height="20" title="Votes: <?=$VoteData["good"]?>"></td>
            <td class="center"><img src="../images/poll_bar.gif" width="<?=$VoteFair?>" height="20" title="Votes: <?=$VoteData["fair"]?>"></td>
            <td class="right"><img src="../images/poll_bar.gif" width="<?=$VotePoor?>" height="20" title="Votes: <?=$VoteData["poor"]?>"></td>
          </tr>
          <?php 
             }
    ?>
          <td><input type="submit" name="Submit" value="Enter" /></td>
          
        </table>
        </form>
        </div>
            <div id="twoColumnLeft">
            
                <?php include('../design/leftlinks.php'); ?>
            </div>
            <div id="footer">
            <?php include('../design/footer.php'); ?>
            </div>
    </div>

    </body>
    </html>
    Kevin

  2. #2
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197
    I have all the bugs worked out that was found in the last post. For some reason more then two radio buttons can be selected how can I change it to limit to one selection per table row, any help is excellent

    PHP Code:
    <?php
    /* Check User Script */
    session_start();  // Start Session
    include ("../Connections/db.php");
    //check if user is already logged in
    /*if (!isset($_SESSION['user_id'])){
    $ip_address     = $_SERVER['REMOTE_ADDR'];

    $msg = 'You tryed to access a members only page. Login or become a registered member to access that page!';

    header("Location: ../index.php?msg=".$msg); 
    }*/
    if(isset($_POST['Submit'])){

    $excellent $_POST['excellent'];
    $very_good $_POST['very_good'];
    $good $_POST['good'];
    $fair $_POST['fair'];
    $poor $_POST['poor'];


    $query_get_PollData "SELECT `excellent`,`very_good`,`good`,`fair`,`total_votes`,`poor`,`id`,`ip_address` FROM `survey`";
    $get_PollData mysql_query($query_get_PollData) or die(mysql_error());
    while(
    $PollData mysql_fetch_assoc($get_PollData)){
     
    if (
    is_array($excellent) || is_array($very_good) || is_array($good) || is_array($fair) || is_array($poor)){

     
    //excellent
        
    if (is_array($excellent)) {

        foreach (
    $excellent AS $key=>$value){

    $excellent $PollData["excellent"] + 1;
    $TotalVotes $PollData["total_votes"]+ 1;
     

    $query_update_excellent = ("UPDATE `survey` SET `excellent`= '$excellent', `total_votes`= '$TotalVotes' WHERE id = '$key'");
     
    mysql_query($query_update_excellent) or die(mysql_error());
        }

    }
        
        
    //very good
        
    if (is_array($very_good)) {

        foreach (
    $very_good AS $key=>$value){

    $very_good $PollData["very_good"] + 1;
    $TotalVotes $PollData["total_votes"]+ 1;
     
    $query_update_very_good = ("UPDATE `survey` SET `very_good`= '$very_good', `total_votes`= '$TotalVotes' WHERE id = '$key'");
     
    mysql_query($query_update_very_good) or die(mysql_error());
      
      }
        }

        
    // good
        
    if (is_array($good)) {

        foreach (
    $good AS $key=>$value){

    $good $PollData["good"] + 1;
    $TotalVotes $PollData["total_votes"]+ 1;
     
    $query_update_good = ("UPDATE `survey` SET `good`= '$good', `total_votes`= '$TotalVotes' WHERE id = '$key'");
     
    mysql_query($query_update_good) or die(mysql_error());
      
      }
        }
    // fair
        
    if (is_array($fair)) {

        foreach (
    $fair AS $key=>$value){

    $fair $PollData["fair"] + 1;
    $TotalVotes $PollData["total_votes"]+ 1;
     
    $query_update_fair = ("UPDATE `survey` SET `fair`= '$fair', `total_votes`= '$TotalVotes' WHERE id = '$key'");
     
    mysql_query($query_update_fair) or die(mysql_error());
      
      }
        }
        
        
    // poor
        
    if (is_array($poor)) {

        foreach (
    $poor AS $key=>$value){

    $poor $PollData["poor"] + 1;
    $TotalVotes $PollData["total_votes"]+ 1;
     
    $query_update_poor = ("UPDATE `survey` SET `poor`= '$poor', `total_votes`= '$TotalVotes' WHERE id = '$key'");
     
    mysql_query($query_update_poor) or die(mysql_error());
      
      }
        }
        }
    //
            
    }//
                
    }// 
                  
    ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>survey</title>

    <link href="../design/default.css" rel="stylesheet" type="text/css" />

    <style type="text/css">
    <!--
    .style1 {font-size: 10px}
    -->
    </style>
    </head>

    <body>
    <div id="outer">
    <?php include('../design/banner.php'); ?>
        
      <div id="twoColumnRight">
      <form name="enter_data" method="post" action="<?php echo $PHP_SELF ;?>">
        <table class="forms">
        
          <tr>
            
            <td colspan="6" class="header" style="width:16%;">Community Survey </td>
          </tr>
          <?php    
          
         $query_get_vote_data 
    "SELECT `excellent`,`very_good`,`good`,`fair`,`poor`,`id`, `title`, `question`, `total_votes` FROM `survey`";

    $get_vote_data mysql_query($query_get_vote_data)or die(mysql_error());

          while(
    $VoteData mysql_fetch_array($get_vote_data)){
          
          if(
    $VoteData["excellent"] != 0) {
        
    $VoteExcellent Round(($VoteData["excellent"] / $VoteData["total_votes"]) * 100) . "%";
    } else {
        
    $VoteExcellent ."%";
    }
          if(
    $VoteData["very_good"] != 0) {
        
    $VoteVery_good Round(($VoteData["very_good"] / $VoteData["total_votes"]) * 100) . "%";
    } else {
        
    $VoteVery_good ."%";
    }
          if(
    $VoteData["good"] != 0) {
        
    $VoteGood Round(($VoteData["good"] / $VoteData["total_votes"]) * 100) . "%";
    } else {
        
    $VoteGood ."%";
    }
          if(
    $VoteData["fair"] != 0) {
        
    $VoteFair Round(($VoteData["fair"] / $VoteData["total_votes"]) * 100) . "%";
    } else {
        
    $VoteFair ."%";
    }
          if(
    $VoteData["poor"] != 0) {
        
    $VotePoor Round(($VoteData["poor"] / $VoteData["total_votes"]) * 100) . "%";
    } else {
        
    $VotePoor ."%";
    }
       
    ?>
    <?php 
    $query_get_survey_questions 
    "SELECT `excellent`,`very_good`,`good`,`fair`,`poor`,`id`, `title`, `question` FROM `survey`";

    $get_survey_questions mysql_query($query_get_survey_questions)or die(mysql_error());

    while (
    $survey_question mysql_fetch_array($get_survey_questions)){ ?>
          <tr>
            <td class="left style1" style="width:20%;"><div align="center">Question</div></td>
            <td class="center style1" style="width:16%;"><div align="center">Excellent</div></td>
            <td class="center style1" style="width:16%;"><div align="center">Very Good </div></td>
            <td class="center style1" style="width:16%;"><div align="center">Good</div></td>
            <td class="center style1" style="width:16%;"><div align="center">Fair</div></td>
            <td class="right style1" style="width:16%;"><div align="center">Poor</div></td>
          </tr>
          <tr>
            <td rowspan="2" class="left"><?php echo $survey_question['question'] ;?></td>
            <td height="50" class="center"><div align="center">
              <input name="excellent[<?php echo $survey_question['id'];?>]" type="radio" value="excellent" />
            </div></td>
            <td class="center"><div align="center">
              <input name="very_good[<?php echo $survey_question['id'];?>]" type="radio" value="very_good" />
            </div></td>
            <td class="center"><div align="center">
              <input name="good[<?php echo $survey_question['id'];?>]" type="radio" value="good" />
            </div></td>
            <td class="center"><div align="center">
              <input name="fair[<?php echo $survey_question['id']; ?>]" type="radio" value="fair" />
            </div></td>
            <td class="right"><div align="center">
              <input name="poor[<?php echo $survey_question['id']; ?>]" type="radio" class="right" value="poor" />
            </div></td>
          </tr>
          <tr>
            <td height="50" class="center"><img src="../images/poll_bar.gif" width="<?=$VoteExcellent?>" height="20" title="Votes: <?=$VoteData["excellent"]?>"></td>
            <td class="center"> <img src="../images/poll_bar.gif" width="<?=$VoteVery_good?>" height="20" title="Votes: <?=$VoteData["very_good"]?>"></td>
            <td class="center"><img src="../images/poll_bar.gif" width="<?=$VoteGood?>" height="20" title="Votes: <?=$VoteData["good"]?>"></td>
            <td class="center"><img src="../images/poll_bar.gif" width="<?=$VoteFair?>" height="20" title="Votes: <?=$VoteData["fair"]?>"></td>
            <td class="right"><img src="../images/poll_bar.gif" width="<?=$VotePoor?>" height="20" title="Votes: <?=$VoteData["poor"]?>"></td>
          </tr>
          <?php 
             }
    ?>
          <td><input type="submit" name="Submit" value="Enter" /></td>
          
        </table>
        </form>
        </div>
            <div id="twoColumnLeft">
            
                <?php include('../design/leftlinks.php'); ?>
            </div>
            <div id="footer">
            <?php include('../design/footer.php'); ?>
            </div>
    </div>

    </body>
    </html>
    Kevin

  3. #3
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197
    the problem is each radio button has a different name. based on how my script is set up this needs to stay this way.
    Kevin

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles