Jump to content

Recommended Posts

Posted

Just a pre-warning. The code I paste below is very rough, I'm still getting to grips with PHP so am doing things so they work first of all, before I even look at tidying them up.

 

What I want to happen is the php part will check if a user has any open helpdesk tickets. if they do, it continues to display them. if not, it will stop doing the bit about the helpdesk and carry on below the ?> and show the other table links instead. i'm guessing the answer will be tidy the script up and make functions, but wanted to know if there was a short term fix for it while i still pick up php

thanks in advance :)

 



School :: Staff Intranet






images/stafflogo.png

		  
		
		
		
		images/google.png
		  
		

		
		
		
		
		
		 
		
		 
		
	
	

	Current open helpdesk tickets - (click here to view/hide)
	
		
			$connect = mysql_connect('localhost', 'helpdesk', 'password');
if (!$connect) {die('Could not connect: ' . mysql_error());}
mysql_select_db('helpdesk');
$initial = $_SERVER["LOGON_USER"];  
$_SESSION['un'] = preg_replace("/.*\\\\/", "", $initial);  
$username = $_SESSION['un']; 
$query="SELECT * FROM client WHERE USER_NAME='$username'"; 
$result=mysql_query($query); 
$num=mysql_numrows($result); 
$i = 0; 
while ($i < $num) { 
$userid = mysql_result($result,$i,"client_id"); 
$query2="SELECT * FROM job_ticket WHERE client_id='$userid' AND status_type_id='1'";
$result2=mysql_query($query2); 
$num2=mysql_numrows($result2); 
If ($num2 == 0) {die('No helpdesk tickets found under your username');}
$x = 0; 
while ($x < $num2) { 
$jobname=mysql_result($result2,$x,"subject"); 
$jobdesc=mysql_result($result2,$x,"question_text"); 
$ticketnum=mysql_result($result2,$x,"job_ticket_id"); 
$status=mysql_result($result2,$x,"status_type_id"); 
If ($status ==1) {$jobstatus="Open";}
If ($status ==2) {$jobstatus="Awaiting User Input";}
$x++;}
echo "Ticket Number: $ticketnum
";
echo "Job Name: $jobname
";
echo "Job Description: $jobdesc
";
echo "Job Status: $fontcolor $jobstatus $fontend
";
echo "
"; 

$i++; 
} 

?>
		
	






<br />
<br />
var parentAccordion=new TINY.accordion.slider("parentAccordion");<br />
parentAccordion.init("acc","h3",-1,-1);<br />
<br />
var nestedAccordion=new TINY.accordion.slider("nestedAccordion");<br />
nestedAccordion.init("nested","h3",1,-1,"acc-selected");<br />
<br />

	
	






Helpdesk


images/helpdesk.png







Booking System


images/bookingsystem.png







	


		
	
	
	
	




Posted (edited)

try this:

 



School :: Staff Intranet






   
   
             
           
           
           
           
             
           

           
           
           
           
           
            
           
            
           
       
       

       Current open helpdesk tickets - (click here to view/hide)
       
           

$connect = mysql_connect('localhost', 'helpdesk', 'password');

if (!$connect) 
{
 die('Could not connect: ' . mysql_error());
}

mysql_select_db('helpdesk');

$initial = $_SERVER["LOGON_USER"]; 

$_SESSION['un'] = preg_replace("/.*\\\\/", "", $initial);  

$username = $_SESSION['un']; 

$query="SELECT * FROM client WHERE USER_NAME='$username'"; 
$result=mysql_query($query); 

$num=mysql_numrows($result); 
$i = 0; 

 while ($i < $num)
 { 
   $userid = mysql_result($result,$i,"client_id"); 
   $query2="SELECT * FROM job_ticket WHERE client_id='$userid' AND status_type_id='1'";
   $result2=mysql_query($query2); 
   $num2=mysql_numrows($result2); 

  If ($num2 == 0) 
 {
   echo 'No helpdesk tickets found under your username'; //removed the die statemant
 }
 else //added else statement
 {
 $x = 0; 

 while ($x < $num2) 
 { 
   $jobname=mysql_result($result2,$x,"subject"); 
   $jobdesc=mysql_result($result2,$x,"question_text"); 
   $ticketnum=mysql_result($result2,$x,"job_ticket_id"); 
   $status=mysql_result($result2,$x,"status_type_id"); 

   If ($status ==1) 
   {
     $jobstatus="Open";
   }

   If ($status ==2) 
   {
     $jobstatus="Awaiting User Input";
   }
 
 $x++;
 }
 }

echo "Ticket Number: $ticketnum
";
echo "Job Name: $jobname
";
echo "Job Description: $jobdesc
";
echo "Job Status: $fontcolor $jobstatus $fontend
";
echo "
"; 

$i++; 
} 

?>
           
       
   





<br />
<br />
var parentAccordion=new TINY.accordion.slider("parentAccordion");<br />
parentAccordion.init("acc","h3",-1,-1);<br />
<br />
var nestedAccordion=new TINY.accordion.slider("nestedAccordion");<br />
nestedAccordion.init("nested","h3",1,-1,"acc-selected");<br />
<br />

       
       






Helpdesk










Booking System










       


           
       
       
       
       
   





 

its hard to tell in the forum editor but that should do it ;), also each to there own but i prefer calling sql cells using $row['cellname']; so

 

		$sql = "SELECT NAME, AGE FROM `TABLE`
				WHERE ROW = VARIABLE";
			
		$rst = mysql_query($sql);
		
		while ($row = mysql_fetch_assoc($rst))
		{
			$name = $row['NAME'];
			$age = $row['AGE'];
                       }

Edited by Flakes
  • Thanks 1
Posted

Why not simply switch the if /die to an if else?

 

ie.

if ($num2 == 0) {
echo('No helpdesk tickets found under your username');
} else {
$x = 0;  
  while ($x < $num2) {  
   $jobname=mysql_result($result2,$x,"subject");  
   $jobdesc=mysql_result($result2,$x,"question_text");  
   $ticketnum=mysql_result($result2,$x,"job_ticket_id");  
   $status=mysql_result($result2,$x,"status_type_id");  
     if ($status ==1) {
      $jobstatus="Open";
     } 
     if ($status ==2) {
      $jobstatus="Awaiting User Input";
     } 
   $x++;
  } 
  echo "Ticket Number: $ticketnum
"; 
  echo "Job Name: $jobname
"; 
  echo "Job Description: $jobdesc
"; 
  echo "Job Status: $fontcolor$jobstatus$fontend
"; 
  echo "
";  
}

 

This will then continue on if the condition is met.

  • Thanks 1
Posted
Why not simply switch the if /die to an if else?

 

sadly i thought of this about ten mins later, i hate not realising the blindingly obvious things!!!

 

thanks to both of you :)

Posted

im a sucker for speed, i would also recommend using the least amount of echo statements possible, every echo requires a call to the parser, so the less you have the faster your scripts run, obviously the speed difference isnt alot in a small script like this but for bigger scripts it can become noticable.

 

echo "Ticket Number: $ticketnum
";
echo "Job Name: $jobname
";
echo "Job Description: $jobdesc
";
echo "Job Status: $fontcolor $jobstatus $fontend
";
echo "
";  

 

can become

 

echo "
Ticket Number: $ticketnum

Job Name: $jobname

Job Description: $jobdesc

Job Status: $fontcolor $jobstatus $fontend


";  

 

another warning tags, tags and other types of html text formatting are being phased out in preference for CSS styling (HTML tt, i, b, big, small tag) i recommend to use CSS, for font styles.

  • Thanks 1
Posted
Also, a small tip - don't put everything on one line if you can break it up. ie. those { blah } bits, put the { and } on new lines. It makes it easier to track what's what in my experience.
  • Thanks 1
Posted
im a sucker for speed, i would also recommend using the least amount of echo statements possible, every echo requires a call to the parser, so the less you have the faster your scripts run, obviously the speed difference isnt alot in a small script like this but for bigger scripts it can become noticable.

 

thanks for that. like i said i've only been looking into php the past couple of weeks so haven't got into the proper way of scripting yet. i'll most likely be altering the script with all these changes soon, but it was just a work in progress at the moment (this intranet page will go live september).

thanks again for the hints :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • 47 When would you like EduGeek EDIT 2025 to be held?

    1. 1. Select a time period you can attend


      • I can make it in June\July
      • I can make it in August\Sept
      • Other time period. Comment below
      • Either time

×
×
  • Create New...