Jump to content

Classes


tsilenzio

Recommended Posts

You have to send the variables to another page.

There are differente ways to save a value for another page:

  • GET-Variables
    GET-Variables are in the URL... for example: www.example.com?var1=value1&var2=value2
    You can get that variable like that:
    echo $_GET['var1'];


  • POST-Variables
    POST-Variables are sent with a form. So you need a form or you send it with Javascript.
    You can get them with
    [/code]$_POST['variable-name'];[/code]
  • COOKIE-Variables
    Before you can use a cookie, you must set it with for example setcookie. You can use it after a refresh
  • ...
    There also other types of them... read more

Link to comment
Share on other sites

yea i know how to use vairables but is there a way to send a whole class in a $_POST or $_SESSION?

 

$_SESSION would work, and no need to serialize it as thorpe said.

 

Basically this would work:

<?php
include('class.def.php'); // has to be before session_Start
session_start();

if (!isset($_SESSION['class_name'])) {
       $_SESSION['class_name'] = new class_name();
}else {
   $x=1;
}
$class &= $_SESSION['class_name']; // dunno if keeping the reference works but yea

if ($x==1)
    echo $class->get_var('test');

$class->set_var('test', 'Testing');

$_SESSION['class_name'] = $class;
?>

 

Link to comment
Share on other sites

well let me ask this then if i have a class asigned to each user and each class has about 8 - 20 vars in it and there will be a class for each person logged in on each page that needs the information in it (like 90% of all my pages) then when there are about 500 - 4,000 ppl on the page at once will this cause the server to laggg REALLY bad or you dunno or what? I would assume it would but then again im no PHP / MySQL expert

Link to comment
Share on other sites

If thats the load you except, I would re-instantiate the object each call. The session is stored in memory and could cause some potential problems.

 

Just generate a function in the class called getUserData or PopulateClass that is called when the constructor is ran and fills the class with needed data.

 

 

EDIT::

You may be fine keeping it in session like I described, but I have no clue. I never implemented that on a huge system with a lot of people.

Link to comment
Share on other sites

ok good idea but would it slow up server load laot if it initalized the data for every var in each class from the tables in MySQL? or not really  I know that ODBC Databases r slow on my PC so i assumed evvery database is slow like that =/ not sure if mySQL is like lightning fast compared to it..

Link to comment
Share on other sites

Most servers database are really fast, you should really be only running 1 query to get all the data. Multiple queries, where 1 would suffice is what drags ya down.

 

But MySQL is very efficient and fast if configured properly and in 3NF form.

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.