Jump to content

[SOLVED] Varible Comparison.


overlordofevil

Recommended Posts

Hello All.

 

I am trying to get data from a table based on a variable that is passed form another page. What I am working on is a character DB for a game and  The way it works is i have a main page that pulls character information and then I use include for the other scripts to show current and available skills that the player can purchase.

 

<?php
include("misc.inc");
include ("functions.inc");

$pname = $_POST ['pname'];
$firstname = $_POST ['firstname'];
$lastname = $_POST ['lastname'];
$raceName = $_POST ['raceName'];
$subrace= $_POST ['subrace'];
$className = $_POST ['className'];

$uid = getplayersid($pname);
$wchar = getwchar($uid);
$raceid = getraceid($raceName);
$classid = getclassid($className);
$xp = 65;
$build = calc_build($xp);
$level = calc_level($xp);
$body = getbody($level, $classid, $raceid);

echo "<table border='1' cellspacing='15'>";
echo "<tr><td colspan='12'><hr></td></tr>";
echo "<tr><td>Players Name</td><td>First</td><td>Last</td><td>Race</td><td>Subrace</td><td>Class</td><td>Level</td><td>XP</td><td>Build</td><td>Body</td><td>Character</td></tr>";
echo "<tr>\n";
echo "<td>$pname</td><td>$firstname</td><td>$lastname</td>\n";
echo "<td>$raceName, $raceid</td><td>$subrace</td><td>$className, $classid </td>\n";
echo "<td>$level</td><td>$xp</td><td>$build</td><td>$body</td><td>$wchar</td>\n";
echo "<tr><td colspan='12'><hr></td></tr>\n";
echo "</table>\n";

include ("skilltest/available.php");
include ("skilltest/current.php");
?>

 

So all the primary code and variables are set here. and it pulls the info in correctly, So what is suppose to happen is based on the variable $classid the included file "available.php" is suppose to pull data from another table that has all the skills and show the proper "cost" for the skill.

 

<?php
//script that pulls skill info

$query = "SELECT * FROM skill_info where skillType = '3'";
$result = mysql_query($query) or die (mysql_error());

echo "<table border='0'>\n";
while ($row = mysql_fetch_array($result))
  {
  extract($row);
  echo "<tr><td>\n";
  if($classid == '1')
  {
  $cost = $FCost;
  }
elseif($classid == '2')
  {
  $cost = $RCost;
  }
elseif($classid == '3')
  {
  $cost = $SCost;
  }
elseif($classid == '4')
  {
  $cost = $TCost;
  }
  $preq= explode(",",$prereq);
  foreach ($preq as $value)
  {
  if ($value == $n)
  {
  echo "<a href='addskill.php?action=add&id=$skillID'>$skillName</a> ($cost)";	
  }
  else
  {
  $query1 = "SELECT * FROM skill1 where type = '3'";
  $result1 = mysql_query($query1) or die (mysql_error());
  while ($row1 = mysql_fetch_array($result1))
  {
  extract($row1);
  if ($value == $skill)
  {
  echo "<a href='addskill.php?action=add&id=$skillID'>$skillName</a> ($cost)";	
  }
  }
  }
  }
  echo "</td></tr>\n";
  }

echo "</table>\n";
?>

 

So I tried to use an if statement to have it set the cost but it always defaults to the first one. I have tried changing up the order that didn't help I tried having the if statement in different ways

 

  if($classid = '1')

  if($classid == 1)

  if($classid = 1)

 

but nothing has allowed me to pull the data in correctly. so If anyone has an idea of how to pull the data I need I would really appreciate it.

 

Link to comment
https://forums.phpfreaks.com/topic/109645-solved-varible-comparison/
Share on other sites

I have debugged it and tested to make sure all the data is pulled correctly and it is. If I try to get the data just based on the Skill Info it all comes up but the "Cost" info is what is defaulting to the first item in the if statement.

 

sorry not sure what you're suggesting I look at, can you explain a bit more.

My code will simply dump the data from the table to the browser in it's raw form.

 

I haven't bothered seeing if there's a problem in your code... you really should tabulate your nested conditional and loop statements

 


while ( this ) {

    if ( is ) {

        foreach ( so much ) {

        }

        if ( easier to ) {

        }

    } elseif ( read ) {


    }

}

ok fair enough on the formating f the code I will make sure to format it for easier reading in the future. :)

 

As for the suggestion of the debugging I put your code into my script and it pulls out what is in the table.

Array

(

    [skillID] => 17

    [skillName] => Archery

    [skillType] => 3

    [FCost] => 6

    [RCost] => 10

    [TCost] => 12

    [sCost] => 15

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 18

    [skillName] => One Handed Blunt

    [skillType] => 3

    [FCost] => 3

    [RCost] => 4

    [TCost] => 5

    [sCost] => 8

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 19

    [skillName] => One Handed Edged

    [skillType] => 3

    [FCost] => 5

    [RCost] => 5

    [TCost] => 7

    [sCost] => 10

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 20

    [skillName] => Polearm

    [skillType] => 3

    [FCost] => 8

    [RCost] => 10

    [TCost] => 10

    [sCost] => 12

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 21

    [skillName] => Shield

    [skillType] => 3

    [FCost] => 5

    [RCost] => 10

    [TCost] => 7

    [sCost] => 15

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 22

    [skillName] => Small Weapon

    [skillType] => 3

    [FCost] => 2

    [RCost] => 2

    [TCost] => 2

    [sCost] => 2

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 23

    [skillName] => Staff

    [skillType] => 3

    [FCost] => 4

    [RCost] => 4

    [TCost] => 4

    [sCost] => 4

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 24

    [skillName] => Thrown Weapon

    [skillType] => 3

    [FCost] => 4

    [RCost] => 4

    [TCost] => 4

    [sCost] => 4

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 25

    [skillName] => Two Handed Blunt

    [skillType] => 3

    [FCost] => 6

    [RCost] => 8

    [TCost] => 8

    [sCost] => 12

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 26

    [skillName] => Two Handed Sword

    [skillType] => 3

    [FCost] => 8

    [RCost] => 12

    [TCost] => 12

    [sCost] => 16

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 27

    [skillName] => Florentine

    [skillType] => 3

    [FCost] => 6

    [RCost] => 6

    [TCost] => 8

    [sCost] => 12

    [prereq] => 17,18,19,20,21,22,30,31

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 28

    [skillName] => Style Master

    [skillType] => 3

    [FCost] => 10

    [RCost] => 15

    [TCost] => 15

    [sCost] => 20

    [prereq] => 17,18,19,20,22,30,31

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 29

    [skillName] => Two Weapons

    [skillType] => 3

    [FCost] => 2

    [RCost] => 4

    [TCost] => 4

    [sCost] => 4

    [prereq] => 27

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 30

    [skillName] => Weapon Master

    [skillType] => 3

    [FCost] => 15

    [RCost] => 18

    [TCost] => 18

    [sCost] => 20

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 31

    [skillName] => One Handed Weapon Master

    [skillType] => 3

    [FCost] => 8

    [RCost] => 10

    [TCost] => 10

    [sCost] => 14

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 32

    [skillName] => Two Handed Weapon Master

    [skillType] => 3

    [FCost] => 12

    [RCost] => 14

    [TCost] => 14

    [sCost] => 18

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

Array

(

    [skillID] => 33

    [skillName] => Wear Extra Armor

    [skillType] => 3

    [FCost] => 2

    [RCost] => 2

    [TCost] => 2

    [sCost] => 4

    [prereq] => 0

    [chapterID] => 0

    [regionID] => 0

)

 

I will add parts of my script to see what happens and post more in a bit.

One glaring error that I see is that you have your functions and misc files as .inc, instead of .php.  If someone found that out, the server would display it as plain text.  Change them to functions.inc.php if you want, but make sure it has a .php ending.

ok thanks for the info I think I found the error. I thought the variables were transferring but they weren't so I got it fixed now.

 

As for the .inc files this is all on a test server so i can make sure it all works but thanks for pointing out the security hole, I will fix that asap.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.