Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #11  
Old 10-25-2009, 03:22 PM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,284
Arianna will become famous soon enough
Default RE: Breeding

Awesome! I have to go now, but I'll test it tomorrow (on my test site).
Reply With Quote
  #12  
Old 10-26-2009, 02:21 AM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,284
Arianna will become famous soon enough
Default RE: Breeding

After a few edits (some brackets didn't match) I managed to get it to show, however, it only shows the females on the drop down lists, not the males (the second list is blank.)
Is it possible at $result2/$num2/$i2 are not valid variables?
Reply With Quote
  #13  
Old 10-26-2009, 09:47 AM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,284
Arianna will become famous soon enough
Default RE: Breeding

Something amazing - my dad (he knows C and C++ and stuff like that) helped me and I managed to have the whole code working!
PHP Code:
<?php

// Basic Rusnak PHP Adoptables Script configurations
include("inc/functions.php");
include(
"inc/config.php");

$themeurl grabanysetting("themeurl");
$links getlinks();

$ads getads("any");

$pagecontent getsitecontent("index");
//$article_title = $pagecontent[title];
//$article_content = $pagecontent[content];
$article_content nl2br($article_content);

$browsertitle grabanysetting("browsertitle");
$sitename grabanysetting("sitename");
$slogan grabanysetting("slogan");

$loginstatus logincheck();
$isloggedin $loginstatus[loginstatus];
$loggedinname $loginstatus[username];

// End of basic configurations

$article_content $article_title."Breeding System"
$article_content $article_content."<p>Adoptable breeding systems sure aren't easy to make!</p>"

$femaleid $_POST['female'];
$maleid $_POST['male'];
$breed $_POST['breed'];
// this two variables will get the female and male ID's from the selection form and the answer if the user has selected the adoptables or not.

// First let's create a page so the users can choose the two adoptables that they want to breed

if ($isloggedin == "yes"){ 
    
// we have to put that in the start of the breeding system, so users that are not logged in cannot see the selection forms

    
if ($breed != 'yes'){
        
// if the anser if the user has selected the adoptables or not, is different than YES, we have to show the options so the user can select them

        // This will start a selection form to select the females
        
$article_content $article_content."<p>Select the Two adoptables you want to Breed:</p><p><form method='post'><select name = 'female'>"

        
//This will select all the female adoptables the user has
        
$result mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'Female'");
        
$num mysql_num_rows($result);

        
// Loop Out code < this will loop so you select all the rows and not just one
        
$i 0;
        while (
$i $num){
            
$aid mysql_result($result,$i,'aid');
            
$type mysql_result($result,$i,'type');
            
$name mysql_result($result,$i,'name');

            
$article_content $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";
            
//this will display something like that: cute kitty (cat), the name (the type); for each adptable (female) the user has

            
$i++;
        }

        
$article_content $article_content."</select><select name='male'>"//now let's do the same for the males

        
$result2 mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'Male'");
        
$num2 mysql_num_rows($result2);

        
// Loop Out code
        
$i2 0;
        while (
$i2 $num){
            
$aid mysql_result($result2,$i2,'aid');
            
$type mysql_result($result2,$i2,'type');
            
$name mysql_result($result2,$i2,'name');

            
$article_content $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";

            
$i2++;
        }

        
$article_content $article_content."</select><input type='hidden' name='breed' value='yes'><input type='submit' value='Breed It'></form>";

        
// ok now the user has two selection forms to those a female and a male adoptable and
                //  when they click Breed It, it will be posted to the variables $_POST['female'] and $_POST['male'], which will be two aid (adoptables ids), 
                //  and with that ID we can select the information that we need from the database, and breed them

        // the hidden input will give us an answer to our question, the user has selected it? and it'll be 'yes'

    
// this is the end of if($breed != 'yes'), so now we have to put an ELSE statment, that means that the answer IS yes, and we can proceed with the breeding

    
else {
        
// ok, if the user gets here, it means that we have the male and female ID, and with it we can select the informations from the database.
        // here you can estabilish what you want.. the adoptables have to be which level to breed? the adoptables have to be the same type? 
        // I took out the incompatible part, it can be added back in if needed
        // first let's get the information we need

        
$result mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$femaleid'");
        
// the result should be just one row, so we don't need a loop

        
$female_type mysql_result($result,0,'type'); 
        
// 0 means that we are selecting the very first row, in this case, the only one
        
$female_name mysql_result($result,0,'name');
        
$female_level mysql_result($result,0,'currentlevel');


        
$result2 mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$maleid'");
        
// the result should be just one row, so we don't need a loop

        
$male_type mysql_result($result2,0,'type'); 
        
// 0 means that we are selecting the very first row, in this case, the only one
        
$male_name mysql_result($result2,0,'name');
        
$male_level mysql_result($result2,0,'currentlevel');

        
// now we have all we need. let's start the security system, to guarantee that the user has the requirements
        
        
if ($male_level AND $female_level 2){
            
//We choose the type!
            
$temptype rand(01);
            if(
$temptype == "0") {
                
$type $male_type;
                unset(
$temptype);
            } else {
                
$type $female_type;
                unset(
$temptype);
            }
            
$article_content $article_content."<p>Your adoptables are breeding.</p>";
        } else { 
//this is if they can't breed
            
$article_content $article_content."Sorry, one of your adoptables don't have the minimum level to breed. Keep feeding them so they can grow.";    
        } 

        if (
$type != "0"){
            
$article_content $article_content."<p>Result: <b>Bred Succesfully</b></p><p>Your new egg is being transferred to you right now. Yay!</p>";

            
// now let's insert the new egg at owned_adoptables

            // we're choosing a gender
            
$gender_rand rand(0,1);

            if(
$gender_rand 0){
                
$new_name $male_name." & ".$female_name."'s Son";
                
$gender 'male';
                unset(
$gender_rand);
            }
            else{
                
$new_name $male_name." & ".$female_name."'s Daughter";
                
$gender 'female';
                unset(
$gender_rand);
            }

            
// now we're choosing the code
            
$code rand(120000);

            
$result3 mysql_query("SELECT * FROM ".$prefix."adoptables WHERE type='$male_type'");
            
$aid mysql_result($result3,0,"id"); //The adoptable's ID
            
$eggimage mysql_result($result3,0,"eggimage");

            
$alts getaltstatus($aid00);

            
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$new_name','$loggedinname','0','0', '$code', '','$alts','notfortrade','no','$gender')");

            
$article_content $article_content."<p><img src='".$eggimage."'><br /><a href='myadopts.php'>Manage ".$new_name." now!</a> You can change its name to your liking.</p>";

        }

        
//uh, this is just here because we need an else, right?
        
else {
            break;
        }

    } 
//this bracket ends the else where we find the male/female id's
}// this is the end of if($isloggedin == "yes")

else { //this is the else of if($isloggedin == "yes")

    
$article_content $article_content."You are not logged in. Please log in to breed.";

}

// **********************************************************************
// Begin Template Definition
// **********************************************************************

//Define our current theme
$file $themeurl;

// Do the template changes and echo the ready template
$template file_get_contents($file);

$template replace(':ARTICLETITLE:',$article_title,$template);
$template replace(':ARTICLECONTENT:',$article_content,$template);
$template replace(':ARTICLEDATE:',$article_date,$template);

$template replace(':BROWSERTITLE:',$browsertitle,$template);
$template replace(':SITENAME:',$sitename,$template);

//Define our links
$template replace(':LINKSBAR:',$links,$template);

//Get the content for the side bar...

$sidebar getsidebar();
$template replace(':SIDEFEED:',$sidebar,$template);

//Get the ad content...
$template replace(':ADS:',$ads,$template);

//Get the slogan info
$template replace(':SLOGAN:',$slogan,$template);

echo 
$template;

// **********************************************************************
// End Template Definition
// **********************************************************************
?>
The only problem is that it doesn't actually create the adoptable. That's a problem, but we're making progress. :D
Reply With Quote
  #14  
Old 10-26-2009, 03:11 PM
BMR777 BMR777 is offline
Member
 
Join Date: Jan 2011
Posts: 1,122
Gender: Male
Credits: 10,704
BMR777 is on a distinguished road
Default RE: Breeding

Don't forget to secure your variables. Anything coming in from the user needs to be secured, otherwise your site can easily be hacked.

For:

PHP Code:
$femaleid $_POST['female'];
$maleid $_POST['male'];
$breed $_POST['breed']; 
I recommend:

PHP Code:
$femaleid $_POST['female'];
$maleid $_POST['male'];
$breed $_POST['breed'];

$femaleid secure($femaleid);
$maleid secure($maleid);
$breed secure($breed); 
That will run the built in security on the variables before you use them in the database. Without this your site can be hacked by someone entering in malicious data. :)
Reply With Quote
  #15  
Old 10-26-2009, 03:12 PM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,284
Arianna will become famous soon enough
Default RE: Breeding

Okay, I'll change that.
Have you any ideas on how to get it working so it inserts the adoptable properly?
Reply With Quote
  #16  
Old 10-26-2009, 03:13 PM
BMR777 BMR777 is offline
Member
 
Join Date: Jan 2011
Posts: 1,122
Gender: Male
Credits: 10,704
BMR777 is on a distinguished road
Default RE: Breeding

Make sure that the number of columns in this line:

PHP Code:
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$new_name','$loggedinname','0','0', '$code', '','$alts','notfortrade','no','$gender')"); 
is the same as the number of columns in your owned_adoptables table in your database. If they don't match up then the adoptable will never be inserted. :)
Reply With Quote
  #17  
Old 10-26-2009, 03:17 PM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,284
Arianna will become famous soon enough
Default RE: Breeding

Okay, let me see
PHP Code:
'','$type','$new_name','$loggedinname','0','0','$code','','$alts','notfortrade','no','$gender' 
The table is
aid, type, name, owner, currentlevel, totalclicks, code, imageurl, usealternates, tradestatus, isfrozen, gender... date.
I cannot see how I missed that. xP I'll edit and see if it works.[hr]
I now did that, but it tells me this at the top of the page (it still displays the rest, though).
Code:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 4 on MySQL result index 22 in /home/pixelpup/public_html/twig3/adoptables/breeding.php on line 76

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 4 on MySQL result index 22 in /home/pixelpup/public_html/twig3/adoptables/breeding.php on line 77

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 4 on MySQL result index 22 in /home/pixelpup/public_html/twig3/adoptables/breeding.php on line 78
Reply With Quote
  #18  
Old 10-27-2009, 10:48 AM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,284
Arianna will become famous soon enough
Default RE: Breeding

Here is my updated version. I'm doing OK - the code is free of syntax errors and it defines the variables correctly, but it won't insert into the table at all!
If anyone is nice enough to help, it is supposed to insert the adoptable on line 195.
PHP Code:
<?php

// **********************************************************************
// Rusnak PHP Adoptables Script
// Copyright 2009 Brandon Rusnak
// For help and support: http://www.rusnakweb.com/forum/
//
// Redistribution prohibited without written permission
// **********************************************************************

// Wake the sleeping giant

// **********************************************************************
// Basic Configuration Info
// **********************************************************************

include("inc/functions.php");
include(
"inc/config.php");

$themeurl grabanysetting("themeurl");

// **********************************************************************
// Define our top links by calling getlinks()
// **********************************************************************

$links getlinks();

// **********************************************************************
// Define our ads by calling getads()
// **********************************************************************

$ads getads("any");

// **********************************************************************
// Grab any settings that we will need for the current page from the DB
// **********************************************************************

$browsertitle grabanysetting("browsertitle");
$sitename grabanysetting("sitename");
$slogan grabanysetting("slogan");

// **********************************************************************
// Check and see if the user is logged in to the site
// **********************************************************************

$loginstatus logincheck();
$isloggedin $loginstatus[loginstatus];
$loggedinname $loginstatus[username];

// **********************************************************************
// End Prepwork - Output the page to the user
// **********************************************************************


$article_content $article_title."Breeding System"
$article_content $article_content."<p>Adoptable breeding systems sure aren't easy to make! I wish that this would work!</p>"

$femaleid $_POST['female'];
$maleid $_POST['male'];
$breed $_POST['breed'];

$femaleid secure($femaleid);
$maleid secure($maleid);
$breed secure($breed); 

// this two variables will get the female and male ID's from the selection form and the answer if the user has selected the adoptables or not.

// First let's create a page so the users can choose the two adoptables that they want to breed

if ($isloggedin == "yes"){ 
    
// we have to put that in the start of the breeding system, so users that are not logged in cannot see the selection forms

    
if ($breed != 'yes'){
        
// if the anser if the user has selected the adoptables or not, is different than YES, we have to show the options so the user can select them

        // This will start a selection form to select the females
        
$article_content $article_content."<p>Select the Two adoptables you want to Breed:</p><p><form method='post'><select name = 'female'>"

        
//This will select all the female adoptables the user has
        
$result mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'Female'");
        
$num mysql_num_rows($result);

        
// Loop Out code < this will loop so you select all the rows and not just one
        
$i 0;
        while (
$i $num){
            
$aid mysql_result($result,$i,'aid');
            
$type mysql_result($result,$i,'type');
            
$name mysql_result($result,$i,'name');

            
$article_content $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";
            
//this will display something like that: cute kitty (cat), the name (the type); for each adptable (female) the user has

            
$i++;
        }

        
$article_content $article_content."</select><select name='male'>"//now let's do the same for the males

        
$result2 mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'Male'");
        
$num2 mysql_num_rows($result2);

        
// Loop Out code
        
$i2 0;
        while (
$i2 $num){
            
$aid2 mysql_result($result2,$i2,'aid');
            
$type2 mysql_result($result2,$i2,'type');
            
$name2 mysql_result($result2,$i2,'name');

            
$article_content $article_content."<option value='".$aid2."'>".$name2." (".$type2.")</option>";

            
$i2++;
        }

        
$article_content $article_content."</select><input type='hidden' name='breed' value='yes'><input type='submit' value='Breed It'></form>";

        
// ok now the user has two selection forms to those a female and a male adoptable and when they click Breed It,
        //   it will be posted to the variables $_POST['female'] and $_POST['male'], which will be two aid (adoptables ids), and with
        //   that ID we can select the information that we need from the database, and breed them

        // the hidden input will give us an answer to our question, the user has selected it? and it'll be 'yes'

    
// this is the end of if($breed != 'yes'), so now we have to put an ELSE statment, that means that the answer IS yes, and we can proceed with the breeding

    
else {
        
// ok, if the user gets here, it means that we have the male and female ID, and with it we can select the informations from the database.
        // here you can estabilish what you want.. the adoptables have to be which level to breed? the adoptables have to be the same type? 
        // I took out the incompatible part, it can be added back in if needed
        // first let's get the information we need

        
$result mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$femaleid'");
        
// the result should be just one row, so we don't need a loop

        
$female_type mysql_result($result,0,'type'); 
        
// 0 means that we are selecting the very first row, in this case, the only one
        
$female_name mysql_result($result,0,'name');
        
$female_level mysql_result($result,0,'currentlevel');


        
$result2 mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$maleid'");
        
// the result should be just one row, so we don't need a loop

        
$male_type mysql_result($result2,0,'type'); 
        
// 0 means that we are selecting the very first row, in this case, the only one
        
$male_name mysql_result($result2,0,'name');
        
$male_level mysql_result($result2,0,'currentlevel');

        
// now we have all we need. let's start the security system, to guarantee that the user has the requirements
        
        
if ($male_level OR $female_level 2){ //this is if they can't breed
            
$article_content $article_content."Sorry, one of your adoptables don't have the minimum level to breed. Keep feeding them so they can grow.";    
        } 

        else {
            
//We choose the type!
            
$temptype rand(01);
            if(
$temptype == "0") {
                
$type $male_type;
                unset(
$temptype);
            } else {
                
$type $female_type;
                unset(
$temptype);
            }
            
$article_content $article_content."<p>Your adoptables are breeding.</p>";
         
            if (
$type != "0"){
               
$article_content $article_content."<p>Result: <b>Bred Succesfully</b></p><p>Your new egg is being transferred to you right now. Yay!</p>";

               
// now let's insert the new egg at owned_adoptables

               // we're choosing a gender
               
$gender_rand rand(0,1);

               if(
$gender_rand 0){
                   
$new_name $male_name." & ".$female_name."'s Son";
                   
$gender 'male';
                   unset(
$gender_rand);
                }
               else{
                   
$new_name $male_name." & ".$female_name."'s Daughter";
                   
$gender 'female';
                   unset(
$gender_rand);
                }

               
// now we're choosing the code
               
$code rand(120000);

               
$result3 mysql_query("SELECT * FROM ".$prefix."adoptables WHERE type='$male_type'");
               
$aid mysql_result($result3,0,"id"); //The adoptable's ID
               
$eggimage mysql_result($result3,0,"eggimage");

               
$alts getaltstatus($aid00);

               
// and the date comes in here too
               
$date date("F jS, Y");   
               
               
$name $new_name;

               
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','notfortrade','no','$gender','$date')");

               
$article_content $article_content."<p><img src='".$eggimage."'><br /><a href='myadopts.php'>Manage ".$name." now!</a>
               <br> It's type is "
.$type." and it was born on ".$date."! You can change its name to your liking.</p>";

            } 
// if our type is not equal to zero, this is where we continue. this is the end of the continuation.
        
// we end the place where it goes on if the levels are ok
    
//this bracket ends the else where we find the male/female id's
}// this is the end of if($isloggedin == "yes")

else { //this is the else of if($isloggedin == "yes")

    
$article_content $article_content."You are not logged in. Please log in to breed.";

}


// **********************************************************************
// Begin Template Definition
// **********************************************************************

//Define our current theme
$file $themeurl;

// Do the template changes and echo the ready template
$template file_get_contents($file);

$template replace(':ARTICLETITLE:',$article_title,$template);
$template replace(':ARTICLECONTENT:',$article_content,$template);
$template replace(':ARTICLEDATE:',$article_date,$template);

$template replace(':BROWSERTITLE:',$browsertitle,$template);
$template replace(':SITENAME:',$sitename,$template);

//Define our links
$template replace(':LINKSBAR:',$links,$template);

//Get the content for the side bar...

$sidebar getsidebar();
$template replace(':SIDEFEED:',$sidebar,$template);

//Get the ad content...
$template replace(':ADS:',$ads,$template);

//Get the slogan info
$template replace(':SLOGAN:',$slogan,$template);


echo 
$template;

// **********************************************************************
// End Template Definition
// **********************************************************************



?>
Reply With Quote
  #19  
Old 10-27-2009, 11:03 AM
Seapyramid Seapyramid is offline
Premium Member
 
Join Date: Feb 2009
Posts: 373
Gender: Female
Credits: 15,570
Seapyramid
Default RE: Breeding

you use $name = $new_name; But just looking over it quickly I don't see where $new_name is defined.

Sea
Reply With Quote
  #20  
Old 10-27-2009, 11:32 AM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,284
Arianna will become famous soon enough
Default RE: Breeding

Here :D
PHP Code:
if($gender_rand 0){
                
$new_name $male_name." & ".$female_name."'s Son";
                
$gender 'male';
                unset(
$gender_rand);
            }
            else{
                
$new_name $male_name." & ".$female_name."'s Daughter";
                
$gender 'female';
                unset(
$gender_rand);
            } 
It works on the code, producing something to the like of this at the end:
Code:
Manage Ik & Random's Daughter now! It's type is Jinx and it was born on October 27th, 2009! You can change its name to your liking.
I don't believe that that is the problem, I think that it's not inserting it into the database correctly.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Breeding Bug? Need help :) Missy Master Questions and Supports 7 08-14-2014 02:29 PM
Breeding help SilverDragonTears Questions and Supports 0 04-12-2012 11:41 PM
Random breeding outcome/ rare breeding SilverDragonTears Questions and Supports 0 03-25-2012 02:33 AM
breeding Ruffsta Feedback and Suggestions 3 06-06-2011 04:09 PM
No breeding RoconzaArt Questions and Supports 15 01-24-2011 02:48 PM


All times are GMT -5. The time now is 04:45 AM.

Currently Active Users: 9747 (0 members and 9747 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636