Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Store Classes In An Array?


Is it possible to store classes in an array? I am fairly new to PHP,
and haven't found anything either way yet.
I have a program that where you can have multiple notes attached to a
ticket, which are stored in a database. I would like to just pull all
the notes from the database, storing each one in a seperate class,
which itself is stored in an array (well, another class, but it's a
classList, it's mainly an array).
I'm getting an error when I run the page:
"Cannot use a scalar value as an array", and "Call to a member function
on a non-object". The second is related to the first, as I'm calling a
function on the array value.
If it is possible, I probably coded something wrong. If that's the
case, I'll post some code.




View Complete Forum Thread with Replies

Related Forum Messages:
Store Values In An Array
$a=10;
$a=15;

while ($a <= $b)
{
$a++;
}

The output is 10,11,12,13,14,15

How to store the values of $a(10,11,12,13,14,15) in an sigle array.

View Replies !
Get Data From The Db And Store It In An Array
I want to have an input field in my Admin CP when you are creating a Forum where you can input a list of numbers (member ids) seperated by commars, like this:

Quote1,6,4,8,2
These will be the ids of people who can moderate the Forum and will be stored in the db along with all the other stuff like forum name/description etc.

That's easy enough.

Now my problem is I need to get that from the db and store it in an array... basically so I can do something like:

<?php
if(in_array($_SESSION['mem_id'], $forum_moderator_array)) {
    echo('Congratulations, you are a forum moderator.');
}
?>

How can I go about doing this?

View Replies !
Store A Array As A Variable
is there any way that i can store a array as a variable because i dont want to creat a database for thousands of variables. heres what i thought of so far

<?PHP
$arrayval = "1,3,2,7,4,6,8,15,12,78,96,1203,1029,39509,12999";
$array = array($arrayval);
echo $array[1],$array[3],$array[2],$array[5],$array[6],$array[4],$array[7],$array[9],$array[5],$array[10],$array[13];
echo "<hr>";
echo $arrayval;
echo "<hr>";
$sum = $array[1]+$array[3]+$array[2]+$array[5]+$array[6]+$array[4]+$array[7]+$array[9]+$array[5]+$array[10]+$array[13];
echo $sum;
?>

View Replies !
Store Array In Session
i store my shopping carts items in an array in a session like this Code:

View Replies !
What's The Best Way To Store An Array In The Database
I am trying to build a simple tree menu where the main items can be either a link or open up a subList of items which themselves can belinks or open into more submenus and so on.
An example is:

$ar = array(
'new_user' => 'newuser.php',
'tst1' => array(
'subtst' => 'subtstlink.php',
'subtst2' => 'sublink2.php'
),
'heyhey' => 'heyhey.php',
);

I am wondering what is the best way to store that in a mysql database (Both the item name and the link to it). Is there any php function that will allow me to make such an array into some sort of variable (String?) which can then be read easilly and made back into the array for manipulation and creation of the tree menu?

View Replies !
How To Store Array In Cookies?
I try to store array in cookie this way:

for($i=0;$i<5;$i++)
{
    $field[]='test'.$i;
}
$_COOKIE['field2']=$field;

Is it possible do it that way? I don't want to store each value of array list store separately. I'd like to store them at once. If I was storing values just to another "normal" variable (not cookie), I would do it this way: Code:

View Replies !
How Do You Store An Sql Result In A Php Array?
How do you store an sql result in a php array? The array will hold, the following fields; itemid, itemname and itemdesc. I would then require, depending on the user selection to query the array by itmeid, and return the itemname.

View Replies !
Can I Store An Array In MySQL?
I would like to store an array in a MySQL table. The values will be numeric and ranging from 1-999. I'm not sure if this is possible, and if it is then I'm not sure on the correct field type to use.

View Replies !
Store Variable In An Array
so i have a query that returns a bunch of rows.... i display the contents of the query into a table... one of the variables that the query returns is $title....

after each row is returned im wanting to store the $title variable into an array, so i can then access that array later... here is my code for storing $title into the array Code:

View Replies !
Store An Array In A Text Document
I want to store an array in a text document. what I've been doing so far looks like this:

fputs( $myFile, $myArray );

but all it does is write the word "Array", instead of the actual array. I'm new to php and I've done my best to search the manual and numerous web resources (including this forum) for an answer, so please don't flame.

View Replies !
Store Mysql Results Into An Array
i just started using php. i've used it before as a maintainer. fun stuff. well now i'm the writer. i want to abstract all the DB commands away from myself and all other developers. so i'm writing a function to query the php database from all users of the database and store them into an array as a return value so that i can seperate my database code from my html creation code.

1. is there a way to put all my database functions into a php file and include that file into all my other php pages? similiarly to a #include in C++ or a import package name in Java?

2. my code to run down the fetched results and store them into an array doesn't seem to be working the way i want it to. if i print out the results from the mysql returned fetch the data is fine. however the array seems to print out "Array[elementnumber]" instead of the value. Code:

View Replies !
How To Store Checkbox Values To An Array?
I need to allow the user to select multiple mysql records via an html form checkbox.  On submission of the form I would like to store these values in an array for either multiple record deletion or creating a list of records. Code:

View Replies !
Four Fields That Are Dates, Store As An Array
I have a form that has over 100 fields. I have four fields that are dates that I would like to store as an array. When I submit the form I place the dates in the array like so:

$planworkdate = array("mon" => $planworkdate0,"tue" =>$planworkdate1,"wed" =>$planworkdate2,"thu" =>$planworkdate3);

and insert into mysql database. When I try to retrieve the data I get the word Array for the result. What am I doing wrong?

$query = "SELECT planworkdate from general";
$resultall = mysql_query($query);
$planworkdate=mysql_result($resultall,$x,"planworkdate");

print $planworkdate; ...

View Replies !
Take All The Results From A Query And Store Them In An Array
trying to get my head around arrays, and I want to take all the results from a query and store them in an array so that I can use them  for later use: Code:

View Replies !
Store Form Fields To An Array
i have a form which consists of several fields for name, address, number etc. i use a php form to process this and output it onto a html form. the thing is, i'd like to store the information in an array. so for each user, the array will have their details. and this can be printed on the screen. can you tell me how this is possible. i have seen examples of arrays, but the values are assigned to the variables already.

View Replies !
Store The Entire Table In A Two Dimensional Array
I am reading info from a tab-delimited text file and I was wondering if anyone knew how to get this concept to work. I am trying to store the entire table in a two dimensional array, but the way I'm doing it right now won't work.

for($i=0; $i<$numrows; $i++)
{$columnsvalue[i] = explode(" ",$newfile[i]);}

does anyone else know how to better work with multi-dimensional arrays?

View Replies !
Mysql_fetch_array Way To Pull Out All The Data, Store It In An Array
I have a webpage which runs repetitive queries agaist a database in order to extract one item at a time and then put the items in an HTML table. The reason for this is formatting, plus the page hits 4 databases.

Instead of running multiple queries pulling one item at a time...is there a way to pull out all the data, store it in an array, and then pull individual items from the array with php as I want to insert them in the table? So, example is Code:

View Replies !
Variables To Store (Name,Species,Sex) Inside An Array
In PHP, is there anyway of using variables to store each piece of information (Name,Species,Sex) inside an array. Then, when it comes to fetching the information, the array position (e.g. 0) is called along with the information type (Name etc). A bit like the following: record(1).name The information is coming from the record array, at position 1 displaying names.

View Replies !
Store While Statment Data In Array Using Session And Retrieve?
I wish to store retreve value from my sql using session array and retrieve this value.
here is my while statement, which is displaying records from my database. I want to store all this value in an array using session and than retrieve this value on click of the table row. Code:

View Replies !
Array Problem - Extract And Store In Seprate Variables .
I have an array from a program of the type $list_box_contents[$row][$col]['text'];
 There are 3 columns  and an indefinite no. of rows.

Each array element contains a few bits of information. I want to to extract this and store in seprate variables .

$list_box_contents[$row][2]['text']; has 2 bits of information, a price and a small text box with some text. How can extract the price data from this .

View Replies !
Store The Selected Checkbox Values In A Variable Or An Array?
how to store the selected checkbox values in a variable or an array?

View Replies !
Array Problem... - Store This List In $_SESSION['liste'];
the user selects 6 numbers in a list I have to store this list in $_SESSION['liste']; (I cant do it differently) the list is stored like that: 34-21-44-32-12-11 (cant do it differently either)

what I need to do is to explode the array, get rid of the - , sort the values in ascending order and send them to my table as a string. so in the end I should have: 111221323444

I tried using a variation of laserlight's script (given in a previous post) without success... hope that someone will have time to give me a hand again in telling me what I could change in saberlights script to make it work.

View Replies !
Explode - Open File Store The Numbers In An Array
I have a .txt file looking like this

3
4
56
23
59
10

i want PHP to open that file and store the numbers in an array something like this

$q = "3,4,56,59,10"

Now i want to read $q and see if it contains 56 and 10 (it does) Code:

View Replies !
Static Classes Vs. Singleton Classes Vs. Globals
Sometimes I want to use certain data and functions anywhere in my code;
for example, when writing logging routines. In PHP5 I could write a
class with all static members and functions, a singleton class, or a
regular class assigned to a global variable. What would be the
advantages of each?

In Java web-apps (or in non-web applications), these classes persist
for much longer, so it's easier to see the reasons for using them. But
in PHP, it seems like you could do pretty much the same thing with all
three.



View Replies !
Classes Within Classes Scope Question
I have two classes, A and B. B is created as an object within A, but also needs to use a variable within A. How do you reference it? Example,

class A {
var somevar = "test";
A { $obj = new B (); }
}

class B {
B { print ( * $somevar from the A class * ); }
}

The class B is trying to use the variable $somevar declared in class A. I just don't know how to use the variable.

View Replies !
Using Classes Inside Of Other Classes
I'm wondering how to use another class inside a preexisting class, without passing the constructor in the preexisting class an object from a file that contains a new declaration.

IE: Instead of doing something like this...

View Replies !
Why Use Classes?
I feel that i mastered functions and now there is something called classes. What makes it superior to functions? Is it better to use them?

View Replies !
PDF , Classes, And PHP
I'm stuck at first base here. Currently working on turning a rather static PDF building script into a more modular, OO PHP app.

I have scaled this example down to the bare bones, trying to see what the heck is going wrong. It recognizes that is should spawn a pdf file, but then there is just no data. Nothing, no error, no helper app.

I'm only a week or so into PDFs and only a couple of days into OO with PHP, so I'm on the lookout for the obvious. I do have PHP/PDF apps that run fine off the same system.

Here is the class:
<?
error_reporting(E_ERROR);
/********************************************
pdfReport.class.php - description
********************************************/
/*
common functions / classes
*/
//class used to build rectangles - how exciting (-:
class pdfReport{
//define our common properties
//page properties
var $pdf;
function createPDF() {
header("Content-type: application/pdf");
header("Content-Dispositions: filename=report.pdf");
$this -> pdf = pdf_open();
pdf_begin_page($pdf, 612, 792);
}//end function createPDF
function closePDF() {
pdf_close($pdf);
}//end function pdf_close
function buildText() {
pdf_set_font($pdf, "Times-Roman", 15, "host");
pdf_show_xy($pdf, "Active Case Review Quarterly Report", 25, 780);
pdf_set_font($pdf, "Times-Roman", 26, "host");
}//end function buildText
}//end class
?>
And here is the page where I call the class:
<?
include("test.class.php");
//error_reporting(E_ERROR);
//create a report
$quarterlyPDF = new pdfReport;
$quarterlyPDF -> createPDF();
$quarterlyPDF -> buildText();
$quarterlyPDF -> closePDF();
//end pdf document
?>

thanks much for any input.

View Replies !
Value Of PHP Classes?
So PHP classes are pretty cool. But what is the value they provide? I understand the value of OO, but in the PHP environment, every class you instantiate lives only in the span of that request. There is no concept of singleton classes, or classes that remain across requests. The notion of allocating new memory for every instance of a class for every request seems wasteful. Thoughts?

View Replies !
Why Uses Classes?
I've read a DevShed article about classes in PHP, but still can't see a practical application for them considering you can use functions throughout your script, or (such as classes) include classes for certain scripts.

Can anyone tell me clearcut, what they are and why I'd use one, and in what instance?

View Replies !
Classes
I've been introduced to the concept of classes in PHP. Everyone says that they're the essence of object oriented programming and that they are extremely useful. Could someone give me an example of a good use of classes?

View Replies !
Classes - Why Would I Want To Use Classes In PHP?
okay, this is really (!) embarassing, but I have to ask:
Why would I want to use classes in PHP?

I have been using PHP for years now and writing the "normal" functions all
the time. I have never even bothered working with classes, but now I would
love to know what makes the classes so special......

View Replies !
DIR CLASSES Wth Is This?
ok, I have the following code:
this file is called cont.php:

<?php
require_once(DIR_CLASSES . 'container/containerbase.php');
.
.
class Container extends Containerbase
{
.
.
.
class def's
.
.
}
?>

Now nowhere in the containerbase.php file is the value DIR_CLASSES defined and its not some PHP global value. I also have no common.inc file that might define this value.

Where/How do I define the DIR_CLASSES value?

View Replies !
Using PHP Classes ... When?
I have been using PHP for a few years but never used classes. I
understand how they are created and how they work but was unsure about
when you use them.

View Replies !
Php Classes Within Classes?
I've been programming PHP for about 2 years and have dabbled with
classes. I'm working on a project and can't seam to figure out how to
use classes within classes. For example:

--foo.class.php--
<?
class Foo
{
var $test1;
function Foo()
{
require_once('bar.class.php');
$test1=new Bar();
}

function testFooBar()
{
return $this->test1->testBar();
}
}
?>

--bar.class.php--
<?
class Bar
{
var $return;
function Bar()
{
$this->return='FooBar Works!'
}

function testBar()
{
return $this->return;
}
}
?>

--index.php--
<?
require_once('foo.class.php');
$test = new Foo();
echo $test->testFooBar();
?>

index.php will disply a blank page instead of 'FooBar Works!'.

View Replies !
Classes... Why?
why would i use a class in php, and how do i use a class in php?

View Replies !
OOP PHP Classes
I was interested in looking at some php5 classes and objects that are object orientated to get an idea of what other people are doing. But more "real world" examples, more than "class FruitBowl" if you know what I mean by this.

Does anyone have any links handy for something like this?

View Replies !
PHP Classes :: & ->
What is the difference between "::" and "->" when using classes?

It always hard to find documentation for something that i only a symbol.

View Replies !
Use And Need Of Classes In PHP
I know what object oriented programming is - I know what classes are and how they work - I'm just trying to figure out when they should be used in PHP...

I have two questions:

1-How do you keep your objects? For example if we had a shopping cart, would we create a new shopping cart object and everytime the user adds/removes items update that same object? and how would you keep that object's information as the user browses through the site? Would you use serialize/unserialize session variable functions? or is there a better way?

2- For example, if we have a website that has users why would we want to make a "Users" class containing all the user information? Can't we just insert/retrieve data directly from the database? and when we get the data from the database what exactly is the point of creating an object out of them when we can just print it out? I guess my question is why would having a Users class be useful in a php web application? (assume users have name, username, password, address, etc.)

View Replies !
Using Two Classes
Lets say I have one class that deals with the database (class called SQL), a class that manages the user authentication (class called User) and another class that does something like getting all the options from the database for a poll (class called Options). The class Options is extended by another class called Poll which is extended by the class called Gateway, like this:

class SQL {}
class User {}

class Gateway {}
class Poll extends Gateway {}
class Options extends Poll {}

$sql = new SQL;
$sql->connect();

$user = new User;
$user->authenticate();

$poll = new Options;

As you see, SQL and User are in no way connected to the other classes, however sometimes I'd like to use SQL inside the Options class. Would it be better to use global inside one of Options' function, like this:

class Options {
public function __construct() {
global $sql;
$sql->query();
}
}
...or would it be better to let Gateway extend Users and SQL, like this:

class SQL {}
class User extends SQL {}
class Gateway extends User {}
class Poll extends Gateway {}
class Options extends Poll {}
// etc...

View Replies !
When To Use Classes
I've been developing websites using PHP for several years now, yet have never used OOP concepts. I am familiar with them, but have never had a need for them in my projects. However, I am now interested in using them to expand my knowledge, but unsure when they are really needed.

Lets say I have a MySQL database with a "customer" table that stores all their information such as name, address, phone number, etc. The web page will do basic queries on the customer info, inserts, updates, selects, and so forth. I'm trying to incorporate classes with this, yet it seems like it's a lot more work than if I were simply using function to perform the actions on the database. I did some browsing on the web and it doesn't seem like classes are really needed when your dealing with data from a database (other than possible a class to connect to the db). Is this true? Any examples maybe?

View Replies !
PHP Classes
Today I looked at the documentation for PHP classes and now I would like to rewrite a member system and content mangement system using classes. In the past Ive used classes in java, and PHP seems very similar other than some syntax stuff.

My primary concern with using classes is that if I wanted to make each member an object would it be possible to store that object in a mysql database, or would I have to have a method within my class to get all the data from the object and put it into the database, and another to then later get the data from the database and construct the object.

View Replies !
'&' In Classes
I am fairly new to coding PHP in classes,I have come across some code an old employee has written with the 'and' symbol used throughout the code. could anyone elaborate on the use of this for me?

e.g.
function &generateDays($start_date, &$rs) {

how does this differ from just:

function generateDays($start_date, &$rs) {
??

View Replies !
PHP And Classes
Specefically, how do they work? php.net describes them as a collection of variables and functions working with these variables. So far I'm doing this with collections of function and include'' statements. For any given operation, a link will include a $_GET['thing'] variable. The index then have:

if ((isset($_GET['thing'])) && ($_GET['thing'] == "linkname")) {
include 'useful_pile_of_functions.php'
}

This method seems to me to be somewhat like using includes as classes, as the called file contains everything needed to support the users desired function. How is using classes better than this method?

View Replies !
Regarding Classes
What is a class. is it like a function? this has allways confused me as i am a newby to programming (since Basic in the 80's).

View Replies !
Using Css Classes
why can't i use css classes in an echo or print function? for example: Code:

echo ("<center>");
echo ("<b>updated on $date</b><br><br>");
echo ("$entry<br><br>");
echo ("</center>");


prints the appropriated variables centered, bolded, etc.
but when i try


Code:
echo ("<center>");
echo ("<b class="entryhead">updated on $date</b><br><br>");
echo ("$entry<br><br>");
echo ("</center>");

it returns a t_string error on that line. why can't i use css classes in my php code, is there a way to apply classes like that via php? if so how do i use them?

View Replies !
Classes In PHP
I want to use some classes in PHP and I haven't ever done it before and I have all these stupid questions that I don't know. They are questions that are too simple to be documented. Here is my class.

class IP{
var $blah ="blah";

function getIP(){
echo $REMOTE_ADDR;
}

function michaelIs($str){
echo "Michael is $str";
}
}

then I do this.

View Replies !
Classes - Why Should We Use Them?
why should we use them? what are they? can anyone give an example of one that works best as a class. because i've yet to use one.

View Replies !
Using Classes
I have a login class that has to connect to the database to verify a username and password. In this class I include and use my mySQL class. Is that ok coding practice?

I am wondering because the login class cannot stand on it's own and is totaly dependent on my mySQL class to be able to work, but I cannot think of another way to do it, without totaly skipping my mySQL class and just directly accesing mySQL thru the mySQL API. Code:

View Replies !
Using Classes In PHP
I have looked over the PHP manual on version 5.0 and am pretty familiar with how classes work in PHP. I have a class in a file called MyClass.php(Or do you name it something else like .class?) that has a class in it with a few functions. PHP Code:

<?php
class myClass {


   private function __function1($property) {
      
   }

private function __function2($property) {
      
   }
}
?>

View Replies !
Problem With Classes..
Has anyone had problems with PHP returning two different results on different machines when using classes?

Here's the scenario:

On win2k/IIS/PHP 4.0.3, I set up a class like this:

class myClass {

var $thisVariable = "test";

function getVariable(){
$this->variable = $thisVariable;
echo $this->variable
}

}

When I instantiate it, it returns "test" but when I upload the file to my website server, which is Apache running PHP 4.0.2, it refuses to return anything.. but when I set it like this:

class myClass {

var $variable;

function getVariable(){
$this->variable = "test";
echo $this->variable
}

}

It works just fine. Any idea why?

View Replies !
Classes And Requires
I am wanting to include some common function into a class, these function are stored in include files, the thing is, PHP will not allow this, or i am doing something wrong. This is the code: PHP Code:

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved