Help please

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Help please

Post by pretender5552 »

I got this code and I know this is along the same lines as how I want to have mine set up, the problem is I can't really get it as it is so different then what I have seen here, can anyone walk me through it and explain how it comes together.

Code: Select all

<?php
	include("includes/config.php");
	include("includes/process.php");
	include("css/stylesheet.php");
?>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
	
	<tr>
    	<td valign="top"><?php include("header.php"); ?></td>
  	</tr>
	
	
	<tr>
	<td>
	

	</td>
	</tr>
	
</table>

<style type="text/css">
<!--
body {
	margin-left: 00px;
	margin-top: 00px;
	margin-right: 00px;
	margin-bottom: 00px;
}
-->
</style>
<script>
function test()
{
//new Dialog().showMessage('Dialog', document.getElementById('prepid1').getValue());
//document.getElementById('prepid1').setValue(document.getElementById('prepid').getValue());
//document.getElementById('JobsForm').submit();
}
</script>
<link href="css/stylesheet.css" rel="stylesheet" type="text/css"/>
<title><?php echo($application_name)?></title>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
  
  <tr>
    <td align="center" valign="top" class="page_bg">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="9" colspan="4" align="center" valign="middle"></td>
      </tr>
	  
	   <?php
	if($error!="")
	{
	?>
	<tr>
	<td valign="top" colspan="4"><?php echo $err = ErrorMessage($error);?></td>
	</tr>
	<?php
	}
	?>
	  
	
      <tr>
        <td colspan="4" ></td>
      </tr>
     
      
      
      
      <tr>
        <td align="left"  > </td>
        <td align="left" class="txt_3" > </td>
        <td align="left" class="txt_3" >Job List</td>
        <td align="left" class="txt_3" >
		<?php
		$level = $user["level"];
		$nextLevelRow = mysql_fetch_array(db_execute_return("Select level from jobs where level>".$level." Order by level DESC Limit 1;"));
	$nextLevel = $nextLevelRow["level"];
	
		?>
		<div align="right"><span class="txt_8"></span> </div></td>
        </tr>
      <tr>
        <td colspan="2" ></td>
        <td ></td>
        <td ></td>
        </tr>
      <tr>
        <td colspan="4" align="left" valign="top" ><table width="100%" border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td colspan="3" align="left" valign="middle" class="txt_7"> </td>
            </tr>
          <tr>
            <td colspan="3" align="center"valign="MIDDLE" class="heading_job_bg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="2%"> </td>
                <td width="28%" align="left" valign="middle" class="txt_9">Description / Payout</td>
                <td width="45%" valign="middle" class="txt_9">Job Requirements </td>
                <td width="25%" valign="middle" class="txt_9">Action</td>
              </tr>
            </table>
              <br />            </tr>
          
		  
		  
		  
		  
		  <tr>
            <td colspan="3" align="left" valign="middle" class="txt_7">
			
			<form id="JobsForm" name="JobsForm" method="post" action="">
			<input type="hidden" name="JobPage"  id="JobPage" value="1" />
				<input type="hidden" name="JobId"  id="JobId" value="0" />
				
				<input type="hidden" name="EnergyRequired"  id="EnergyRequired" value="0" />
				<input type="hidden" name="CourtRequired"  id="CourtRequired" value="0" />
				<input type="hidden" name="ExperienceGain"  id="ExperienceGain" value="0" />
				<input type="hidden" name="PayoutStart"  id="PayoutStart" value="0" />
				<input type="hidden" name="PayoutEnd"  id="PayoutEnd" value="0" />
				<input type="hidden" name="goodwill" id="goodwill" value="0" />
				<input type="hidden" name="prepid1" id="prepid1" value="0"  />
				<input type="hidden" name="prep_quantity" id="prep_quantity" value="0" />
				
			<?php
		  	$count=0;
			//$level = 4;
			
		  $result = db_execute_return("Select * from jobs where level<= ".$level." order by level DESC;");
				while($row = mysql_fetch_array($result))
				{
					$name=$row["name"];
					$desc=$row["description"];
					$payout_start=$row["payout_start"];
					$payout_end=$row["payout_end"];
					$experience=$row["experience"];
					$energy_required=$row["energy_required"];
					$group_required=$row["group_required"];
		  			$group_goodwill_points = $row["goodwill_points"];
					
			
		  ?>
			
				
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<?php
			if($count>0)
			{
			?>
			<tr>
            <td colspan="4" align="left" valign="middle"></td>
            </tr>
		  <?php
		  }
		  ?>
              <tr>
                <td width="4" height="22"> </td>
                <td width="208" class="txt_10"><?php echo $name;?></td>
                <td class="farhan">Required:</td><td width="215" rowspan="2" class="txt_10" align="left">
				<?php
				$prepflag = 0 ;
				$result2 = db_execute_return("SELECT weapons.name,weapons.image_small,jobs_requirement.quantity,`jobs_requirement`.item_type FROM `jobs_requirement`,`weapons` WHERE `jobs_requirement`.item_id = `weapons`.id and `jobs_requirement`.job_id = ".$row["id"]." and `jobs_requirement`.item_type = 'weapon' ");
					while($row2 = mysql_fetch_array($result2))
					{
					
					echo '<span style="font-size:9px;">'.$row2["quantity"].' x </span>';
					
					?>
					
				<img src="<?php echo $server_url.'images/weapons/'.$row2["image_small"];?>" title="<?php echo $row2["quantity"].' '.$row2["name"];?>" width="30" />
				<?php
			  }
			  if(db_execute_count("SELECT job_prep.name, job_prep.image, 		jobs_requirement.quantity
						FROM `jobs_requirement` , `job_prep`
						WHERE `jobs_requirement`.item_id = `job_prep`.id
						AND `jobs_requirement`.job_id = '".$row["id"]."'
						AND `jobs_requirement`.item_type = 'job_prep';") > 0)
			  {
			  $prepflag = 1;
			  $prepImage = mysql_fetch_assoc(db_execute_return("SELECT job_prep.id,job_prep.name, job_prep.image, 		jobs_requirement.quantity
						FROM `jobs_requirement` , `job_prep`
						WHERE `jobs_requirement`.item_id = `job_prep`.id
						AND `jobs_requirement`.job_id = '".$row["id"]."'
						AND `jobs_requirement`.item_type = 'job_prep';"));
			  		
						echo 'Prep req. <span style="font-size:9px;">'.$prepImage["quantity"].'</span>';
				?>
			  <img src="<?php echo $server_url.'images/job_prep/'.$prepImage["image"];?>" title="<?php echo $prepImage["quantity"].' '.$prepImage["name"];?>" width="30" />
					<?php
					}
					?>
			  				</td>
                <td width="189" rowspan="2" align="center"><table width="70%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td valign="middle" > <div align="center"> <span class="jobs_bttn_bg" >
          <?php 
		  	if($prepflag == 1)
			{
		  ?>
				<input name="DoJob" id="DoJob" type="submit" class="button_silver" value="Do This Job!"  
				onclick="document.getElementById('JobId').setValue(<?php echo $row["id"];?>	);document.getElementById('EnergyRequired').setValue(<?php echo $energy_required;?>);document.getElementById('CourtRequired').setValue(<?php echo $group_required;?>);document.getElementById('ExperienceGain').setValue(<?php echo $experience;?>);document.getElementById('PayoutStart').setValue(<?php echo $payout_start;?>);document.getElementById('PayoutEnd').setValue(<?php echo $payout_end;?>);document.getElementById('goodwill').setValue('<?php echo $group_goodwill_points;?>');document.getElementById('prepid1').setValue(<?php echo $prepImage["id"];?>);document.getElementById('prep_quantity').setValue('<?php echo $prepImage["quantity"];?>');" />
			<?php
			}
			else
			{
			?>
				<input name="DoJob" id="DoJob" type="submit" class="button_silver" value="Do This Job!"  onclick="document.getElementById('JobId').setValue(<?php echo $row["id"];?>);document.getElementById('EnergyRequired').setValue(<?php echo $energy_required;?>);document.getElementById('CourtRequired').setValue(<?php echo $group_required;?>);document.getElementById('ExperienceGain').setValue(<?php echo $experience;?>);document.getElementById('PayoutStart').setValue(<?php echo $payout_start;?>);document.getElementById('PayoutEnd').setValue(<?php echo $payout_end;?>);document.getElementById('goodwill').setValue(<?php echo $group_goodwill_points;?>);" />
		  <?php	
			}
		  ?>
		  
          </span> </div></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td> </td>
                <td class="txt_10"><span class="txt_m">Payout: $<?php echo $payout_start;?> - $<?php echo $payout_end;?></span></td>
                <td width="140" class="txt_12">Energy: <?php echo $energy_required;?>
				<br />
                          <span class="txt_1">
<?php echo($favorpoints_name)?>: <?php echo $group_goodwill_points;?></span></td>
				</tr>
              
			  
			  <tr>
                <td> </td>
                <td class="txt_10"><span class="txt_1">Experience: +<?php echo $experience;?><br />
                </span></td>
             <td colspan="2" class="txt_10"> </td>
                <td> </td>
              </tr>
			  <tr>
            <td colspan="5" align="left" valign="middle" class="line_sep"> </td><br>
            </tr>
            </table>
			<?php
		  $count++;
		  }
		  
	?>
			</form>						</td>
          </tr>
        
</table>          </td>
        </tr>
      <tr>
        <td colspan="4" align="center" valign="middle" ></td>
      </tr>
      <tr>
        <td colspan="4" align="center" valign="middle" ></td>
      </tr>
      
      <tr>
        <td colspan="4" align="left" valign="middle" style="padding-left:8px;" class="txt_3" >Job-Prep</td>
      </tr>
      <tr>
          <td colspan="4" align="center" valign="top class="heading_job_bg" > </td>
      </tr>
      <tr>
        <td colspan="4" align="center" valign="middle" >
				
			<?php
		  	$count=0;
			//$level = 4;
			
		  $result = db_execute_return("Select * from job_prep where level<= ".$level." order by level DESC;");
				$t = mysql_num_rows($result);
				if($t > 0)
				{
				while($row = mysql_fetch_array($result))
				{
					$name=$row["name"];
					$image = $row["image"];
					$desc=$row["description"];
					$payout_start=$row["payout_start"];
					$payout_end=$row["payout_end"];
					$experience=$row["experience"];
					$energy_required=$row["energy_required"];
					$group_required=$row["group_required"];
		  			
			
		  ?>
		  
		  <form id="prepForm<?php echo $row["id"];?>" name="prepForm<?php echo $row["id"];?>" method="post" action="">
			<input type="hidden" name="JobPrep"  id="JobPrep" value="1" />
				<input type="hidden" name="JobId"  id="JobId" value="<?php echo $row["id"];?>" />
				
				<input type="hidden" name="EnergyRequired"  id="EnergyRequired" value="<?php echo $energy_required;?>" />
				
				<input type="hidden" name="ExperienceGain"  id="ExperienceGain" value="<?php echo $experience;?>" />
				<input type="hidden" name="PayoutStart"  id="PayoutStart" value="<?php echo $payout_start;?>" />
				<input type="hidden" name="PayoutEnd"  id="PayoutEnd" value="<?php echo $payout_end;?>" />
		
		  
		      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <!--DWLayoutTable-->
                <tr> 
                  <td colspan="4" align="left" valign="middle"> </td>
                  <td> </td>
                </tr>
                <tr> 
                  <td width="4" height="22"> </td>
                  <td width="209" class="txt_10"><?php echo $name;?></td>
                  <td class="farhan">Required:</td>
                  <td width="215" rowspan="2" class="txt_11" align="left"> 
                    <?php
				$result2 = db_execute_return("SELECT distinct weapons.name,weapons.image_small,jobs_requirement.quantity FROM `jobs_requirement`,`weapons`,`job_prep` WHERE `jobs_requirement`.item_id = `weapons`.id and `jobs_requirement`.job_id = ".$row["id"]." and `jobs_requirement`.item_type = 'job_prep'");
					while($row2 = mysql_fetch_array($result2))
					{
					echo '<span style="font-size:9px;">'.$row2["quantity"].' x </span>';
					?>
                    <img src="<?php echo $server_url.'images/weapons/'.$row2["image_small"];?>" title="<?php echo $row2["quantity"].' '.$row2["name"];?>" width="30" /> 
                    <?php
				  }
			    	$owned = GetPrepQuantityUser($user_id,$row["id"]);
				?>
                  </td>
                  <td width="189" rowspan="2" align="center"> <div align="left" style="padding-left:8px; color:#FFFFFF;"><strong>Owned: 
                      <?php echo $owned;?></strong></div>
                    <table width="70%" border="0" cellspacing="0" cellpadding="0">
                      <tr> 
                        <td valign="middle" > <div align="center"> <span class="jobs_bttn_bg" > 
                            <?php 
		  	
				echo '<input name="DoJob" id="DoJob" type="submit" class="button_silver" value="Do This Job!"  onclick="document.getElementById(\'JobId\').setValue('.$row["id"].');document.getElementById(\'EnergyRequired\').setValue('.$energy_required.');document.getElementById(\'CourtRequired\').setValue('.$group_required.');document.getElementById(\'ExperienceGain\').setValue('.$experience.');document.getElementById(\'PayoutStart\').setValue('.$payout_start.');document.getElementById(\'PayoutEnd\').setValue('.$payout_end.');" />';

		  ?>
                            </span> </div></td>
                      </tr>
                    </table></td>
                </tr>
                <tr> 
                  <td> </td>
                  <td class="txt_10"><span class="txt_m">Payout: $<?php echo $payout_start;?> 
                    - $<?php echo $payout_end;?></span></td>
                  <td width="140" class="txt_12">Energy: <?php echo $energy_required;?> 
                    <br /> </td>
                </tr>
                <tr> 
                  <td height="19"> </td>
                  <td valign="top" class="txt_10"><span class="txt_1">Experience: 
                    +<?php echo $experience;?></span></td>
                  <td colspan="2" class="txt_10"> </td>
                  <td> </td>
                </tr>
                <tr> 
                  <td> </td>
                  <td class="txt_10"><span class="txt_1"><img src="<?php echo $server_url.'images/job_prep/'.$image;?>" title="<?php echo $name;?>" width="30" /><br />
                    </span></td>
                  <td colspan="2" class="txt_10"> </td>
                  <td> </td>
                </tr>
                <tr> 
                  <td colspan="5" align="left" valign="middle" class="line_sep"> </td>
                </tr>
              </table>
			<?php
		 
		  
		  
		  ?>
		  </form>
		  <?php
		  }
		  }
		  
	?>
						</td>
      </tr>
      <tr>
       <td colspan="4" align="center" valign="middle" ><?php include_once("footer.php");?></td>
      </tr>
	  <tr><td colspan="4"> </td></tr>
 </table>
 </td>
  </tr>
</table>
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Help please

Post by Jackolantern »

Those are just include files. They read the contents of another file into yours. The first word in those include paths are the folders PHP is looking in, and the rest is the file name.

EDIT: D'oh! First issue I have had with browsing the web on my iPod Touch. For some reason the rest of the script did not show up for me.
The indelible lord of tl;dr
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: Help please

Post by pretender5552 »

What about this part.

Code: Select all

<input name="DoJob" id="DoJob" type="submit" class="button_silver" value="Do This Job!"  onclick="document.getElementById('JobId').setValue(<?php echo $row["id"];?>);document.getElementById('EnergyRequired').setValue(<?php echo $energy_required;?>);document.getElementById('CourtRequired').setValue(<?php echo $group_required;?>);document.getElementById('ExperienceGain').setValue(<?php echo $experience;?>);document.getElementById('PayoutStart').setValue(<?php echo $payout_start;?>);document.getElementById('PayoutEnd').setValue(<?php echo $payout_end;?>);document.getElementById('goodwill').setValue(<?php echo $group_goodwill_points;?>);" />
Could I use this instead of the href I was using and how would I make that work, meaning adding in the experience, and money they gain?
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Help please

Post by SpiritWebb »

Doing the same thing. The first column is grabbing the table name in the database, and the second part is displaying the value in that table.

Code: Select all

getElementId('EnergyRequired') table name 
php echo $energy_required is the value in that table for that element
Image

Image
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Help please

Post by Jackolantern »

D'oh! I was accessing this thread from my iPod Touch and I did not get the scroll bars to see the rest of the script LOL. I was wondering why you were asking about include files, which are used liberally through the video tutorials haha.

As far as the question goes, that is actually not technically PHP (although it uses some PHP in there to dynamically add the values that are coming from the server with the original page). It appears that those segments are there to update a display with the values of the player's experience, money and other stats. Basically it is trying to get those stats into the page's Javascript so that the page can do dynamic client-side effects with it, such as create stat bars, or something else of that type. Basically, that part of the script will be visible on the client-side if the user looks at the page source, but those PHP tags sprinkled through it will be replaced with the actual values generated on the server. That way the Javascript will have the right values loaded in and can do whatever dynamic effects it wants.

For some more info on the differences between client-side scripting (Javascript only, don't mind any documents mentioning any others) and server-side scripting (PHP in our case, but there are hundreds of others), you can check out this document. Sadly, I could not find a more recent description that adds AJAX to the discussion, but that is not important at this point.
The indelible lord of tl;dr
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: Help please

Post by pretender5552 »

Sorry I must be slow right now, because I still don't know exactly how to use it. How would that make it possible to add the experience, and money to the character while taking away the energy, and how would I make it specific to the job I want it to do, as there will be several in the table.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Help please

Post by Jackolantern »

Ohh, then that is not what that segment of code did. Or if it did, it shouldn't have done it that way (although I am almost possible that code block you called attention to was only about displaying stats on the page). Javascript is not used in the core mechanics of adding things or taking things from the player because it is not secure, and players can put whatever values they want into it.

I guess I don't know what the problem is. If you want to take energy away and reward money and experience, that seems like it should be quite simple: read values from the database, alter those values, and then insert the altered values, all in PHP.
The indelible lord of tl;dr
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: Help please

Post by pretender5552 »

Code: Select all

$newenergy = $playerinfo3['energy'] - $jobsinfo3['energy'];
$updateenergy="update player set energy='$newenergy' where name='Bryan'";
  mysql_query($updateenergy) or die (mysql_error());

$newcredit = $playerinfo3['credit'] + $rand1;
$updatecredit="update player set credit='$newcredit' where name='Bryan'";
  mysql_query($updatecredit) or die (mysql_error());

$newexperience = $playerinfo3['experience'] + $jobsinfo3['experience'];
$updateexperience="update player set experience='$newexperience' where name='Bryan'";
  mysql_query($updateexperience) or die (mysql_error());
So I can just put this with the onclick=
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Help please

Post by Jackolantern »

No, "onclick=" is Javascript, which is client-side programming. I highly suggest you read the link I posted above about client-side vs. server-side scripting. You will not be attaching any PHP code (uses "$" on variables, interacts with the database, etc.) to buttons in the HTML, or anything like that. PHP is often just put into the page to run on its own as the page is being processed by the server. Javascript is the one that has to be "hooked-up" into the page somehow (either through "onblank=" attributes, or through events), because it runs in the browser after the page has already been created.

If you want to execute that line of code, you simply put it in your page in PHP tags <?php ?>. It will run as the page is being requested by the user. You cannot make PHP code run from the user pressing a button unless you either: A. have the button take the user to a new PHP webpage where the script will run as the page is being requested, or B. use AJAX to make the button click call another PHP script. For now I would not worry about B.
The indelible lord of tl;dr
Post Reply

Return to “Advanced Help and Support”