PHP/MySQL Tutorial Thread!

For general discussions of any sort that don't fit in the other forums.

Moderators: Mystic Dragon, Xalia, Shard, JKatkina

delyar
Dragon
Posts: 732
Joined: Wed Jul 06, 2005 12:08 pm
Location: Ottawa, Ontario
Contact:

Re: PHP/MySQL Tutorial Thread!

Post by delyar »

I'll give that a shot later tonight.

Warning: The code is EXTREMELY messy because I couldn't figure out a way to shorten it (especially for the S## and D## columns - all attempts at subsequent while loops with auto increments failed) and this table has a ridiculous amount of columns (I think it was 118 total).

The $row refers to information taken from another table earlier on, which is confirmed to work. For some reason, it cannot recognize "male" as distinct from "female" in the DragonGender column so that's the clunky wording there.

Code: Select all

while(($kids = mysql_fetch_array( $kid )) AND ($kids['YearH']<9)) {
	echo "<tr><td style=font-size:7pt;>";
// Mateinfo here
	if ($row['DragonGender']='female') {
		if (isset($kids['FID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['FID'] ) . ">";
		if (isset($kids['F'])) echo "{$kids['F']}</a>";
		if (isset($kids['FS'])) echo "<br>{$kids['FS']}"; }
	else {
		if (isset($kids['MID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['MID'] ) . ">";
		if (isset($kids['M'])) echo "{$kids['M']}</a>";
		if (isset($kids['MS'])) echo "<br>{$kids['MS']}"; }
	if (isset($kids['OfficialN'])) echo "<br>{$kids['OfficialN']} @ {$kids['Location']}";
	if (isset($kids['YearH'])) echo "  in DY {$kids['YearH']}";
// clutch stats!


		if (isset($kids['S28'])) $b=28;
		elseif (isset($kids['S27'])) $b=27;
		elseif (isset($kids['S26'])) $b=26;
		elseif (isset($kids['S25'])) $b=25;
		elseif (isset($kids['S24'])) $b=24;
		elseif (isset($kids['S23'])) $b=23;
		elseif (isset($kids['S22'])) $b=22;
		elseif (isset($kids['S21'])) $b=21;
		elseif (isset($kids['S20'])) $b=20;
		elseif (isset($kids['S19'])) $b=19;
		elseif (isset($kids['S18'])) $b=18;
		elseif (isset($kids['S17'])) $b=17;
		elseif (isset($kids['S16'])) $b=16;
		elseif (isset($kids['S15'])) $b=15;
		elseif (isset($kids['S14'])) $b=14;
		elseif (isset($kids['S13'])) $b=13;
		elseif (isset($kids['S12'])) $b=12;
		elseif (isset($kids['S11'])) $b=11;
		elseif (isset($kids['S10'])) $b=10;
		elseif (isset($kids['S9'])) $b=9;
		elseif (isset($kids['S8'])) $b=8;
		elseif (isset($kids['S7'])) $b=7;
		elseif (isset($kids['S6'])) $b=6;
		elseif (isset($kids['S5'])) $b=5;
		elseif (isset($kids['S4'])) $b=4;
		elseif (isset($kids['S3'])) $b=3;
		elseif (isset($kids['S2'])) $b=2;
		elseif (isset($kids['S1'])) $b=1;
		else $b=0;

		if (isset($kids['D21'])) $g=21;
		elseif (isset($kids['D20'])) $g=20;
		elseif (isset($kids['D19'])) $g=19;
		elseif (isset($kids['D18'])) $g=18;
		elseif (isset($kids['D17'])) $g=17;
		elseif (isset($kids['D16'])) $g=16;
		elseif (isset($kids['D15'])) $g=15;
		elseif (isset($kids['D14'])) $g=14;
		elseif (isset($kids['D13'])) $g=13;
		elseif (isset($kids['D12'])) $g=12;
		elseif (isset($kids['D11'])) $g=11;
		elseif (isset($kids['D10'])) $g=10;
		elseif (isset($kids['D9'])) $g=9;
		elseif (isset($kids['D8'])) $g=8;
		elseif (isset($kids['D7'])) $g=7;
		elseif (isset($kids['D6'])) $g=6;
		elseif (isset($kids['D5'])) $g=5;
		elseif (isset($kids['D4'])) $g=4;
		elseif (isset($kids['D3'])) $g=3;
		elseif (isset($kids['D2'])) $g=2;
		elseif (isset($kids['D1'])) $g=1;
		else $g=0;
	$c=$b+$g;
	echo "<br>$c offspring total";
	if ($c>$kids['Eggs']) echo "; some twins";

	echo "</td><td style=font-size:7pt;>";

if (isset($kids['S1ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S1ID'] ) . ">";
if (isset($kids['S1'])) echo "{$kids['S1']}</a><br>";
if (isset($kids['S2ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S2ID'] ) . ">";
if (isset($kids['S2'])) echo "{$kids['S2']}</a><br>";
if (isset($kids['S3ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S3ID'] ) . ">";
if (isset($kids['S3'])) echo "{$kids['S3']}</a><br>";
if (isset($kids['S4ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S4ID'] ) . ">";
if (isset($kids['S4'])) echo "{$kids['S4']}</a><br>";
if (isset($kids['S5ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S5ID'] ) . ">";
if (isset($kids['S5'])) echo "{$kids['S5']}</a><br>";
if (isset($kids['S6ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S6ID'] ) . ">";
if (isset($kids['S6'])) echo "{$kids['S6']}</a><br>";
if (isset($kids['S7ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S7ID'] ) . ">";
if (isset($kids['S7'])) echo "{$kids['S7']}</a><br>";
if (isset($kids['S8ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S8ID'] ) . ">";
if (isset($kids['S8'])) echo "{$kids['S8']}</a><br>";
if (isset($kids['S9ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S9ID'] ) . ">";
if (isset($kids['S9'])) echo "{$kids['S9']}</a><br>";
if (isset($kids['S10ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S10ID'] ) . ">";
if (isset($kids['S10'])) echo "{$kids['S10']}</a><br>";
if (isset($kids['S11ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S11ID'] ) . ">";
if (isset($kids['S11'])) echo "{$kids['S11']}</a><br>";
if (isset($kids['S12ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S12ID'] ) . ">";
if (isset($kids['S12'])) echo "{$kids['S12']}</a><br>";
if (isset($kids['S13ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S13ID'] ) . ">";
if (isset($kids['S13'])) echo "{$kids['S13']}</a><br>";
if (isset($kids['S14ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S14ID'] ) . ">";
if (isset($kids['S14'])) echo "{$kids['S14']}</a><br>";
if (isset($kids['S15ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S15ID'] ) . ">";
if (isset($kids['S15'])) echo "{$kids['S15']}</a><br>";
if (isset($kids['S16ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S16ID'] ) . ">";
if (isset($kids['S16'])) echo "{$kids['S16']}</a><br>";
if (isset($kids['S17ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S17ID'] ) . ">";
if (isset($kids['S17'])) echo "{$kids['S17']}</a><br>";
if (isset($kids['S18ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S18ID'] ) . ">";
if (isset($kids['S18'])) echo "{$kids['S18']}</a><br>";
if (isset($kids['S19ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S19ID'] ) . ">";
if (isset($kids['S19'])) echo "{$kids['S19']}</a><br>";
if (isset($kids['S20ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S20ID'] ) . ">";
if (isset($kids['S20'])) echo "{$kids['S20']}</a><br>";
if (isset($kids['S21ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S21ID'] ) . ">";
if (isset($kids['S21'])) echo "{$kids['S21']}</a><br>";
if (isset($kids['S22ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S22ID'] ) . ">";
if (isset($kids['S22'])) echo "{$kids['S22']}</a><br>";
if (isset($kids['S23ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S23ID'] ) . ">";
if (isset($kids['S23'])) echo "{$kids['S23']}</a><br>";
if (isset($kids['S24ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S24ID'] ) . ">";
if (isset($kids['S24'])) echo "{$kids['S24']}</a><br>";
if (isset($kids['S25ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S25ID'] ) . ">";
if (isset($kids['S25'])) echo "{$kids['S25']}</a><br>";
if (isset($kids['S26ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S26ID'] ) . ">";
if (isset($kids['S26'])) echo "{$kids['S26']}</a><br>";
if (isset($kids['S27ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S27ID'] ) . ">";
if (isset($kids['S27'])) echo "{$kids['S27']}</a><br>";
if (isset($kids['S28ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['S28ID'] ) . ">";
if (isset($kids['S28'])) echo "{$kids['S28']}</a><br>";
if (is_null($kids['S1'])) echo "None<br>";
	echo "</td><td style=font-size:7pt;>";
// Daughters info here
if (isset($kids['D1ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D1ID'] ) . ">";
if (isset($kids['D1'])) echo "{$kids['D1']}</a><br>";
if (isset($kids['D2ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D2ID'] ) . ">";
if (isset($kids['D2'])) echo "{$kids['D2']}</a><br>";
if (isset($kids['D3ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D3ID'] ) . ">";
if (isset($kids['D3'])) echo "{$kids['D3']}</a><br>";
if (isset($kids['D4ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D4ID'] ) . ">";
if (isset($kids['D4'])) echo "{$kids['D4']}</a><br>";
if (isset($kids['D5ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D5ID'] ) . ">";
if (isset($kids['D5'])) echo "{$kids['D5']}</a><br>";
if (isset($kids['D6ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D6ID'] ) . ">";
if (isset($kids['D6'])) echo "{$kids['D6']}</a><br>";
if (isset($kids['D7ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D7ID'] ) . ">";
if (isset($kids['D7'])) echo "{$kids['D7']}</a><br>";
if (isset($kids['D8ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D8ID'] ) . ">";
if (isset($kids['D8'])) echo "{$kids['D8']}</a><br>";
if (isset($kids['D9ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D9ID'] ) . ">";
if (isset($kids['D9'])) echo "{$kids['D9']}</a><br>";
if (isset($kids['D10ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D10ID'] ) . ">";
if (isset($kids['D10'])) echo "{$kids['D10']}</a><br>";
if (isset($kids['D11ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D11ID'] ) . ">";
if (isset($kids['D11'])) echo "{$kids['D11']}</a><br>";
if (isset($kids['D12ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D12ID'] ) . ">";
if (isset($kids['D12'])) echo "{$kids['D12']}</a><br>";
if (isset($kids['D13ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D13ID'] ) . ">";
if (isset($kids['D13'])) echo "{$kids['D13']}</a><br>";
if (isset($kids['D14ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D14ID'] ) . ">";
if (isset($kids['D14'])) echo "{$kids['D14']}</a><br>";
if (isset($kids['D15ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D15ID'] ) . ">";
if (isset($kids['D15'])) echo "{$kids['D15']}</a><br>";
if (isset($kids['D16ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D16ID'] ) . ">";
if (isset($kids['D16'])) echo "{$kids['D16']}</a><br>";
if (isset($kids['D17ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D17ID'] ) . ">";
if (isset($kids['D17'])) echo "{$kids['D17']}</a><br>";
if (isset($kids['D18ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D18ID'] ) . ">";
if (isset($kids['D18'])) echo "{$kids['D18']}</a><br>";
if (isset($kids['D19ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D19ID'] ) . ">";
if (isset($kids['D19'])) echo "{$kids['D19']}</a><br>";
if (isset($kids['D20ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D20ID'] ) . ">";
if (isset($kids['D20'])) echo "{$kids['D20']}</a><br>";
if (isset($kids['D21ID'])) echo "<a href=d-template.php?id=" . urlencode( $kids['D21ID'] ) . ">";
if (isset($kids['D21'])) echo "{$kids['D21']}</a><br>";
if (is_null($kids['D1'])) echo "None<br>";
	echo "</td></tr>";
// close loop here
}
The females do have problems with pulling out the right clutches as well. For example, Akyoth is missing at least 1 clutch (which is confirmed in there as her son links back to her) and Nerissath (another dragon I checked) doesn't pull any of her 3+ successful clutches even though her babies link back to her using the same table's data. (I use the dragon_pedigrees table for both pedigree and babies.) So it doesn't seem like a table problem...

Weird that you don't see any problems with the mate bit of the loop yet the boys are listing themselves as their own mates.
Character Listing
Site Listing - Links to All Sites (Link back here if confused!)
User avatar
StarFyre
Ancient Dragon
Posts: 3246
Joined: Wed Jul 06, 2005 10:44 am
Location: Middle of Nowhere
Contact:

Re: PHP/MySQL Tutorial Thread!

Post by StarFyre »

Herpderp. There is a coding error - it's one I have the occasional problem with as well, which means I tend to overlook it.

"if ($row['DragonGender']='female')" should be "if ($row['DragonGender']=='female')". The single = sign means that you're assigning $row['DragonGender'] to be female no matter what it was previously - the reason why it works in context is because the assignment returns "true" to say that the assignment was successful.

I don't know why you'd have problems with the looping - try a for loop instead?

Code: Select all

$b=0;
for($i = 28; $i > 0; $i--){
   $sid= "S" . $i;
   if(isset($kids['$sid'])) {
       $b=$i;
   }
}
I think that'd work right. Same thing for the printing out portions.

Code: Select all

for($i = 1; $i <= $b; $i++){
   $id= "S" . $i . "ID";
   $name= "S" . $i;
   if (isset($kids['$id'])) echo "<a href=d-template.php?id=" . urlencode( $kids['$id'] ) . ">";
   if (isset($kids['$name'])) echo "{$kids['$name']}</a><br>";
}
Though if you've already tried that, forgive my presumption =P
delyar
Dragon
Posts: 732
Joined: Wed Jul 06, 2005 12:08 pm
Location: Ottawa, Ontario
Contact:

Re: PHP/MySQL Tutorial Thread!

Post by delyar »

Did your modifications. It fixed the male issue, (D'oh) but... it nuked the offspring stats & lists (plus they now show different but not complete clutches! whee!). http://lambeosaurine.com/characters-new ... .php?id=14
Character Listing
Site Listing - Links to All Sites (Link back here if confused!)
User avatar
StarFyre
Ancient Dragon
Posts: 3246
Joined: Wed Jul 06, 2005 10:44 am
Location: Middle of Nowhere
Contact:

Re: PHP/MySQL Tutorial Thread!

Post by StarFyre »

He-hey, progress! Alrighty then.. I guess take out the for loops to build the list of kiddies and put back in your code? Does that fix the issue?
delyar
Dragon
Posts: 732
Joined: Wed Jul 06, 2005 12:08 pm
Location: Ottawa, Ontario
Contact:

Re: PHP/MySQL Tutorial Thread!

Post by delyar »

The very bottom of the page is the print command by the way. I have NO idea what it is trying to tell me.

Putting back in my code recovers the functionality of the offspring lists but they still don't list the full amount of clutches. For example, http://lambeosaurine.com/characters-new ... .php?id=14 should have the same kids as http://characters.lambeosaurine.com/d-akyoth.html (notably, it is missing one of her clutches with Keranath which I KNOW is included as her son (http://lambeosaurine.com/characters-new ... php?id=252) with him lists them as parents). Hrmph.
Character Listing
Site Listing - Links to All Sites (Link back here if confused!)
delyar
Dragon
Posts: 732
Joined: Wed Jul 06, 2005 12:08 pm
Location: Ottawa, Ontario
Contact:

Re: PHP/MySQL Tutorial Thread!

Post by delyar »

I used mysql_num_rows to get the number of clutches that my query is pulling... and it's a number much higher than it is displaying. So, on the bright side, my table works! On the bad side... I have no idea what is truncating the display.

EDIT: Aha! Apparently because I had my $kids = mysql_fetch_array($kid) line before my while loop, it was skipping the first entry. So that fixes some of the issues.
Character Listing
Site Listing - Links to All Sites (Link back here if confused!)
Post Reply