Hiya DaniWeb members,
Before starting it's not basic $variables I need help with.
I've been working on a project lately for a Minecraft Server website and this project will work alongside the MCMMO plugin.
Most of it works but I would like some help/advise on how to turn
$nextLevel = $playerSkills[$playerSkillsKeys[$i]]."Level" + 1;
so when this is executed it will currently be dislayed as <text>Level
I would like to have it be turned into $<text>Level and then echo out the value of $<text>Level
Please see the code snippit below for a overview.
Thank you.
<?php
include_once "config.php";
$player = "KingGold171";
//get a player's ID from their name
$sql_getPlayerIdFromName = "SELECT id FROM mcmmo_users WHERE user LIKE '$player'";
$r_getPlayerIdFromName = mysqli_query($con, $sql_getPlayerIdFromName);
while ($row = mysqli_fetch_object($r_getPlayerIdFromName))
{
$playerID = $row->id;
}
echo $playerID ;
//get a player's skills form their ID
$sql_getPlayerStats = "SELECT acrobatics,alchemy,archery,axes,excavation,fishing,herbalism,mining,repair,swords,taming,unarmed,woodcutting FROM mcmmo_skills WHERE user_id = $playerID;";
$r_getPlayerStats = mysqli_query($con, $sql_getPlayerStats);
while ($row = mysqli_fetch_object($r_getPlayerStats))
{
$playerSkills = (array) $row;
}
$playerSkills = array_slice($playerSkills, 0);
$skillNames = array(
"acrobatics",
"alchemy",
"archery",
"axes",
"excavation",
"fishing",
"herbalism",
"mining",
"repair",
"swords",
"taming",
"unarmed",
"woodcutting",
);
$playerSkillsKeys = array_keys($playerSkills);
$SkillNamesKeys = array_keys($skillNames) ;
$query = mysqli_query($con, "SELECT mcmmo_users.user, mcmmo_skills.taming, mcmmo_skills.mining, mcmmo_skills.woodcutting, mcmmo_skills.repair, mcmmo_skills.unarmed, mcmmo_skills.alchemy, mcmmo_skills.herbalism, mcmmo_skills.excavation, mcmmo_skills.archery, mcmmo_skills.swords, mcmmo_skills.axes, mcmmo_skills.acrobatics, mcmmo_skills.fishing FROM mcmmo_users INNER JOIN mcmmo_skills ON mcmmo_users.id=mcmmo_skills.user_id WHERE mcmmo_users.user='$player' ");
$num_url = mysqli_num_rows($query);
while ($obj = mysqli_fetch_object($query)) {
$acrobaticsLevel = $obj->acrobatics;
$alchemyLevel = $obj->alchemy;
$archeryLevel = $obj->archery;
$axesLevel = $obj->axes;
$excavationLevel = $obj->excavation;
$fishingLevel = $obj->fishing;
$herbalismLevel = $obj->herbalism;
$miningLevel = $obj->mining;
$repairLevel = $obj->repair;
$swordsLevel = $obj->swords;
$tamingLevel = $obj->taming;
$unarmedLevel = $obj->unarmed;
$woodcuttingLevel = $obj->woodcutting;
}
$query2 = mysqli_query($con, "SELECT mcmmo_users.user, mcmmo_experience.taming, mcmmo_experience.mining, mcmmo_experience.woodcutting, mcmmo_experience.repair, mcmmo_experience.unarmed, mcmmo_experience.alchemy, mcmmo_experience.herbalism, mcmmo_experience.excavation, mcmmo_experience.archery, mcmmo_experience.swords, mcmmo_experience.axes, mcmmo_experience.acrobatics, mcmmo_experience.fishing FROM mcmmo_users INNER JOIN mcmmo_experience ON mcmmo_users.id=mcmmo_experience.user_id WHERE mcmmo_users.user='$player' ");
$num_url = mysqli_num_rows($query2);
while ($obj = mysqli_fetch_object($query2)) {
$acrobaticsExp = $obj->acrobatics;
$alchemyExp = $obj->alchemy;
$archeryExp = $obj->archery;
$axesExp = $obj->axes;
$excavationExp = $obj->excavation;
$fishingExp = $obj->fishing;
$herbalismExp = $obj->herbalism;
$miningExp = $obj->mining;
$repairExp = $obj->repair;
$swordsExp = $obj->swords;
$tamingExp = $obj->taming;
$unarmedExp = $obj->unarmed;
$woodcuttingExp = $obj->woodcutting;
}
for($i = 0; $i < sizeof($playerSkills); $i++){
//just to make it a bit clearer
echo "<br />" . $skillNames[$skillNamesKeys[$i]] ;
$nextLevel = $playerSkills[$playerSkillsKeys[$i]]."Level" + 1;
echo "<br />" . $nextLevel ;
$getExp = mysqli_query($con, "SELECT total_exp FROM mcmmo_levels WHERE id = '$nextLevel';");
$result = mysqli_num_rows($getExp);
while ($obj = mysqli_fetch_object($getExp)) {
$playerSkills."TotalExp" == $obj->total_exp;
}
if ($nextLevel >=1001)
{
echo "The MCMMO cap's at 1000";
}
else
{
$percent = $skillNames[$SkillNamesKeys[$i]]."Exp" / $skillNames[$SkillNamesKeys[$i]]."TotalExp";
$percent1 = $percent * 100;
//===DEBUG===
echo "<br />Required exp:" . $skillNames[$SkillNamesKeys[$i]] ."TotalExp";
echo "<br />Current exp:" . $$skillNames[$SkillNamesKeys[$i]] ."Exp";
echo "<br />current / required:" . $percent;
echo "<br />* 100:" . $percent1;
//=== END DEBUG===
$arr1 = str_split($percent1);
$pb = $arr1[0] . $arr1[1] . $arr1[2] . $arr1[3];
echo "<div id='page-wrap'>";
// $skillName = ucfirst($SkillNamesKeys[$i]); //ucfirst() = first letter uppercase
echo "<h3> Current " . $skillNames[$SkillNamesKeys[$i]] . " Level: " . $playerSkills[$playerSkillsKeys[$i]] . "</h3>" ;
echo "<h2> Next " . $skillNames[$SkillNamesKeys[$i]] . " Level: " . $nextLevel. "</h2>" ;
echo "<div class='meter'>";
echo "<span style='width:" . $pb . "%>";
echo "<p>";
echo "<strong>";
echo "<span style='color:green'>";
echo $playerSkills[$playerSkillsKeys[$i]]."Exp" ;
echo "</span>";
echo "</strong>";
echo "</p>";
echo "</span>";
echo "</div>";
}
}
?>