+ Post New Thread
Results 1 to 7 of 7
Web Development Thread, How to kill a php script but continue loading in Coding and Web Development; Just a pre-warning. The code I paste below is very rough, I'm still getting to grips with PHP so am ...
  1. #1

    MK-2's Avatar
    Join Date
    Oct 2006
    Location
    Nottingham
    Posts
    3,237
    Thank Post
    149
    Thanked 581 Times in 307 Posts
    Blog Entries
    8
    Rep Power
    200

    How to kill a php script but continue loading

    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

    PHP Code:
    <html>
    <head>
    <title>School :: Staff Intranet</title>
    <link href="dhs.css" rel="stylesheet" type="text/css" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>

    <div id="container">
        <center><div id="header-image"><img src="images/stafflogo.png"></div></center>
        <div id="body">
                &nbsp;&nbsp;
                <table cellpadding="3" cellspacing="3" class="search" width="800px" align="center">
                <tr>
                <td>
                <center><img src="images/google.png">
                &nbsp;&nbsp;
                <br>
                <form method="get" action="http://www.google.co.uk/search">
                <input type="text"  name="q" size="55" maxlength="255" value="" />
                <input type="submit" value="Search" />
                </form></center>
                </td></td></table>
                &nbsp;
                <hr width="75%">
                &nbsp;
                
            <div id="main-text">
            <ul class="acc" id="acc">
    <li>
            <h3><center>Current open helpdesk tickets - (click here to view/hide)</center></h3>
            <div class="acc-section">
                <div class="acc-content">
                    <?php
    $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="<font color='green'>Open</font>";}
    If (
    $status ==2) {$jobstatus="<font color='red'>Awaiting User Input</font>";}
    $x++;}
    echo 
    "<b>Ticket Number</b>: $ticketnum<br>";
    echo 
    "<b>Job Name</b>: $jobname<br>";
    echo 
    "<b>Job Description</b>: $jobdesc<br>";
    echo 
    "<b>Job Status</b>: $fontcolor $jobstatus $fontend<br>";
    echo 
    "<br><hr width=75%>"

    $i++; 


     
    ?>
                </div>
            </div>
        </li>

    </ul>

    <script type="text/javascript" src="js/script.js"></script>

    <script type="text/javascript">

    var parentAccordion=new TINY.accordion.slider("parentAccordion");
    parentAccordion.init("acc","h3",-1,-1);

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

    </script>
            
            
    <table width="90%" cellpadding="5" cellspacing="10" class="links" align="center">
    <tr>

    <td class="outer" width="20%" onClick="document.location.href='http://dhs-intranet:8081';" style="cursor:pointer;cursor:hand" onmouseover="style.backgroundColor='#6f9387';" onmouseout="style.backgroundColor='#e2ebe8'">
    <table align="center">
    <tr>
    <th>Helpdesk</th>
    </tr>
    <tr>
    <td align="center"><img src="images/helpdesk.png" border="0"></td>
    </tr>
    </table>
    </td></a>

    <td class="outer" width="20%" onClick="document.location.href='#';" style="cursor:pointer;cursor:hand" onmouseover="style.backgroundColor='#6f9387';" onmouseout="style.backgroundColor='#e2ebe8'">
    <table align="center">
    <tr>
    <th>Booking System</th>
    </tr>
    <tr>
    <td align="center"><img src="images/bookingsystem.png" border="0"></td>
    </tr>
    </table>
    </td>
    </td>

    </tr>
    </table>
            <br><br>
                
            <div id="footer">
            <?php echo '&copy; School '.date('Y').''?>
            </div>
            </div>
        </div>
    </div>

    </body>
    </html>

  2. #2
    Flakes's Avatar
    Join Date
    Nov 2009
    Location
    Newcastle
    Posts
    476
    Thank Post
    38
    Thanked 74 Times in 48 Posts
    Rep Power
    27
    try this:

    PHP Code:
    <html>
    <head>
    <title>School :: Staff Intranet</title>
    <link href="dhs.css" rel="stylesheet" type="text/css" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>

    <div id="container">
        <center><div id="header-image"><img src="http://www.edugeek.net/images/stafflogo.png"></div></center>
        <div id="body">
                &nbsp;&nbsp;
                <table cellpadding="3" cellspacing="3" class="search" width="800px" align="center">
                <tr>
                <td>
                <center><img src="http://www.edugeek.net/images/google.png">
                &nbsp;&nbsp;
                <br>
                <form method="get" action="http://www.google.co.uk/search">
                <input type="text"  name="q" size="55" maxlength="255" value="" />
                <input type="submit" value="Search" />
                </form></center>
                </td></td></table>
                &nbsp;
                <hr width="75%">
                &nbsp;
                
            <div id="main-text">
            <ul class="acc" id="acc">
    <li>
            <h3><center>Current open helpdesk tickets - (click here to view/hide)</center></h3>
            <div class="acc-section">
                <div class="acc-content">
    <?php

    $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="<font color='green'>Open</font>";
        }

        If (
    $status ==2
        {
          
    $jobstatus="<font color='red'>Awaiting User Input</font>";
        }
      
      
    $x++;
      }
      }

    echo 
    "<b>Ticket Number</b>: $ticketnum<br>";
    echo 
    "<b>Job Name</b>: $jobname<br>";
    echo 
    "<b>Job Description</b>: $jobdesc<br>";
    echo 
    "<b>Job Status</b>: $fontcolor $jobstatus $fontend<br>";
    echo 
    "<br><hr width=75%>"

    $i++; 


     
    ?>
                </div>
            </div>
        </li>

    </ul>

    <script type="text/javascript" src="js/script.js"></script>

    <script type="text/javascript">

    var parentAccordion=new TINY.accordion.slider("parentAccordion");
    parentAccordion.init("acc","h3",-1,-1);

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

    </script>
            
            
    <table width="90%" cellpadding="5" cellspacing="10" class="links" align="center">
    <tr>

    <td class="outer" width="20%" onClick="document.location.href='http://dhs-intranet:8081';" style="cursor:pointer;cursor:hand" onmouseover="style.backgroundColor='#6f9387';" onmouseout="style.backgroundColor='#e2ebe8'">
    <table align="center">
    <tr>
    <th>Helpdesk</th>
    </tr>
    <tr>
    <td align="center"><img src="http://www.edugeek.net/images/helpdesk.png" border="0"></td>
    </tr>
    </table>
    </td></a>

    <td class="outer" width="20%" onClick="document.location.href='#';" style="cursor:pointer;cursor:hand" onmouseover="style.backgroundColor='#6f9387';" onmouseout="style.backgroundColor='#e2ebe8'">
    <table align="center">
    <tr>
    <th>Booking System</th>
    </tr>
    <tr>
    <td align="center"><img src="http://www.edugeek.net/images/bookingsystem.png" border="0"></td>
    </tr>
    </table>
    </td>
    </td>

    </tr>
    </table>
            <br><br>
                
            <div id="footer">
            <?php echo '&copy; School '.date('Y').''?>
            </div>
            </div>
        </div>
    </div>

    </body>
    </html>
    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

    PHP Code:
                $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'];
                            } 
    Last edited by Flakes; 5th July 2011 at 03:36 PM.

  3. Thanks to Flakes from:

    MK-2 (5th July 2011)

  4. #3

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,837
    Thank Post
    517
    Thanked 2,478 Times in 1,921 Posts
    Blog Entries
    24
    Rep Power
    837

    Reply

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

    ie.
    PHP Code:
    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="<font color='green'>Open</font>";
          } 
          if (
    $status ==2) {
           
    $jobstatus="<font color='red'>Awaiting User Input</font>";
          } 
        
    $x++;
       } 
       echo 
    "<b>Ticket Number</b>: $ticketnum<br>"
       echo 
    "<b>Job Name</b>: $jobname<br>"
       echo 
    "<b>Job Description</b>: $jobdesc<br>"
       echo 
    "<b>Job Status</b>: $fontcolor$jobstatus$fontend<br>"
       echo 
    "<br><hr width=75%>";  

    This will then continue on if the condition is met.

  5. Thanks to localzuk from:

    MK-2 (5th July 2011)

  6. #4

    MK-2's Avatar
    Join Date
    Oct 2006
    Location
    Nottingham
    Posts
    3,237
    Thank Post
    149
    Thanked 581 Times in 307 Posts
    Blog Entries
    8
    Rep Power
    200
    Quote Originally Posted by localzuk View Post
    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

  7. #5
    Flakes's Avatar
    Join Date
    Nov 2009
    Location
    Newcastle
    Posts
    476
    Thank Post
    38
    Thanked 74 Times in 48 Posts
    Rep Power
    27
    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.

    PHP Code:
    echo "<b>Ticket Number</b>: $ticketnum<br>";
    echo 
    "<b>Job Name</b>: $jobname<br>";
    echo 
    "<b>Job Description</b>: $jobdesc<br>";
    echo 
    "<b>Job Status</b>: $fontcolor $jobstatus $fontend<br>";
    echo 
    "<br><hr width=75%>"
    can become

    PHP Code:
    echo "
    <b>Ticket Number</b>: 
    $ticketnum<br />
    <b>Job Name</b>: 
    $jobname<br />
    <b>Job Description</b>: 
    $jobdesc<br />
    <b>Job Status</b>: 
    $fontcolor $jobstatus $fontend<br />
    <br /><hr width=75%>"

    another warning <b> tags, <strong> 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.

  8. Thanks to Flakes from:

    MK-2 (6th July 2011)

  9. #6

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,837
    Thank Post
    517
    Thanked 2,478 Times in 1,921 Posts
    Blog Entries
    24
    Rep Power
    837
    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.

  10. Thanks to localzuk from:

    MK-2 (6th July 2011)

  11. #7

    MK-2's Avatar
    Join Date
    Oct 2006
    Location
    Nottingham
    Posts
    3,237
    Thank Post
    149
    Thanked 581 Times in 307 Posts
    Blog Entries
    8
    Rep Power
    200
    Quote Originally Posted by Flakes View Post
    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

SHARE:
+ Post New Thread

Similar Threads

  1. PHP - Form POST script
    By BarryWAaMC in forum Coding
    Replies: 9
    Last Post: 31st March 2010, 11:32 AM
  2. PHP script help
    By FN-GM in forum Web Development
    Replies: 18
    Last Post: 19th August 2008, 02:52 PM
  3. Loading .reg files in a startup script
    By Ric_ in forum Windows
    Replies: 7
    Last Post: 27th September 2005, 04:23 PM

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
  •