Jump to content
MakeWebGames

[v1] local school help


TheMafia!
 Share

Recommended Posts

hi I'm having problems with my local school

when someone starts a course and the time is over it starts going into minus

here is my local school

<?php
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm);
$h->menuarea();
switch ($_GET['view'])
{
   case 'info': info(); break;
   case 'currentusers': current_users(); break;
   case 'do': course_do(); break;
   default: course_index(); break;
}
function course_index()
{
   global $ir,$c,$userid;
   if ($ir['Course'] > 0)
   {
       $coursequery = "SELECT * FROM Courses WHERE cID = {$ir['Course']}";
       $courseresult = mysql_query("$coursequery");
       $course = mysql_fetch_array($courseresult);
       print "<center>Sorry you cannot start another course 
                until the currrent course you are doing is complete!

                Here if you course information:


       <table width='50%' border='1' class='coll' bgcolor='#303030'>
           <tr>
               <th colspan='2'>Course Information</th>
           </tr>
           <tr>
               <td width='30%'>Course Name:</td>
               <td>{$course['cNAME']}</td>
           </tr>
           <tr>
               <td>Course Time Left (Days):</td>
               <td>{$ir['CourseDays']}</td>
           </tr>
           <tr>
               <td>Course Description:</td>
               <td>{$course['cDESCRIPTION']}</td>
           </tr>
           <tr>
               <td>Course Type:</td>
               <td>{$course['cTYPE']}</td>
           </tr>
       </table>";
   }
   else
   {
   print "
   <center>
   <h4>Local School</h4>
   <hr color='black' width='50%'>


   <table width='50%' border='1' class='coll' bgcolor='#303030'>
       <tr>
           <th width='50%'>Course Name</th>
           <th width='50%'>Course Information</th>
       </tr>";
   $coursequery="SELECT * FROM Courses ORDER BY cTYPE ASC";
   $courseresult=mysql_query("$coursequery");
   while ($course=mysql_fetch_array($courseresult))
   {
       echo "
           <tr>
               <td>{$course['cNAME']}</td>
               <td>- [url='localschool.php?view=info&ID={$course[']Course Information[/url]</td>
           </tr>";
   }
}
print "</table>";
}
function info()
{
   global $ir,$c,$userid;
   $cinfoquery="SELECT * FROM Courses WHERE cID='{$_GET['ID']}'";
   $cinforesult=mysql_query("$cinfoquery");
   $cinfo=mysql_fetch_array($cinforesult);
   $userquery="SELECT * FROM users WHERE Course='{$cinfo['cID']}'";
   $user=mysql_query("$userquery");
   if (mysql_num_rows($user) == $cinfo['cMAXUSERS'])
   {
       $c = "<font color=red>".mysql_num_rows($user)."/{$cinfo['cMAXUSERS']}</font>";
   }
   else
   {
       $c = "".mysql_num_rows($user)."/{$cinfo['cMAXUSERS']}";
   }
   print "<center><h4>Course Information</h4>
            <hr color='black' width='50%'>
            <table width='50%' border='1' class='coll' bgcolor='#303030'>
                <tr colspan='4'>
                    <th colspan='4'>Information About Course: {$cinfo['cNAME']}</th>
                </tr>
                <tr>
                    <td>Name:</td>
                    <td>{$cinfo['cNAME']}</td>
                </tr>
                <tr>
                    <td>Type of course:</td>
                    <td>{$cinfo['cTYPE']}</td>
                </tr>
                <tr>
                    <td>Max Users:</td>
                    <td>$c</td>
                </tr>
                <tr>
                    <td>Cost:</td>
                    <td>{$cinfo['cCOST']}</td>
                </tr>
                <tr>
                    <td>Power Required:</td>
                    <td>{$cinfo['cPOWERR']}</td>
                </tr>
                <tr>
                    <td>Level Required:</td>
                    <td>{$cinfo['cLEVELR']}</td>
                </tr>
                <tr>
                    <td>Time Length (Days)</td>
                    <td>{$cinfo['cLENGTH']}</td>
                </tr>
                <tr colspan='2'>
                    <th colspan='2'>Course Description</th>
                </tr>
                <tr colspan='2'>
                    <td colspan='2'>[size="1"]{$cinfo['cDESCRIPTION']}[/size]</td>
                </tr>
                <tr>
                    <td>- <a href='localschool.php?view=currentusers&ID={$cinfo['cID']}'
                           style='color:steelblue;'>View users doing this course!</td>
                    <td>- <a href='localschool.php?view=do&ID={$cinfo['cID']}' 
                           style='color:steelblue;'>Do</td>
                </tr>
            </table>";
}
function current_users()
{
   global $c,$ir,$userid; 
   $coursequery="SELECT * FROM Courses 
                          WHERE cID='{$_GET['ID']}'";
   $courseresult=mysql_query("$coursequery");
   $course=mysql_fetch_array($courseresult);
   print "
   <center>
   <h4>Viewing users doing the course named: {$course['cNAME']}!";
   $userquery="SELECT * FROM users WHERE Course='{$_GET['ID']} 
                       ORDER BY userid ASC'";
   $userresult=mysql_query("$userquery");
   print "
   <table width='25%' border='1' bgcolor='#303030' class='coll'>
       <tr>
           <th>UserName</th>
       </tr>";
        if (mysql_num_rows($userresult) == 0)
       {
           echo "
               <tr>
                   <td>No users found doing this course!</td>
               </tr>";
       }
       else
       {
           while ($user=mysql_fetch_array($userresult))
           {
                echo "
                    <tr>
                        <td>- <a href='profile.php?u={$user['userid']}'>
                               {$user['username']}</a></td>
                    </tr>";
           }
       }
           print "</table>";
}
function course_do()
{
   global $c,$ir,$userid;
   if ($_GET['ID'] == "")
   {
       die ("Invalid course!");
   }
   if (!$_GET['ID'])
   {
       die ("Invalid course!");
   }
   $coursequery="SELECT * FROM Courses 
                          WHERE cID='{$_GET['ID']}'";
   $courseresult=mysql_query("$coursequery");
   $course=mysql_fetch_array($courseresult);
   $cdonequery = "SELECT * FROM CoursesDone
                          WHERE cdUSERID = $userid 
                          AND cdCOURSEID = '{$_GET['ID']}'";
   $cdoneresult = mysql_query("$cdonequery");
   if (mysql_num_rows($cdoneresult) > 0)
   {
       die ("You have already done this course!");
   }
   $userquery="SELECT * FROM users WHERE Course='{$_GET['ID']}'";
   $user=mysql_query("$userquery");
   print "<center>
            <h4>Do Course</h4>
            <hr color='black' width='50%'>";
   if (mysql_num_rows($user) == $course['cMAXUSERS'])
   {
       die ("This course has reached it's maximum 
               user capacity, please try another course!");
   }
   if ($ir['level'] < $course['cLEVELR'])
   {
       die ("You are not able to do this course as your level is too low!");
   }
   if ($ir['money'] < $course['cCOST'])
   {
       die ("You do not have enough money to start this course!");
   }
   elseif ($ir['energy'] < $course['cPOWERR'])
   {
       die ("You don't have enough power to do this course!");
   }
   elseif (mysql_num_rows($courseresult) == 0)
   {
   die ("Invalid course!");
   }
   else
   {
       $query="UPDATE users SET Course={$_GET['ID']},
                     CourseDays={$course['cLENGTH']}, 
                     energy=energy-{$course['cPOWERR']}, 
                     money=money-{$course['cCOST']}
                     WHERE userid = '$userid'";
       $result=mysql_query("$query");
       print "Congratulations, you have started the [b]{$course['cNAME']}[/b] 
                course, you will complete it is [b]{$course['cLENGTH']}[/b] days!";
   }
}
$h->endpage();
?>

 

can any body help me

Link to comment
Share on other sites

Re: [v1] local school help

heres my course cron

can you help?

<?php
require "global_func.php";
include "mysql.php";
global $c;
mysql_query("UPDATE users SET CourseDays=CourseDays-1 WHERE Course>0");
$userquery = "SELECT  * FROM users WHERE Course>0";
$userresult = mysql_query("$userquery") or die (mysql_error());
$user = mysql_fetch_array($userresult);
if ($user['CourseDays'] == 0)
{
$coursequery = "SELECT * FROM Courses WHERE cID='{$user['Course']}'";
$courseresult = mysql_query("$coursequery") or die (mysql_error());
$course = mysql_fetch_array($courseresult);
$updatequery = "UPDATE userstats SET 
                        intelligance=intelligance+'{$course['cINTEL']}', 
                        endurance=endurance+'{$course['cENDU']}', 
                        labor=labor+'{$course['MANL']}'";
$updateresult = mysql_query("$updatequery") or die (mysql_error());
$cdonequery = "INSERT INTO CoursesDone 
                       VALUES ('', '{$course['cID']}', '{$user['userid']}')";
$cdone = mysql_query("$cdonequery") or die (mysql_error());
event_add($user['userid'],"You completed the [b]{$course['cNAME']}[/b] course and gained.


[b]{$course['cINTEL']}[/b] Intelligence

[b]{$course['cENDU']}[/b] Endurence

[b]{$course['cMANL']}[/b] Manual Labor.


Also you may have unlocked some unqiue things within the game, look around the game see if there is anything new, the description of the course you just completed will give you a idea of what you just unlocked.",$c);
mysql_query("UPDATE users SET Course=0 
                    WHERE CourseDays=0 OR CourseDays<0");
}
print "Cron complete!";
?>
Link to comment
Share on other sites

Re: [v1] local school help

try

mysql_query("UPDATE users SET CourseDays=CourseDays-1 WHERE Course>0 AND CourseDays > 0");

if that don't work the waay your wanting..

You can aloways do this...

$set = sprintf("UPDATE users SET CourseDays = '%d' WHERE CourseDays < '%d' ",(0),(0));

mysql_query($set);

Link to comment
Share on other sites

Re: [v1] local school help

you dont understand,

 

do i replace the whole cron file with

mysql_query("UPDATE users SET CourseDays=CourseDays-1 WHERE Course>0 AND CourseDays > 0");

or do i change the file and ad

mysql_query("UPDATE users SET CourseDays=CourseDays-1 WHERE Course>0 AND CourseDays > 0");

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...