Jump to content

Recommended Posts

Here is the code I am trying to make work. As you can see, the code as it stands will call a javascript window and that works well. I now want to add the lines that are commented out, in order to make the window display or not display conditionally. I have tried many combinations of escaping quotation marks, or substituting them, but nothing works properly. Usually I lose the link action along with a display of some of the code attached to the link. Could someone have a look and see if they can propose a code solution.

<?php
//if ($review != 0) 
//$yes2 =  
                    
if ("{$row['passState']}" == 0) {echo "<a href='javascript<b></b>:void(0);'NAME='var basestring='window'+new Date().getTime();' title=' Results of quiz 'onClick=window.open('check/check.php?quizTitle=". urlencode($quizTitle) ."', 'width=1100, height=510, resizable=yes, menubar=no, status=0, scrollbars=1');> <p>Check your answers</p> </a><br />\n";} 
                    
                   
//echo $yes2;					
//if ($review != 1)
//echo "";
?>

If it is any help, I'm using this code elsewhere on the page and it works fine.

<?php 					
if ($review != 0) 
$yes2 = "REVIEW";
echo $yes2;					
if ($review != 1)
echo ""; 
?>

 

Going to tell the truth here and say I'm not exactly sure what you are trying to do. I will make a few comments on what I see though.

 

You seem to be missing some brackets. Ex.

 

 

<?php 					
if ($review != 0) 
     {
$yes2 = "REVIEW";
echo $yes2;
      }

if ($review != 1)
echo ""; 

?>

 

I am only assuming this is how it is meant to function, as I don't know exactly what it is supposed to do. What the example reads to me is:

 

If $review does not equal 0 then $yes2 equals "REVIEW", either way print $yes2. then continue with the next if statement.

 

 

I'll explain further.

Firstly, the shorter piece of code described at the end of my post functions correctly. I just put it in the post to show a simplification of the longer similar piece of code described first. It's OK without the curly braces, but I can put them in, it makes no difference.

 

Now, the purpose of the first piece of code is to display or not display a column of data showing an array of links in a web page. What can be displayed is a popup javascript window giving the results of a student test. The column is an array because there are several tests to choose from.

Now some managers want their students to be able to see the results and some do not, so on another page in the site a manager can use a form to permit or deny his students the ability to review their results, hence the variable $review which will then have a value of 1 or 0 in the database.

As the code stands (with the conditional statement commented out) it all works fine.

What I want to be able to do is to have the link to the popup window displayed on the page according to a managers choice, yes or no. If I uncomment the conditional statement to enact this, the link no longer works, or even displays correctly.

I need some help in correcting the syntax for $yes = "blah blah etc";

Also, I should explain to phpSensei that there is a further condition already embedded in the link, and that is that the link should only display if passState in the database has a value of 0. This means that the student did not pass the test. This means that only tests that were not passed can be reviewed, but additionally, some managers do not want students to have that option anyway.

Here is the whole code as you requested. I'd appreciate your comments.

<?php session_start();
ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
// check if logged in.
if (isset($_SESSION['id'])) {
// Put session variables into local variables
    $userPwd     = $_SESSION['userPwd'];	
    $id          = $_SESSION['id'];
$userIdRec   = $_SESSION['userIdRec'];
    $userId      = $_SESSION['userId'];
$quizTitle   = $_SESSION['quizTitle'];
$family      = $_SESSION['family'];
$given       = $_SESSION['given'];
$transferCode= $_SESSION['transferCode'];
$userCollege = $_SESSION['userCollege'];
$userGroup   = $_SESSION['userGroup'];
$egroup      = $_SESSION['egroup'];
$managerId   = $_SESSION['managerId'];
$doe         = $_SESSION['doe'];
$lastlogin   = $_SESSION['lastlogin'];
$avatar      = $_SESSION['avatar'];
$permit      = $_SESSION['permit'];
$speech      = $_SESSION['speech'];	
}
else 
{ 
?>
<html>
<tr>
  <td> 
    <p> 
    <p> 
    <p></td>
</tr>
<table align="center" border="1" width="400" height="200">
    <td align="center" valign="center">You must log in at the <a href="../index.php">Student Portal</a> to see<br />
      your quiz list.</td>
</table>
</html>
<?php exit(); 
} 
include_once "../real_conn/real_conn.php";
$sql = mysql_query("SELECT * FROM users WHERE id='$id'"); 
$login_check = mysql_num_rows($sql);
if($login_check > 0){ 
    while($row = mysql_fetch_array($sql)){ 
        // Get member data into a session variable
        $egroup = $row["egroup"];
        $_SESSION['egroup'] = $egroup; 

        $userPwd = $row["userPwd"]; 
      $_SESSION['userPwd'] = $userPwd;  

        $given = $row["given"]; 
      $_SESSION['given'] = $given;  

        $avatar = $row["avatar"]; 
      $_SESSION['avatar'] = $avatar;  

        $permit = $row["permit"]; 
      $_SESSION['permit'] = $permit;  

        $review = $row["review"]; 
      $_SESSION['review'] = $review;

}
}
?>
<!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" dir="ltr" lang="en-US" xml:lang="en">
<head>
<!--
    Base template (without user's data) checked by http://validator.w3.org : "This page is valid XHTML 1.0 Transitional"
    -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Student Quiz Record</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]-->
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="script.js"></script>
<script Language = "JavaScript">

function OpenWin1()
{
	window.open("avatar/sel_avatar.php", "Child",'width=550,height=560,right=30,top=20,scrollbar=yes,resize=yes');

}
</script>
</head>
<body>
<div id="art-main">
  <div class="art-sheet">
    <div class="art-sheet-tl"></div>
    <div class="art-sheet-tr"></div>
    <div class="art-sheet-bl"></div>
    <div class="art-sheet-br"></div>
    <div class="art-sheet-tc"></div>
    <div class="art-sheet-bc"></div>
    <div class="art-sheet-cl"></div>
    <div class="art-sheet-cr"></div>
    <div class="art-sheet-cc"></div>
    <div class="art-sheet-body">
      <div class="art-header">
        <div class="art-header-center">
          <div class="art-header-png"></div>
          <div class="art-header-jpeg"></div>
        </div>
        <div class="art-logo">
          <h1 id="name-text" class="art-logo-name"><a href="#">Safety Testing Online</a></h1>
          <h2 id="slogan-text" class="art-logo-text">Safety - The Most Valuable Insurance.</h2>
        </div>
      </div>
      <div class="art-nav">
        <div class="l"></div>
        <div class="r"></div>
        <ul class="art-menu">
          <li> <a href="stud_logout.php"><span class="l"></span><span class="r"></span><span class="t">Log Out</span></a></li>
          <li>
            <?php 					
		    if ($permit != 0) 
			$yes = "<a href=\"#\" onClick=\"window.open ('avatar/sel_avatar.php', 'mywindow','height=775, width=900, left=30, right=30,top=20, scrollbars');\"><span class=\"t\">SELECT YOUR AVATAR";
			echo $yes;					
			if ($permit != 1)
			echo ""; 
			?>
            </span></a> </li>
          <li> <a href="student_do_quiz.php"><span class="l"></span><span class="r"></span><span class="t">Quiz Page</span></a></li>
          <li> <a href="web_certificate/certificate.php" target="_blank"><span class="l"></span><span class="r"></span><span class="t">Certificate</span></a></li>
        </ul>
      </div>
    </div>
    <div class="art-content-layout">
      <div class="art-content-layout-row">
        <div class="art-layout-cell art-content">
          <div class="art-post">
            <div class="art-post-tl"></div>
            <div class="art-post-tr"></div>
            <div class="art-post-bl"></div>
            <div class="art-post-br"></div>
            <div class="art-post-tc"></div>
            <div class="art-post-bc"></div>
            <div class="art-post-cl"></div>
            <div class="art-post-cr"></div>
            <div class="art-post-cc"></div>
            <div class="art-post-body"></div>
            <div class="art-post-bl"></div>
            <div class="art-post-br"></div>
            <div class="art-post-tc"></div>
            <div class="art-post-bc"></div>
            <div class="art-post-cl"></div>
            <div class="art-post-cr"></div>
            <div class="art-post-cc"></div>
            <div class="art-post-body">
              <div class="art-post-inner art-article">
                <table style="text-align:center" width="778" border="0" >
                  <tr>
                    <td width="120" style="text-align:left" ROWSPAN="2"><?php
				 if ($permit != '0') 
                     $img = "<img src='avatar/av/".$avatar."' height=\"100\" width=\"100\" />";
                     echo $img;
				 ?>
                      </font></td>
                    <td width="650" style="text-align:left"><font size="+1"><?php echo "$userCollege"; ?> Safety Testing.</font></td>
                  </tr>
                  <tr>
                    <td width="650" style="text-align:left">Hi <?php echo "$given"; ?>. Your quiz results are shown below.    <a href="student_do_quiz.php?id=" target="_self">Return to your Quiz Page</a></font></td>
                  </tr>
                </table>
                <hr />
                <table width="778">
                  <tr>
                    <td width="13"></td>
                    <td width="140" style="vertical-align:middle; text-align:center;" >QUIZ NAME</td>
                    <td width="13"></td>
                    <td width="100" style="vertical-align:middle; text-align:center;" >DATE</td>
                    <td width="13"></td>
                    <td width="100" style="vertical-align:middle; text-align:center;" >SUCCESS</td>
                    <td width="13"></td>
                    <td width="100" style="vertical-align:middle; text-align:center;" >TRY AGAIN</td>
                    <td width="13"></td>
                    <td width="100" style="vertical-align:middle; text-align:center;" >
                    <?php 					
		    if ($review != 0) {
			$yes2 = "REVIEW";}
			echo $yes2;					
			if ($review != 1)
			echo ""; 
			?>
                    </td>
                    <td width="13"></td>
                    <td width="80" style="vertical-align:middle; text-align:center;" >SCORE</td>
                    <td width="13"></td>
                  </tr>
                </table>
                <?php
$query1 = mysql_query("SELECT quizTitle, passState, userScore, totalScore, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' ORDER BY quizTitle ASC, passState DESC, userDate DESC ");
?>
                <table width="778" style="font-size:16px">
                  <tr>
                    <?php
while ($row = mysql_fetch_array($query1))
{
?>
                    <td width="13"></td>
                    <td width="140" style="vertical-align:middle; text-align:left; font-size:12px;"><?php $quizTitle = "{$row[quizTitle]}"; $_GET['quiztitle']=$quizTitle; echo "{$row['quizTitle']} <br />\n"; ?></td>
                    <td width="13"></td>
                    <td width="100" style="vertical-align:middle; text-align:center; font-size:12px;"><?php echo "{$row['userDate']} <br />\n"; ?></td>
                    <td width="23"></td>
                    <td width="100" style="text-align:center;"><?php if ("{$row['passState']}" == 1) {echo "<img src=' ../wood/wood_tool_images/tick2.png' /><br />\n";}?></td>
                    <td width="13"></td>
                    <td width="100" style="text-align:center;"><?php if ("{$row['passState']}" == 0) {echo "<img src=' ../wood/wood_tool_images/cross2.png' /><br />\n";} ?></td>
                    <td width="13"></td>
                    <td width="100" style="text-align:left; vertical-align:baseline font-size:10px; text-decoration:underline; color:#06F;">

				<?php
                    //if ($review != 0) 
			//$yes2 =  
                    
				if ("{$row['passState']}" == 0) {echo "<a href='javascript:void(0);'NAME='var basestring='window'+new Date().getTime();' title=' Results of quiz 'onClick=window.open('check/check.php?quizTitle=". urlencode($quizTitle) ."','width=1100,height=510,resizable=yes,menubar=no,0,status=0,scrollbars=1');><p>Check your answers</p></a><br />\n";} 
                    
                   
			//echo $yes2;					
			//if ($review != 1)
			//echo "";
			?>
                    
                    </td>
                    <td width="13"></td>
                    <td width="80" style="vertical-align:middle; text-align:center; font-size:12px;"><?php echo "{$row['userScore']}".'/'."{$row['totalScore']} <br />\n"; ?></td>
                    <td width="13" style="text-align:center; font-size:10px;"></td>
                  </tr>
                  <?php 
}
        
      
?>
                </table>
                <hr />
                <!-- /article-content -->
              </div>
              <div class="cleared"></div>
            </div>
            <div class="cleared"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="cleared"></div>
  <div class="art-footer">
    <div class="art-footer-inner">
      <div class="art-footer-text">
        <p><a href="../minor/contact.html">Contact Us</a> | <a href="../minor/terms.html">Terms of Use</a> | <a href="../minor/copyright.html">Copyright</a> | <a href="../minor/privacy.html">Privacy Statement</a>| <a href="../minor/ffa-woodworking.html">Links</a><br />
          <?php 
$time = time () ; 
//This line gets the current time off the server
$year= date("Y",$time); 
//This line formats it to display just the year
echo "Copyright © 2010 - " . $year;
//this line prints out the copyright date range, you need to edit 2010 to be your opening year
?>
          All Rights Reserved.</p>
      </div>
      <div class="art-footer-background"></div>
    </div>
    <div class="cleared"></div>
  </div>
</div>
<div class="cleared"></div>
<p class="art-page-footer">Designed by <a href="http://www.safetytestingonline.com">Frank Carroll</a>. </p>
</div>
<!-- Site Meter -->
<center>
  <script type="text/javascript" src="http://s36.sitemeter.com/js/counter.js?site=s36jindabyne">
</script>
  <noscript>
  <a href="http://s36.sitemeter.com/stats.asp?site=s36jindabyne" target="_top"> <img src="http://s36.sitemeter.com/meter.asp?site=s36jindabyne" alt="Site Meter" border="0"/> </a>
  </noscript>
  <br />
  <!-- Copyright (c)2009 Site Meter -->
</center>
</body>
</html>

  • Line 8-24: You are placing the sessions inside the variables, and then you repeat the same process from line 48-65. You only need the $id... Repetitive coding
  • Line 47: No need for a while loop if only 1 user id is present in the query just do a fetch array without loop
  • Line 224: Your quotations are way off, You need to make a javascript function to call this window, this would be easier way.... your putting too much inside one href action..

 

in other words, everything is fine, you can use this code with no problems with printing that link.

 

 <?php 					
		    if ($review != 0) {
			$yes2 = "REVIEW";}
			echo $yes2;					
			if ($review != 1)
			echo ""; 
			?>

 

So What Can I Do Sensei?

 

You can make a function as mentioned

 

<script type="text/javascript" language="javascript">

				 	 function popupQuiz(quizUrl,quizTitle):
				        window.open(quizUrl,quizTitle,'width=1100,height=510,resizable=yes,menubar=no,0,status=0,scrollbars=1');
					   } 
</script>

 

Then use it on line 224 like this

 

<a href="javascript:popupQuiz(\'check/check.php?quizTitle='. urlencode($quizTitle).'\',\''.$quizTitle.'\')"><p>Check your answers</p></a>";

 

 

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.