Jump to content

php class


chriscloyd

Recommended Posts

would this be how to start a class if im trying to get an id from a url
say if my url is index.php?project=3  <=== that 3 is the id
how do i echo the class to get the $p_name

[code]
<?php
class getproject {
    var $id = $_GET['project'];
    function p_name {
          $get_name = mysql_query("SELECT * FROM projects WHERE id = '$id'") or die(mysql_error());
          $p = mysql_fetch_assoc($get_name);
          $p_name = $p['name'];
    }
}
?>
[/code]
Link to comment
Share on other sites

[code]
<?php
class getproject {
  var $id = $_GET['project'];
  function p_name() {
    if ($result = mysql_query("SELECT `name` FROM projects WHERE id = '{$this->id}'")) {
      if (mysql_num_rows($result) > 0) {
        $row = mysql_fetch_assoc($result);
        return $row['name'];
      }
    }
  }
}
?>
[/code]

Looks to me like you might be trying to run before you can walk.
Link to comment
Share on other sites

i get this error

Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\includes\porfolio_getfunctions.php on line 3


[CODE]
<?php
class getproject {
var $id = $_GET['project'];
//project name
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['name'];
}
}
}
}
?>
[/CODE]
Link to comment
Share on other sites

I don't think you can declare and assign a property in one go in php5. Use....

[code]
<?php
class getproject {

        private $id;

        function __construct() {
                $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['name'];
}
}
}
}
?>[/code]
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.