/    Sign up×
Community /Pin to ProfileBookmark

simple php class problem

I’ll keep it short and sweet

here is my class:

[code=php]

<?php
//db connection
include(“../inc/conn.php”);

class getBody{
public $query;
public $defaultQuery;
public $rs;
private $result;

public function buildBody(){

//print $string;
//$query = ” SELECT * FROM texts WHERE Title = ‘$string’ “;

$result = mysql_query($query)or die(mysql_error());

if ( mysql_num_rows($result)>0 ){
$row = mysql_fetch_array($result);

$rs = $row[‘Content’];

}else{

//$query = ” SELECT * FROM texts WHERE Title = ‘Default'”;

$result = mysql_query($query);

$row = mysql_fetch_array($result);

$rs = $row[‘Content’];

}

}

}

?>
[/code]

here is the call:

[code=php]
$body = new getBody;
$body->query = ” SELECT * FROM texts WHERE Title = ‘$page’ “;
$body->defaultQuery = ” SELECT * FROM texts WHERE Title = ‘Default'”;
//$query = ” SELECT * FROM texts WHERE Title = ‘$string’ “;
//$query = ” SELECT * FROM texts WHERE Title = ‘Default'”;
$body->buildBody();
[/code]

here is the reply:

[QUOTE]

Query was empty

[/QUOTE]

what am i doing wrong?
Thanks ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@scragarOct 29.2008 — [code=php]
<?php
//db connection
include("../inc/conn.php");

class getBody{
public $query;
public $defaultQuery;
public $rs;
private $result;

public function buildBody(){

//print $string;
//$query = " SELECT * FROM texts WHERE Title = '$string' ";

$this->result = mysql_query($this->query)or die(mysql_error());

if ( mysql_num_rows($this->result)>0 ){
$row = mysql_fetch_array($this->result);

$this->rs = $row['Content'];

}else{

//$query = " SELECT * FROM texts WHERE Title = 'Default'";

$this->result = mysql_query($this->query);

$row = mysql_fetch_array($this->result);

$this->rs = $row['Content'];

}


}


}
[/code]
Copy linkTweet thisAlerts:
@NogDogOct 29.2008 — In case it doesn't jump out at you from Scragar's code, within a class's methods you refer to its class variables via [b]$this->variable_name[/b], not simply [b]$variable_name[/b].
Copy linkTweet thisAlerts:
@NatdripauthorOct 29.2008 — okay this is the fix I came up with.

thank you for your help scragar ?

So is what I have here wrong NogDog?[/QUOTE]



[code=php]

<?php
//db connection
include("../inc/conn.php");

class getBody
{
var $query;
var $defaultQuery;


public function buildBody(){


$query = $this->query;
$result = mysql_query($query)or die(mysql_error());

if ( mysql_num_rows($result)>0 ){
$row = mysql_fetch_array($result);

return $row['Content'];
}else{


$defaultQuery = $this->defaultQuery;
$result = mysql_query($defaultQuery);

$row = mysql_fetch_array($result);

return $row['Content'];

}



}


}

$body = new getBody();
$body->query = " SELECT * FROM texts WHERE Title = 'Reseller' ";
$body->defaultQuery = " SELECT * FROM texts WHERE Title = 'Default'";
//$query = " SELECT * FROM texts WHERE Title = 'lame' ";
//$query = " SELECT * FROM texts WHERE Title = 'Default'";
print $body->buildBody();

?>

[/code]
×

Success!

Help @Natdrip spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...