Am not entirely sure but I think you should replace:

array("POST")

with:

$_POST

Actually the purpose of this was, if I remember correctly, to output the contents of the post array. I wrote a method inside of a class that would take an array of super globals by name so,

$headerMan->getHeaderVarString(array("POST", "GET"));

would convert the strings in the array to variable arrays which refer to super global arrays and output:
_POST
key1=value1
key2=value2
_GET
key1=value1
key2=value2
key3=value3


Something has been modified since though.

thanks for trying though pritaeas.

Sry i have been pretty busy lately

the function is the same data that you gave me in the earlier post. but instead of going though and error correcting and debugging, i thought that i would take a crack at it. So this is what i came up with. I didnt think that it would be so simple. Thanks to the previous code it was.

function getPost () {
		foreach($_POST as $key => &$value){
			global ${$key};
			${$key} = $value;
		}
	}

thanks for trying though pritaeas.

Sry i have been pretty busy lately

the function is the same data that you gave me in the earlier post. but instead of going though and error correcting and debugging, i thought that i would take a crack at it. So this is what i came up with. I didnt think that it would be so simple. Thanks to the previous code it was.

function getPost () {
		foreach($_POST as $key => &$value){
			global ${$key};
			${$key} = $value;
		}
	}

and what are you trying to accomplish with this code?

well what i am doing is simple. to get all the post data and put it like this $variable = "value"; so instead of creating 100+ or so $variable = $_POST; it does it for me. I typically name my input fields th same in the DB so that it is easy to remember and it is organized.

well what i am doing is simple. to get all the post data and put it like this $variable = "value"; so instead of creating 100+ or so $variable = $_POST; it does it for me. I typically name my input fields th same in the DB so that it is easy to remember and it is organized.

I guess I misunderstood before, I thought that you just wanted to output a string. In that case I wouldn't think that you would want to do this in a function or a method of a class only because that would actually be a pretty sloppy way of doing it in my opinion, only because you would have to use global for each variable and it would end up being much more complicated than it has to be. So I would just do the following outside of a function or class:

foreach($_POST as $key=>&$value)
{
    $$key = $value;
}

Cool i will keep that inline. Now i do have some other thoughts.

now i have got the regular query output down. You know where you cann the variables you need. But how would i go about doing a loop. Would it just make sense to just write it out or is it possible to put it into a function. Would i need to write out out once and use it dynamically or dp i have to write it out custom everytime

Thanks for this thread. Learnt a load and I will share it with my friends at websitecow.com

:)

Thanks for this thread. Learnt a load and I will share it with my friends at websitecow.com

:)

haha thats great. If you would like to know more check out the book PHP Object Oriented Solutions by Friends of ED thats where i got started.

Ya i just keep posting in this thread to keep things organized. Always trying to learn

Cool i will keep that inline. Now i do have some other thoughts.

now i have got the regular query output down. You know where you cann the variables you need. But how would i go about doing a loop. Would it just make sense to just write it out or is it possible to put it into a function. Would i need to write out out once and use it dynamically or dp i have to write it out custom everytime

if you are referring to this code:

foreach($_POST as $key=>&$value)
{
    $$key = $value;
}

you will actually have to write it out every time because of the limitations of scope of the function or method and the fact that a function or method can only return one value, be that an array of values, object or string, it is still just one of something. I generally don't bother with this because I am very comfortable with arrays to the point that I actually prefer my data to be in an array so if I know the key I want I just use that key to reference the value in question in the post array like $_POST. However, if you are comfortable with working with variables like $valueInQuestion rather than directly with the post array like $_POST then you can just use the extract function.

read here: http://php.net/manual/en/function.extract.php

sry been busy for some time.

no i was actually talking about when you loop a query to echo out multiple rows of information. for example if you were to grab file names and print them out in a table row with call to actions to delete or edit that file.

i have a regular query to grab just tid-bits of info like this

require_once('query.class.php');
		
		$fields = array("companyname","password");
		$query = new Query();
		$query->getData("users", $fields, "WHERE company_id='$company_id' and master='1'");
		
		
echo $query->companyname;
echo '<br />';
echo $query->password;
	echo '<br />';
function getData($strDbType, $table, $fields, $condition) {
		
        if(!$this->dbConn($strDbType)) return false;
			
			$result = mysql_query("SELECT * FROM $table $condition");
	
        		while($myrow = mysql_fetch_assoc($result))
             		{
				 		if($fields != ''){
				 		foreach ($fields as &$value) {
					 		$this->{$value} = $myrow[$value];
				 		}
				 		}
				 
			 		}
}

But im not sure if it would be sound to put a query loop into a function or if it is even possible. should i just write out the query everytime or is it possible to put it into a function like above with it being simple.

sry been busy for some time.

no i was actually talking about when you loop a query to echo out multiple rows of information. for example if you were to grab file names and print them out in a table row with call to actions to delete or edit that file.

i have a regular query to grab just tid-bits of info like this

require_once('query.class.php');
		
		$fields = array("companyname","password");
		$query = new Query();
		$query->getData("users", $fields, "WHERE company_id='$company_id' and master='1'");
		
		
echo $query->companyname;
echo '<br />';
echo $query->password;
	echo '<br />';
function getData($strDbType, $table, $fields, $condition) {
		
        if(!$this->dbConn($strDbType)) return false;
			
			$result = mysql_query("SELECT * FROM $table $condition");
	
        		while($myrow = mysql_fetch_assoc($result))
             		{
				 		if($fields != ''){
				 		foreach ($fields as &$value) {
					 		$this->{$value} = $myrow[$value];
				 		}
				 		}
				 
			 		}
}

But im not sure if it would be sound to put a query loop into a function or if it is even possible. should i just write out the query everytime or is it possible to put it into a function like above with it being simple.

That depends on the how often you use this query. I generally add code to classes and functions if I am going to use that code more than once. If the code, be it a query to fetch data or anything, would be something that I would like to have readily accessible then yes, I would put it into a function.

when building a software i use a query loop alot. so it would seem to make sense to put it into a function. but i wouldnt know how to go about doing that. I've looked for examples of other people doing it or tried to think of how to do it but came up with nothing.

You should probably create a new thread for this. You've lost me on this one and maybe someone else can understand the question a little better than I do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.