Jump to content

call a function from php class


chriscloyd

Recommended Posts

Okay i have some functions in my php class but im tyring to call a function from inside my class like below but it does not work heres my code

[code]<?php
class getproject
{
private $id;
    function __construct() {
if (!isset($_GET['project'])) {
$get_project = mysql_query("SELECT * FROM projects ORDER BY id DESC");
$pid = mysql_fetch_assoc($get_project);
$this->id = $pid['id'];
} else {
$this->id = $_GET['project'];
}
    }
function name() {
if ($result = mysql_query("SELECT `title` FROM projects WHERE id = '{$this->id}'")) {
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
return $row['title'];
}
}
}
function type() {
if ($result = mysql_query("SELECT `type` FROM projects WHERE id = '{$this->id}'")) {
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
return $row['type'];
}
}
}
function start() {
if ($result = mysql_query("SELECT `startdate` FROM projects WHERE id = '{$this->id}'")) {
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
return $row['startdate'];
}
}
}
function enddate() {
if ($result = mysql_query("SELECT `enddate` FROM projects WHERE id = '{$this->id}'")) {
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
return $row['enddate'];
}
}
}
function file1() {
if ($result = mysql_query("SELECT `location` FROM project_screenshots WHERE pid = '{$this->id}'")) {
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
return $row['location'];
}
}
}
function file2() {
if ($result = mysql_query("SELECT `location` FROM project_screenshots WHERE pid = '{$this->id}' AND id != '{$project->file1()}")) {
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
return $row['location'];
}
}
}
}
?>[/code]
Link to comment
Share on other sites

Okay this line:
if ($result = mysql_query("SELECT `location` FROM project_screenshots WHERE pid = '{$this->id}' AND id != '{$project->file1()}")) {

What is $project? Just like you use $this to reference id, a variable, you need to use it to call the methods.
$this->file1()
Link to comment
Share on other sites

[quote author=jesirose link=topic=124811.msg517694#msg517694 date=1170213728]
too much code to look through without more info. What error do you get that makes you say it's "not working"
[/quote]
I didn't mean just that one time dude. If all you can say is "didn't work", all the help you'll get is "tough luck"
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.