designing a peon maker

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Folcon
Forum Newbie
Posts: 6
Joined: Tue May 23, 2006 5:25 pm

designing a peon maker

Post by Folcon »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


basically im trying to create a script that makes peons... of both male and female but for some reason i always end up with male peons... (reasons unknow either rand is not working or something is auto switching to male  ) not a great this when i plan to add a later script that allows peons over a certain age to procreate... so any ideas as to what is wrong?

this script is a modular include file so for testing purposes all the variables i can call are listed in the beginning then i will include it in its proper place once i know it works...

Code: Select all

<?
include('DB.php');
ConnectToDB();
function peonborn()
{
$username = "Freddy";
$peonage = 1;
$peonjob = "none";
$peonmoney = 0;
$peonsex = rand(0,1);
if($peonsex = 1)
{$peonsex = "m" ;}
 else { $peonsex = "f" ; }

if($peonsex = "m")
{
$array = file("MaleFirstNames.txt");
shuffle($array);
for ($i=0; $i<1; $i++) {
echo $array[$i];
$PEONSQL = "INSERT into peons(user,name,sex,age,job,money,moneylast,buildingno) VALUES ('$username','$array[$i]', '$peonsex','$peonage','$peonjob','$peonmoney','0','0')";
mysql_query($PEONSQL) or die("could not insert into table peons");
}
}
else
{
$array = file("FemaleFirstNames.txt");
shuffle($array);
for ($i=0; $i<1; $i++) {
echo $array[$i];
$PEONSQL = "INSERT into peons(user,name,sex,age,job,money,moneylast,buildingno) VALUES ('$username','$array[$i]', '$peonsex','$peonage','$peonjob','$peonmoney','0','0')";
mysql_query($PEONSQL) or die("could not insert into table peons");
}
}
}
function insertpeonvalues()
{
$PEONSQL = "INSERT into peons(user,name,sex,age,job,money,moneylast,buildingno) VALUES ('$username','$peonname', '$peonsex','$peonage','$peonjob','$peonmoney','0','0')";
mysql_query($PEONSQL) or die("could not insert into table peons");
}

peonborn();
//insertpeonvalues();

?>
:? :?


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by Folcon on Thu May 25, 2006 2:58 pm, edited 1 time in total.
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

because in your if's you use = instead of == so it sets them all to male.
Folcon
Forum Newbie
Posts: 6
Joined: Tue May 23, 2006 5:25 pm

Post by Folcon »

great thanks!!
hmm i assume you mean like this

Code: Select all

if($peonsex == 0)
{$peonsex == "f" ;}
 else { $peonsex == "m" ; }
the only problem that causes is that the variable peonsex doesn't change from numbers to m or f.... hmm i might have to shift the variable or something...
Folcon
Forum Newbie
Posts: 6
Joined: Tue May 23, 2006 5:25 pm

Post by Folcon »

never mind be being thick it is now

Code: Select all

if($peonsex == 0)
{$peonsex = "f" ;}
 else { $peonsex = "m" ; }
allowing $peonsex to be equated to 0 and then later changing it to either m or f...

thanks for that though :)
Post Reply