-_-

-_-

sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
My for loop only goes through once. :/

php code

<?php
$world
= new World(); // trunk/core.php
$counter = 0;
for (
$i=0; $i <= $world->FindWorlds; $i++)
{
$counter++;
$world->GetData($counter);

// $displayWorld = $world->DisplayWorld();
// if($displayWorld===false)
// {
// die("if(\$displayWorld===false)");// encountered an error
// }
// else
//{
echo $world->id . "<br />";
echo
$world->name . "<br />";
echo
$world->description . "<br />";
echo
$world->threads . "<br />";
echo
$world->lastPost . "<br />";
echo
"<be />";
//}
?>



php code

<?php
public function FindWorlds()
{
//$database = new Database();
//$countRowsConnect = $database->ConnectToDatabase("general");
$countRowsConnect= mysql_connect("127.0.0.1","general","g-g-g-godlike");
mysql_select_db("general");
$countRows = mysql_query("SELECT `id` FROM `world`");
$this->numberOfCategories = mysql_num_rows($countRows);
//mysql_free_result($countRows);
//mysql_close($countRowsConnect);
return $this->numberOfCategories;
}
?>


 
 
 
2010 Dec 4 at 15:20 PST — Ed. 2010 Dec 4 at 15:20 PST
sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
So I fixed this by putting $world->FindWorlds outside of the for loop.
php code

<?php
$iterations
= $world->FindWorlds();
for (
$i=0; $i <= $iterations-1; $i++)
?>



I still don't know why it wouldn't throw an error. I'm assuming it has something to do with the '->'.
 
 
 
2010 Dec 4 at 15:26 PST
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
PHP looks so nasty. I assume '->' is some kind of dereferencing, or tells the program you want to access the method FindWorlds from $world?
 
 
 
2010 Dec 4 at 15:30 PST
sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
Down Rodeo said:
tells the program you want to access the method FindWorlds from $world?

php code

<?php
require_once 'database.php';

// all we need to do is display, get, or set data
class World
{
public
$id;
public
$name;
public
$description;
public
$threads;
public
$lastPost;
public
$numberOfCategories;

public function
__construct($inId=null, $inName=null, $inThread=null, $inLastPost=null)
{
$this->id = $inId;
$this->name = $inName;
$this->thread = $inThread;
$this->lastPost = $inLastPost;
}
/*
* Determine the amount of worlds
*/
public function FindWorlds()
{
//$database = new Database();
//$countRowsConnect = $database->ConnectToDatabase("general");
$countRowsConnect= mysql_connect("127.0.0.1","general","g-g-g-godlike");
mysql_select_db("general");
$countRows = mysql_query("SELECT `id` FROM `world`");
$this->numberOfCategories = mysql_num_rows($countRows);
//mysql_free_result($countRows);
//mysql_close($countRowsConnect);
return $this->numberOfCategories;
}
/*
* Get data from mysql
*/
public function GetData($worldId)
{
//connect to mysql
//$database = new Database();
//$getDataConnect = $database->ConnectToDatabase("general");
$getDataConnect= mysql_connect("127.0.0.1","general","g-g-g-godlike");
mysql_select_db("general");
$getData = mysql_query("SELECT * FROM `world` WHERE `id`='$worldId'");
$Data = mysql_fetch_assoc($getData);

$this->id = $Data['id'];
$this->name = $Data['name'];
$this->description = $Data['description'];
$this->lastPost = $Data['most recent'];

//mysql_free_result($getData);
//mysql_close($getDataConnect);

// Get most recent post information (name, time, etc)
$this->lastPost = $this->GetMostRecent($this->id);
// Get number of threads
$this->threads = $this->GetThreads($this->id);


return
true;

}
/*
* Set data, does not modify mysql
*/
public function SetData()
{

}
/*
* Sets data, modifies general.world
*/
public function Update()
{

}
/*
* Display data, must call GetData first, otherwise the function will return false
*/
public function DisplayWorld()
{
// if we don't make sure we call getdata we cannot display anything!
if( empty($this->id) || empty($this->name) || empty($this->description) || empty($this->threads) || empty($this->lastPost) )
{
return
false;
}
else
{

return
true;
}
}

private function
GetMostRecent($worldId)
{
$mostRecentQuery = mysql_query("SELECT `most recent` FROM `world` where id=$worldId");
$mostRecent = mysql_fetch_assoc($mostRecentQuery);
$mostRecentPost = $mostRecent['most recent'];
$mostRecentData = mysql_query("SELECT * FROM region WHERE world=$worldId ORDER BY date DESC");
$final = mysql_fetch_assoc($mostRecentData);
return
$final['poster'] . "," .$final['date'];
}

private function
GetThreads($worldId)
{
$threadsQuery = mysql_query("SELECT id FROM region WHERE world=$worldId");
return
mysql_num_rows($threadsQuery);
}

public function
__destruct()
{
// Dark ages? (celestial year 60ish?)
}
}
// end class world

// moar code less comments!
class Land
{

}
// end class land

class Region
{

}
// end class region

?>

 
 
 
2010 Dec 4 at 15:36 PST — Ed. 2010 Dec 4 at 15:37 PST
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
 
 
 
2010 Dec 4 at 15:40 PST
SuperJer
Websiteman

2005 Mar 20 • 6629
sprinkles said:
So I fixed this by putting $world->FindWorlds outside of the for loop.
php code

<?php
$iterations
= $world->FindWorlds();
for (
$i=0; $i <= $iterations-1; $i++)
?>



I still don't know why it wouldn't throw an error. I'm assuming it has something to do with the '->'.


You weren't calling the function "FindWorlds" originally. You were saying "while $i is not more than the FindWorlds function itself."
 
 
 
2010 Dec 5 at 23:44 PST
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
 
 
 
2010 Dec 6 at 01:50 PST
sprinkles

Chrome Whore
2009 Sep 6 • 2547
10 ₧
idk, I know it only looped once though.
 
 
 
2010 Dec 6 at 02:37 PST
SuperJer
Websiteman

2005 Mar 20 • 6629
Looks like evaluating a method without parentheses just yields NULL. When coerced to an integer that's 0. So $i is less than or equal to 0 for one iteration.
 
 
 
2010 Dec 7 at 21:21 PST
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5486
57,583 ₧
That makes a kind of sense, I suppose. Bit odd though, no? I wonder what situations you'd want that in, too :p
 
 
 
2010 Dec 8 at 05:55 PST
Page [1]