- Joined
- Jun 8, 2007
- Messages
- 1,965
- Reaction score
- 482
There's some ugly code up there.. Functions where there's no need for them.. OOP for a single step, one-time-use system.. Yuck! You people need to learn procedural before moving on to more advanced things. It's usually the best option, but since nobody here actually went through the process properly, or it seems like it, there's all these weird redundant methods popping in and out.
There's a simple answer to this: Put the name of the job in the database instead of the useless number. Might as well do a find & replace query for your database once, so you don't have to do all this redundant coding thereafter.
You'll see a few messages when you run this query. They should all be good, but if you get any errors, tell me and I'll see what I can do. The success messages should tell you what the query does, so live by that as far as these queries go.
Run that code one time, then get rid of it. Change any instance of a number in the job field. That will leave less gaps to check in security as well.
Be sure to change the code that gives the user their job, it needs to be the name rather then a number from now-on. It makes sense if you think about it. That should make things much easier for the long-run
Hope that helps
Oh and from now on to get the job from the db, you can grab it along-side all the other data; like this:
Well you can sort and display the information however you like, I'm just showing that you can just grab $row['job'] from the db without any special redundant functions every-time. It makes all the difference, trust me.
Good luck
There's a simple answer to this: Put the name of the job in the database instead of the useless number. Might as well do a find & replace query for your database once, so you don't have to do all this redundant coding thereafter.
PHP:
$jobs = new array('','Mercenary', 'Acrobat', 'Assist', 'Magician',
'Knight', 'Blade', 'Jester', 'Ranger',
'RingMaster', 'BillPoster', 'Psykeeper', 'Elementor');
$err = (string) null; $msg = (string) null;
for($i=1;$i<count($jobs);$i++)
{
$q = mysql_query('UPDATE `characters` SET `job` = "'.$jobs[$i].'" WHERE `job` = "'.$i.'"') or $err.='<p>'.mysql_error().'</p>';
$msg .= 'Changed all jobs from <strong>`'.$i.'` to `'.$jobs[$i].'`</strong> (Affected `'.mysql_num_rows($q).'` rows.)<br />';
}
echo $err.$msg;
Run that code one time, then get rid of it. Change any instance of a number in the job field. That will leave less gaps to check in security as well.
Be sure to change the code that gives the user their job, it needs to be the name rather then a number from now-on. It makes sense if you think about it. That should make things much easier for the long-run
Hope that helps
Oh and from now on to get the job from the db, you can grab it along-side all the other data; like this:
PHP:
$query = mysql_query('SELECT `id`, `name`, `job`, `level`, `gender`, `money` FROM `characters`');
while($row = mysql_fetch_assoc($query))
{
echo 'Name: '.$row['name'].' | Job: '.$row['job'].' | Level: '.$row['level'].' | Gender: '.$row['gender'].' | Penya: '.$row['money'].'<br />';
}
Good luck



