Jump to content
  • 0

Calling job/class table of sql via php code


Meister

Question


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

How to call class/job to show it on a page via php code.

$sql = blah ?

what's next i'm lost after it thanks!

Edited by emong
Link to comment
Share on other sites

5 answers to this question

Recommended Posts


  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3127
  • Reputation:   1617
  • Joined:  03/26/12
  • Last Seen:  

Are you using a CP? Flux has public functions available for this.

If you're coding this into a site yourself, you'll need a series of if{}elseif{} statements. You could do it via case, in a foreach, or while loop.. there's lots of different methods.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

Are you using a CP? Flux has public functions available for this.

If you're coding this into a site yourself, you'll need a series of if{}elseif{} statements. You could do it via case, in a foreach, or while loop.. there's lots of different methods.

I'm using flux cp can you show me how to do it? or an example of how to call a variable from mysql?

Link to comment
Share on other sites


  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3127
  • Reputation:   1617
  • Joined:  03/26/12
  • Last Seen:  

This is the function inside lib/Flux.php:

/**
 * Get the job class name from a job ID.
 *
 * @param int $id
 * @return mixed Job class or false.
 * @access public
 */
public static function getJobClass($id)
{
 $key   = "JobClasses.$id";
 $class = self::config($key);

 if ($class) {
  return $class;
 }
 else {
  return false;
 }
}

So for example:


$sth = $server->connection->getStatement("SELECT * FROM {$server->charMapDatabase}.char WHERE account_id = ?");
$sth->execute(array($session->account->account_id));
$charlist = $sth->fetchAll();
if(!$charlist){
 $charselect='No characters on account!';
} else {
 foreach($charlist as $char){
$charclass = getJobClass($char->class);
$charselect.= 'ID: '$char->char_id .' Name: '. $char->name .' Class: '. $charclass;
 }
}

On your page within theme, you would have:

<?php echo $charselect ?>

The above is an example and is not guaranteed to work, but it should... i think. Does that help?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  280
  • Topics Per Day:  0.06
  • Content Count:  841
  • Reputation:   17
  • Joined:  04/16/12
  • Last Seen:  

This is the function inside lib/Flux.php:

/**
 * Get the job class name from a job ID.
 *
 * @param int $id
 * @return mixed Job class or false.
 * @access public
 */
public static function getJobClass($id)
{
 $key   = "JobClasses.$id";
 $class = self::config($key);

 if ($class) {
  return $class;
 }
 else {
  return false;
 }
}

So for example:


$sth = $server->connection->getStatement("SELECT * FROM {$server->charMapDatabase}.char WHERE account_id = ?");
$sth->execute(array($session->account->account_id));
$charlist = $sth->fetchAll();
if(!$charlist){
 $charselect='No characters on account!';
} else {
 foreach($charlist as $char){
$charclass = getJobClass($char->class);
$charselect.= 'ID: '$char->char_id .' Name: '. $char->name .' Class: '. $charclass;
 }
}

On your page within theme, you would have:

<?php echo $charselect ?>

The above is an example and is not guaranteed to work, but it should... i think. Does that help?

Yes this help, but I'm confused on how to insert it here..


<?php if (!defined('FLUX_ROOT')) exit; ?>
<?php
/**
* ======================================
*  TOP pvp Ranking Base on Kills
*  Ranks are base on Player Kills ratio
* --------------------------------------
*  Author: "Gerome" John Gerome Baldonado
*  Email: [email protected]
*  http://rathena.org/board/user/715-gerome/
*  Requirements: Pvpladder Script by Annie.. or any Pvpladder Script
*/

$pvpladder = Flux::config('FluxTables.pvpladder');
$minimumkills = 1;    // Minimum Kills..
$player = array();
$minimumRank = 5;  // Minimim Player(s) that will Display. if the value is 3 it will display 1st - 3rd

$sql = "SELECT  `char`.`name` , `kills`, `streaks` FROM {$server->charMapDatabase}.`char` JOIN $pvpladder ON $pvpladder.char_id = `char`.char_id WHERE `kills` > $minimumkills  ORDER BY `kills` DESC LIMIT 5 ";
$sth = $server->connection->getStatement($sql),;
$sth->execute();

$rankings= $sth->fetchAll();

$x = 1;
foreach($rankings as $rank):
$player['name'][$x] = $rank->name;
$player['kills'][$x] = $rank->kills;
$player['streaks'][$x] = $rank->streaks;
$x+=1;
endforeach;
?>

Cause there will be conflicts. What to do? do i need to redo it?

Link to comment
Share on other sites


  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3127
  • Reputation:   1617
  • Joined:  03/26/12
  • Last Seen:  

Since you're already calling data from the char table, you'd just need to shove `char`.`class` into the SQL statement.

In your foreach you'd add $player['class'][$x] = getJobClass($rank->class);

Link to comment
Share on other sites

×
×
  • Create New...