[PHP Help gone wrong somewhere but where :(

Experienced Elementalist
Joined
Apr 13, 2010
Messages
280
Reaction score
18
PHP:
<?php
	$job = mysql_query("SELECT job FROM `characters` WHERE gm=0") or die(mysql_error());
	if($job==500 || $job==510){
	echo 'GM';
	}elseif($job==000){
	echo 'Beginner';
	}elseif($job==100){
	echo 'Warrior';
	}elseif($job==110){
	echo 'Fighter';
	}elseif($job==120){
	echo 'Page';
	}elseif($job==130){
	echo 'Spearman';
	}elseif($job==111){
	echo 'Crusader';
	}elseif($job==121){
	echo 'White Knight';
	}elseif($job==131){
	echo 'Dragon Knight';
	}elseif($job==112){
	echo 'Hero';
	}elseif($job==122){
	echo 'Paladin';
	}elseif($job==132){
	echo 'Dark Knight';
	}elseif($job==200){
	echo 'Magician';
	}elseif($job==210){
	echo 'Fire/Poison Wizard';
	}elseif($job==220){
	echo 'Ice/Lightning Wizard';
	}elseif($job==230){
	echo 'Cleric';
	}elseif($job==211){
	echo 'Fire/Poison Mage';
	}elseif($job==221){
	echo 'Ice/Lightning Mage';
	}elseif($job==231){
	echo 'Priest';
	}elseif($job==212){
	echo 'Fire/Poison Arch Mage';
	}elseif($job==222){
	echo 'Ice/Lightning Arch Mage';
	}elseif($job==231){
	echo 'Bishop';
	}elseif($job==300){
	echo 'Bowman';
	}elseif($job==310){
	echo 'Hunter';
	}elseif($job==320){
	echo 'Crossbowman';
	}elseif($job==311){
	echo 'Ranger';
	}elseif($job==321){
	echo 'Sniper';
	}elseif($job==312){
	echo 'Bow Master';
	}elseif($job==322){
	echo 'CrossBow Master';
	}elseif($job==400){
	echo 'Thief';
	}elseif($job==410){
	echo 'Assassin';
	}elseif($job==420){
	echo 'Bandit';
	}elseif($job==411){
	echo 'Hermit';
	}elseif($job==421){
	echo 'Chief Bandit';
	}elseif($job==412){
	echo 'Night Lord';
	}elseif($job==422){
	echo 'Shadower';}
	?>

So i have all my jobs and now i want to be able to view it in a table like

PHP:
  <?php
	$tsel = mysql_query("SELECT * FROM `characters` WHERE gm=0 ORDER BY `level` asc limit 50") or die(mysql_error());
	while ($top = mysql_fetch_array($tsel)) {
		print "<tr><td class=content>$top[name]</td><td class=content>$top[level]</td><td class=content>$top[meso]</td><td class=content>$job</td></tr>";
	}
	?>

Can someone tell me what is wrong because all it prints out is

Code:
Resource id #6
 
You should use mysql_fetch_assoc instead (Like mentioned in the other thread of yours).. Also

this:
PHP:
  if($job==500 || $job==510){ 
    echo 'GM'; 
    }elseif($job==000){ 
    echo 'Beginner'; 
    }elseif($job==100){
is not really a good way to go.. so much if statements XD, you should look up switch/case statement ;) That one will speed up your script alot!
 
using mysql_fetch_assoc
Code:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\server\www\job.php on line 2
 
Lol, i looked closer to your code..
And the 2nd one is fine.. but the code below is missing a fetch function:

you use mysql_query, but never fetch the contents in the array... so thats why you're getting resource id #

PHP:
<?php 
    $job = mysql_query("SELECT job FROM `characters` WHERE gm=0") or die(mysql_error()); 
    if($job==500 || $job==510){ 
    echo 'GM'; 
    }elseif($job==000){ 
    echo 'Beginner'; 
    }elseif($job==100){ 
    echo 'Warrior'; 
    }elseif($job==110){ 
    echo 'Fighter'; 
    }elseif($job==120){ 
    echo 'Page'; 
    }elseif($job==130){ 
    echo 'Spearman'; 
    }elseif($job==111){ 
    echo 'Crusader'; 
    }elseif($job==121){ 
    echo 'White Knight'; 
    }elseif($job==131){ 
    echo 'Dragon Knight'; 
    }elseif($job==112){ 
    echo 'Hero'; 
    }elseif($job==122){ 
    echo 'Paladin'; 
    }elseif($job==132){ 
    echo 'Dark Knight'; 
    }elseif($job==200){ 
    echo 'Magician'; 
    }elseif($job==210){ 
    echo 'Fire/Poison Wizard'; 
    }elseif($job==220){ 
    echo 'Ice/Lightning Wizard'; 
    }elseif($job==230){ 
    echo 'Cleric'; 
    }elseif($job==211){ 
    echo 'Fire/Poison Mage'; 
    }elseif($job==221){ 
    echo 'Ice/Lightning Mage'; 
    }elseif($job==231){ 
    echo 'Priest'; 
    }elseif($job==212){ 
    echo 'Fire/Poison Arch Mage'; 
    }elseif($job==222){ 
    echo 'Ice/Lightning Arch Mage'; 
    }elseif($job==231){ 
    echo 'Bishop'; 
    }elseif($job==300){ 
    echo 'Bowman'; 
    }elseif($job==310){ 
    echo 'Hunter'; 
    }elseif($job==320){ 
    echo 'Crossbowman'; 
    }elseif($job==311){ 
    echo 'Ranger'; 
    }elseif($job==321){ 
    echo 'Sniper'; 
    }elseif($job==312){ 
    echo 'Bow Master'; 
    }elseif($job==322){ 
    echo 'CrossBow Master'; 
    }elseif($job==400){ 
    echo 'Thief'; 
    }elseif($job==410){ 
    echo 'Assassin'; 
    }elseif($job==420){ 
    echo 'Bandit'; 
    }elseif($job==411){ 
    echo 'Hermit'; 
    }elseif($job==421){ 
    echo 'Chief Bandit'; 
    }elseif($job==412){ 
    echo 'Night Lord'; 
    }elseif($job==422){ 
    echo 'Shadower';} 
    ?>
 
Got ya but how do i add that i thought that has mysql_query
 
Look at the other code, and do exactly as that one....
It's this line
PHP:
while ($top = mysql_fetch_array($tsel)) {

google a bit and figure out how to use it :). You should be able to find stuff yourself
 
PHP:
$jobsArray = array("000"=>"Beginner", "100"=>"Warrior", "110"=>"Fighter");

$query = mysql_query("SELECT job FROM `characters` WHERE gm=0");  

$jobs = mysql_fetch_array($query) or die(mysql_error());

foreach ($jobs as $job) {
  $jobId = $job['job'];

  echo $jobsArray[$jobId];
}

though I don't really understand why would you want to do this at all.. for example why don't you have both job_id and job_name in db..
 
Last edited:
PHP:
$job = mysql_query("SELECT job FROM `characters`") or die(mysql_error());
	while ($jobb = mysql_fetch_array($job)) {  
	if($job==500 || $job==510){
	echo 'GM';
	}elseif($job==000){
	echo 'Beginner';
	}elseif($job==100){
	echo 'Warrior';
	}elseif($job==110){
	echo 'Fighter';
	}elseif($job==120){
	echo 'Page';
	}elseif($job==130){
	echo 'Spearman';
	}elseif($job==111){
	echo 'Crusader';
	}elseif($job==121){
	echo 'White Knight';
	}elseif($job==131){
	echo 'Dragon Knight';
	}elseif($job==112){
	echo 'Hero';
	}elseif($job==122){
	echo 'Paladin';
	}elseif($job==132){
	echo 'Dark Knight';
	}elseif($job==200){
	echo 'Magician';
	}elseif($job==210){
	echo 'Fire/Poison Wizard';
	}elseif($job==220){
	echo 'Ice/Lightning Wizard';
	}elseif($job==230){
	echo 'Cleric';
	}elseif($job==211){
	echo 'Fire/Poison Mage';
	}elseif($job==221){
	echo 'Ice/Lightning Mage';
	}elseif($job==231){
	echo 'Priest';
	}elseif($job==212){
	echo 'Fire/Poison Arch Mage';
	}elseif($job==222){
	echo 'Ice/Lightning Arch Mage';
	}elseif($job==231){
	echo 'Bishop';
	}elseif($job==300){
	echo 'Bowman';
	}elseif($job==310){
	echo 'Hunter';
	}elseif($job==320){
	echo 'Crossbowman';
	}elseif($job==311){
	echo 'Ranger';
	}elseif($job==321){
	echo 'Sniper';
	}elseif($job==312){
	echo 'Bow Master';
	}elseif($job==322){
	echo 'CrossBow Master';
	}elseif($job==400){
	echo 'Thief';
	}elseif($job==410){
	echo 'Assassin';
	}elseif($job==420){
	echo 'Bandit';
	}elseif($job==411){
	echo 'Hermit';
	}elseif($job==421){
	echo 'Chief Bandit';
	}elseif($job==412){
	echo 'Night Lord';
	}elseif($job==422){
	echo 'Shadower';}
	?>

Its gives me parse error
Code:
Parse error: parse error in C:\server\www\job.php on line 77

Could you redo thre script for me ?

---------- Post added at 10:56 AM ---------- Previous post was at 10:46 AM ----------

I cant because there is only Job Id and isnt it client side that updates it if not what file in MS is it ?
 
How can i when the job id updates the title wont :/
 
I want to do it trhis way isnt this possible

---------- Post added at 11:38 AM ---------- Previous post was at 11:19 AM ----------

Is it possible? and can someone show me how ?
 
I CAN DO THAT. put what difference dose it make! When the user chooses there job or upgrade there job i dont know what file it is that updates the database. So HOW CAN I ADD A STUPID TABLE as there is no point because it wont update! ITS AN MS SERVER
 
Why would you need to update the job title when someone signs up??
You need to create another table that will hold all job titles and the job id's. When you've done that you can look up the users job_id in the newly created table :)
If you do not know how to do this, then I'd suggest getting some tutorials from google and start with learning the basics of SQL
 
Lock please


I find this useless for what i want im proberly not explaing properly
 
ok this is for MapleStory. the server reconizes the job id and puts the title accordingly. the server updates the db with the job id and not the title.

the switch idea is good but the code will be tooooo long. the array approach is the best one for this IMO
 
ok this is for MapleStory. the server reconizes the job id and puts the title accordingly. the server updates the db with the job id and not the title.

the switch idea is good but the code will be tooooo long. the array approach is the best one for this IMO

Yes but what I can't understand is, if maplestory never touches job_name, then why not just create it.. and use it outside of maplestory, you know... for your own and not ingame.
 
It is only based on what you want.

Forget the switch(), countrary to popular belief it is slower than if/elseif's, besides, it will not shorten your code in this case.

Then, making another table or using the array method...
If you want performance, use the array.
If you want your code cleaner, and easier to update later, make the job table with a JOIN in your SQL query.
 
Back