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




Array Passed To Dispay_table()


how to process the array passed to dispay_table(). The idea being that i can pass any number of fields in the array and have them output. Any ideas on how this can be done?

$sql = mysql_query("SELECT * FROM whatever");
$table = new CreateTable();
$table->display_table($sql, "field1, field2, field2");
function display_table($sql, $fields){
while($result = mysql_fetch_array($sql)){
// I'm trying to get all the values of // the fields array to dispay here.
// i.e. $result[field1]
}}




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Varaible Passed Through URL Is Not In $_GET Array
I am passing a variable through url.
www.example.com/maxmoney.php?id=xyz@yahoo.com

In the maxmoney.php I have tried to catch it this way
$email=$_GET['id'];
when i echoed $email or $_GET['id']; its not displaying.

I am using php 5. I could not figure out what the issue is.

Push To Array Passed To Function By Reference?
Anyone know how to push values to an array that was passed to a function by reference.
This doesn't work:

function something(&$somearray) {
array_push($somearray,"new value"); }

How Many Arguments Passed???
is there a function or method, where i can get the number of arguments passed to a function.? i know that there is a function called func_num_args, but it seams that this function have to be called from within the function, and that was not what i wanted.

XML Being Passed To PHP Via POST
I am using macromeda Flash to create anXML object which I pass to PHP.
I need to know how to recieve it into PHP so I can process it in PHP.
For now all I want to do is display the XML on the screen.

To start at the simplest point I am trying this:

$my_xml = $_POST;
echo $my_xml;

Of course all it echos is "Array"

If I have tried a few other things, but I am shooting in the dark.

Data Not Being Passed Into Db
I have this code to enter stuff into my db, When someone views a profile it's supposed to add 1 to the views column but it doesn't. Code:

Only One Session Variable Passed On...
I have a problem in a login thingy (again). Only the first session variable is passed along to the next page...

Stopping Spaces From Getting Passed
I have a simple little form that takes the name and a comment, and adds it to a table. I want to know if there is a way to prevent someone from just entering spaces, and having that get entered as their name. I have the if statement check for $name == '' - but the names entered as just spaces get by it.

Can One Get The Name Of Parameters Passed To A Function?
One thing I like about Ruby is the use of symbols when passing
function parameters to a function. One thing I dislike about PHP is
that if a function has 4 optional parameters but you want to do
something with the 4th one, you need to put in something, perhaps
empty strings, for the first 3 parameters, even though you've no
interest in using them.

I'm wondering if there is anyway to emulate the Ruby style with
something like this:

http://us2.php.net/manual/en/function.func-get-args.php

Is there a way to get the parameters as an associative array? A
numerically indexed array is just as useless as the normal style of
passing arguments.

How To Process The Passed Value In Php3?
one of my php3 page passes values to another php3 page. "www.mydomain.com/searchit.php3?variable=value" What are the commands to get/process the passed value? both the scripts or PHP3.

Can $this Be Passed As A Method Parameter?
In a class, can $this be passed by reference or value?

function setDatabaseObject("MySql", $this) {
// some code here checks the name of the
// class of the object that is calling this method
}

For security, and to enforce naming conventions, I'd like for some of
my objects to only be callable from certain classes, but the only way
I can think for an object to get the name of the calling code is if I
had in the $this keyword.

Variable Passed In Through Header
We recently upgraded PHP and variables that were once passed through the URL are no longer
recognized.

Example:

http://www.sun.com/test.php?defectID=2

Within the test.php code:

<?php
session_start();

$defectID = (int)$defectID;

if ( $defectID != 2 ) {
// This should not execute, but does.
echo "Error: $defectID";
exit;
}

?>

Can URL Parms Be Passed To A PHP Script?
Will the following pass parms "Color" and "Contrast" to the PHP script? If so, how does one
retrieve the parms within the script?

http://xyz.com/script.php?Color=blue&Contrast=weak

Variables Passed Between Functions
I have a function that fills the value field of a form with 2 possible variables but they are not getting set so when you view source you just see value=""

I also try echoing these variables to see if they are getting set but they are not.  Is it becuase they need to be set to global? Code:

Figuring Out When 2 Hours Have Passed
What I'd like to do is this.  get a date and time and determine if it has been a certain amount of time since then.  For example, I make an entry in the database of 11:00pm, and I want to periodically check, and if it is 1:00am or later, then I would update the database.  Any suggestions?

Date Has Passed Function
I have dates in my db which are stored as strings like this 08/01/2007 and i am trying to write a script which either says the date i pass in is in the future or in the past.

Only Enter Results If Date Has Passed
I have a PHP match result system. I do not want the user to enter the result if the date has not passed. If the date has passed then $played = 'Yes', If not then $played = 'No'.

I read the date and time values of the match from the database. I then need to validate them. I could use the system clock BUT somebody could simply move the date on their machine to beat the system! Is there any other way to solve this?

Variables Not Passed From Url Or Form To Page
I use a Mac at home running OSX 10.2, and use the Apache PHP MySQL trio for developing and testing sites. I've had very good experiences with this setup and have had no major problems till now.

I noticed recently that variables added to the end of the url (the get method, ...url/page.php?var=value) are not passed to the script within the page. Forms using either the get or post method have the same problem. For example, a page named "foobar.php" containing this: Code:

How To Quit A Function If All Paramters Not Passed
Is there a way to quit a function if all the parameters are not passed to the funtion ie

Function One ($two,$three) {
.......
}

if either one of the two vars are not passed then dont execute the function , i was just wondering if there was a Generic PHP function which will work for all functions i know how to do it for indivdual functions ie , by just checking for the vars.

Input Type=image Value Not Passed
I know this is really an HTML question, but a bunch of <i>designers</i> are not going to know the answer to this (yes, I know some programmers hang out there as well).

Anyway, does the input type 'image' not support a value??? I've got the typical form with two input types and the client wanted to change the buttons to images. No problem. But now my script doesn't work and I checked and the values assigned to the images are not being passed when the image is clicked. Is this normal or am I missing something?
AND, if it IS normal, how do I work around it???

Passed Variables In Included Files
I'm looking for a guide on how variables are handled in included files. A pitfall I've run into is that if I define a variable, then include a file, the variable can be displayed on the included file. But if I try to call that same variables on the included page within a function, the variable is undefined. Example: PHP Code:

Display Selected Record That Has Been Passed To URL
I have a page which can list all records from a table in my local database.

For each record that is displayed there is link next to it. When the link is
pressed another page opens up and the ID (automated primary key in my table)
of the record selected is passed to the URL.

So now the URL looks something like this:

http://localhost/Webpages/newpage.php?recordID=3

How do I display the details of the record that has been selected on this
new page?

Values In Form Not Passed Using Onclick ?
i have a php file name main.php i want to do a post and not a get since this action is to delete a row in the database. however, when i try to do a href onclick, the values are not passed to the main.php. why ? Code:

echo "You have " .$votesattach. " votes for this quote. Delete the Quote and Votes ?";
echo "<form name=send1 method=post action=main.php?action='deleteit'>";
echo "<input type=hidden name=action value=deleteit>";
echo "<input type=hidden name=which value=$delete>";
echo "<input type=hidden name=userno value=$userno></form>";
echo "<a href=main.php onclick=document.send1.submit()>YES</a>";}

how do i do pass values to the server using a post method ?

Function With Reference-passed Variabel
Are there somebody, who can tell me, what I'm doing wrong with this
function:
function hej($q, &$h) {
if ($q == 0) {
return true;
$h = 'Hello'
} else {
return false;
$h = 'Goodbye'
}
}

$rt = hej(0, &$a);
if ($rt==true) { echo 'Hej' }
else { echo 'Farvel' }
print_r($a);
echo "<br />
";

Recovering Parameters Passed With URL On The Receiving PHP End
If I pass parameters to a PHP script in URL like

..php?a=aa&b=bb
how do I recover them on the receiving PHP end?
I looked at the list of PHP Variables using phpinfo() and found nothing
suitable

Accessing A Passed Variable's Previous Name
I want to pass a variable to a function and have that function add it to an array, using the variable's name (before it was passed) without the dollar sign as the key.
So. Code:

When A Value Passed In Form Or Q'string Is Empty..
I am trying to figure out how to deal with when not all elements
in a submitted form are filled out or when page expects a query string
and doesn't get one.. I tried the two conditionals below, but still got
errors:

$param= $_GET['msg'];

/*
if ($param != "") {
echo $param;
}
*/

if (isset($param)) {
echo $param;
}

query string is:

home.php?msg=selected records have been deleted from the database.

(referrer pg is not always pg sending query string.. so need to deal
w/when no query string is passed..)

Hiding Passed Variable In The Address Bar
when i pass values from the link like this

<a href="reservation.php?myseldate=1".'-'.$month_curr.'-'.$year_curr."">Click here</a>
then in the address bar it shows

http://localhost/pankopat/reservation.php?myseldate=1-9-2007

if the user alters the value of date and change 1-9-2007 to 2-9-2007 (or any other thing) then that value gets saved in the database..

Is it possible to hide this value in the address bar or make it uneditable..

Variable Being Passed From Site Into PhpBB
I am creating an autologin feature where my site members are logged into the bulletin board automaticly

the only variable I find that is global is $sAuth

it stores the members id #... I can user this to pull the name and password out of the database and set name and password in the forum to eaqual these... is this a security issue?

or can $sAuth only be set by script on my site??? I am rather new and want to make sure this variable can not be asigned in another way.

Showing A Different Page When A Variable Is Passed
this is the code i have just now

<? include 'code.php' ?> //where variables are kept

<?
$welcome = $_REQUEST['welcome'];
$leave = $_REQUEST['leave'];
if ( $welcome )
echo $page['welcome'];
if ( $leave ) {
echo $page['leave']; {
} else {
echo $page['redirect'];
}?>

what i want to do is, if the variable passed is "welome" i want it to show a welcome page and if "leave" is passed i want it to show a leave page, and when no variable is passed i want it to redirect to a totally different page

like this:
index.php?welcome
Show welcome page

index.php?leave
show leaving page

index.php
redirect to a different page

Passed Variable Not Working In An If Statement
I am setting up a website where students can login and browse their course information and handouts.

I have set up a database with there courses in and have managed to get each students courses to appear after they have logged in correctly.  The course shows as a hyper link and is passed to a page where an if statement checks which course it is and then directs them to the relevant page. Code:

How To Extract Variable Passed With Get Method
I want to extract the variable below and assign it as  $bActive = $_Get["name"];
Something is just not working as $bActive produces an empty array. Please help.

Quoteecho "  <td><input type="checkbox" name="active_".$key.""value="active"";Thanks.

Ensure A Variable Passed Through Through URL Exists?
It just donned on me that I need an error message if someone tries to go to a page with a variable in the URL that doesn't correspond to a database entry.

For example, http://www.domain.com/poetry.php?piece=4 does not yet exist. Say I only have three poems in the database right now. What are some ways (or the best way) to make sure the variable leads to content or to otherwise display an error message?

PHP Not Populating Form Variables Passed Through POST Or GET
I"m running:

Windows Xp SP2
Apache2
PHP5
MySQL4

Everything seems fine and dandy, and I can do scripting on server side, but for some reason I cannot get data from a form to be put into a variable.

I have a simple form in an html page which submits, and in the php script that handles the input, none of the data in the form is going into the variables.

My php.ini file does have all the GPC's in place(ie variable_order, the way they get processed).

How Prevent IE From Adding [1] To Name Of A File Passed By Readfile()?
I'm using the following code example from php.net to pass a binary file via a php script:

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename="".basename($filename)."";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
set_time_limit(0);
@readfile("$filename") or die("File not found.");

$filename is set for example to /name-2.0.cgm

In Firefox the "Save As" dialog correctly suggests this name. But IE6 suggests the following name: name-2[1].0.cgm

Anyone knows how I can prevent IE from adding the [1]?

Class Object Passed Via PHP Session Fails!
I try to use PHP session function, and it doesn't work properly. :-(
I want to pass a whole object from site A to site B to minimize Database
connections.

I don't use GLOBALS = ON. My param GLOBALS is set to OFF and has be be
keept off!

Well. I want to pass a complete object of class article from website A
to website B. A daily problem, I think! But it doesn't work!

Here is my Code:
-------------------------------------------------
class article
{
var $titel;
var $id;
var $verkaufsart;
var $mehrwertsteuerAusweisbar;
var $preisart;
var $verfügbarAb;
var $angebotspreis;
var $hinweise;
var $beschreibung;

function setTitel($titel) {
$this->titel = $titel;
}

function getTitel() {
return $this->titel;
}

function setId($id) {
$this->id = $id;
}

function getId() {
return $this->id;
}
}

-------------------------------------------------
// site A
<?php
include_once 'article.php'
session_start();
$art = new article();
$art2 = new article();
session_register("art");
session_register("art2");
$art->setTitel("Test");
$art->setId("15");
$art2->setTitel("Test2");
$art2->setId("16");

print $art->getId()." ".$art->getTitel();
print $art2->getId()." ".$art2->getTitel();

print "<a href="step2.php">NEXT</a>";
?>

-----------------------------------------------
// site B
<?php
include_once 'article.php'
session_start();
if (!is_object($art)) $art = new article();
if (!is_object($art2)) $art2 = new article();
print $art->getId()." ".$art->getTitel();
print $art2->getId()." ".$art2->getTitel();
.....
-------------------------------------------------

By the way, when I print out the variable $_SESSION, I can see the
content of the object, but I dont have access:

Array ( [art] => article Object ( [titel] => Test [id] => 15
[verkaufsart] => [mehrwertsteuerAusweisbar] => [preisart] =>
[verfügbarAb] => [angebotspreis] => [hinweise] => [beschreibung] => )
[art2] => article Object ( [titel] => Test2 [id] => 16 [verkaufsart] =>
[mehrwertsteuerAusweisbar] => [preisart] => [verfügbarAb] =>
[angebotspreis] => [hinweise] => [beschreibung] => ) )

How is it possible, to receive the complete object via a php session on
the next site?

Formating Xml Results Passed From A Php Parser Script
How can i format my results when parsing xml to PHP? At the moment the value for $data is not formated. I was wanting to put line breaks after each <slide>. PHP Code:

Sajax: Lost Parameters Passed To Php Function
i write an entire site using sajax and php and I found it very powerful
and useful. But yesterday my client had formatted the ubuntu server and when server is come back online a strange thing happened.

Sajax seems to work fine (i use the debug mode) while send parameters
to the exported function but when the server function has been called
the parameters sended by javascript are lose and the function receive
the string "Array".

I miss some php/apache module?
Maybe some security module installed don't let pass the parameter?

This is my code:

Variable Number Of Parameters Passed To A Method
Is it possible to have a variable number of parameters passed to a method?

function myMethod( $a, $b )
{
 // i want to check for $c, $d, $e, etc... here
}

Variable Passed Through A Function Error - Driving Me Crazy
I have a file that contains a form and passes the results of that form through this function. The function parses the form, checks the fields for content, then enteres the information into a database. Everything is working until I apply the $tblname variable as one of the variables in the function. It is not used anywhere else and for some reason when I change the actual table name to this variable, it is not inserting into the table (I tested the query and there is no table name defined).

Eliminating Passed URL Variables For Multiple Listings On A Page
I have a page with a list of several users, each hyperlinked to another page of 'more info' about that user. The hyperlink contains the UserNumber, UserRegion, and UserStatus, and the receiving page picks up the data in the passed URL. This works well, but I'd like to eliminate the passing of these variables in the URL.

One way is to make a graphic ('More Info') that can be clicked to submit a form. Each 'More info' graphic from the dynamically created page could hold the UserNumber, but how can I pass several variables with a single click? On some pages, there can be 100+ users, and I hate to have 100+ separate forms and hidden fields.

I thought of using session variables, how can I know which user was clicked to set the session variables?

Slow Pages Passed By PHP Interpreter Via Locale Network
In order to encircle a problem of performance we have with our PHP
scripts, we were brought the make the following test. We take a
standard HTML page of our site, and we make a copy of this file but
renaming it with the PHP extension. This way, those two HTML and PHP
files have exactly the same content which is entirely HTML without any
PHP tags, neither PHP commands.

The we benched the time for displaying those pages (using FireFox):
Source HTML + extension HTML + called from Locale Machine =0,5 sec
Source HTML + extension PHP + called from Locale Machine =0,5 sec
Source HTML + extension HTML + called from Local Network =0,5 sec
Source HTML + extension PHP + called from Local Network =4 sec (!!)

All Calls are made with the same URL in http://....
This behavior is the same on several client PC we've tested in our
Local Network.

The server is Win2000 + Pentium III-800 + 256 Mb Ram. Apache 2.0.55 +
PHP 5.1.6 are manually installed and running, the server has no other
specific software. There is no anti-virus, no fire-wall.

Do you have an idea of what can cause pages passed by the PHP
interpreter to be dramatically slowed down only when they are called
via the locale network ?

Encrypting Variable Values Passed Thru A Link In A Web Page
I am working on a project in PHP / Mysql on linux platform. The project has a login page where any registered user is supposed to login before he/she can have access to some major functionalities in the project.

Since I need to check the authenticity of the user in other secured pages, I have to carry forward the username with which he/she has logged. As I am doing so, the username is appearing in the url. This of course is a major security lapse.

Recover The Agrument Names Passed To A Function Inside That Function? Possible?
Is it possible to recover the agrument names of the arguments passed to a function inside that same function?

example :

blabla($hehe, $huhu, $hihi);

function blabla($a, $b, $c)
{
arg_name($a) = "hehe";
arg_name($b) = "huhu";
// ...
}

Is this possible (agr_name is an imaginary fn)

Reference Stays Reference Even If Passed By Value
I started porting a huge PHP application to PHP5 and encountered a
problem with references. I don't know whether the behavior I see is a
bug or a feature. The following nonsens test program should make clear
what's the problem:

class test {
public $_foo = null;

public function __construct($foo) {
$this->_foo = $foo;
}
}

function fct1(&$p) {
print "before call to fct2(): $p->_foo
";
fct2($p);
print "after call to fct2(): $p->_foo
";
}

function fct2($p) {
print "in fct2(): $p->_foo
";
$p->_foo = "bla bla bla";
print "after modifying value parameter fct2(): $p->_foo
";
}

$t = new test("Hello World!");
fct1($t);

If I evaluate this code with php v5.1.2 I get the following output:

before call to fct2(): Hello World!
in fct2(): Hello World!
after modifying value parameter fct2(): bla bla bla
after call to fct2(): bla bla bla

I don't understand this: fct1() takes a parameter as reference, so
fct1() should be able to change the argument I pass to it, but it does
not do this. Instead it call fct2(), a function that takes a "value
parameter". In my understanding, fct2() can change its argument, but
changes to not affect the caller, ie. changing the parameter should
not affect the variable passed to it in the callers scope.

Am I wrong or is this a (known) bug?

BTW: The PHP4 version works fine with php4.

Assigning A Multi-dimensional Array To & From A Session Variable Loses The Array
I have created a multidimensional array and then assigned that array to a session variable so that I can use it easily on another page.  However, when I go to the array later, there's never anything in it. Code:

Error In Page When Checking Http_get_vars("myvar") And "myvar" Was Not Passed In URL String
PHP, coming from ASP coding

if (HTTP_GET_VARS['b']==1){
print "Yes";
}else{
print "No";
}

when "b" is not passed via
(http://www.mydomain.com?b=1

an error occurs and the "NO" is printed but an error is printed too.

How can I check for the value of "b" so that no error occurs if b is
not passed??

example

http=www.mydomain.com

$myvar=HTTP_GET_VARS['b']

causes an error because
"b" does not exist (ie. its not passed in the URL string.

$myvar maybe evaluated as NULL or Empty but the error is printed in
the page, anyway.

Selecting Array Rows Based On An Array Of Field=>values
Here's the code i have:

$db = array(); //main array
$db['main'] = array(); //table `main`
$db['main'][] = array('id'=>0,
'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin');
//row
$db['main'][] = array('id'=>1,
'username'=>'bob_smith','userpass'=>'psswrd','userlevel'=>'user');
//row

function trim_value(&$value){
$value = strtolower(trim($value));
}
function fdb_select($fields = "*", $table, $where = false, $limit =
false){
global $db;
$retv = $db[$table];

//LIMIT RESULTS TO FIELDS
if(strrpos($fields, ",") === false){$field=array($fields);}else{$field
= explode(",", $fields);};
array_walk($field, "trim_value");
$all_fields = array_keys($retv[0]);
if($fields == '*'|| is_null($fields)){$field = $all_fields;};
$field = array_uintersect($all_fields, $field, "strcasecmp");
$retvi = array();
foreach($retv as $num =$row){
foreach($row as $fname =$fvalue){
$fname1 = strtolower($fname);
if(in_array($fname1, $field)){
$retvi[$num][$fname]=$fvalue;
};
};
};
//DONE LIMITING TO FIELDS
if($where != false){

//UP TO HERE IT WORKS FINE
//LIMIT TO WHERE CLAUSE
$retvj = array();
foreach($retvi as $num =$row){
//IN THE ROW
foreach($where as $k =$v){
//IF ROW MEETS ALL REQUIREMENTS
if($row[$k] == $v){
$retvj[] = $retvi[$num]; //Keep that row
};
};
};
//DONE LIMITING TO WHERE CLAUSE
};
$retvi = (isset($retvj)) ? $retvj:$retvi;
//SEND A FINAL ASSOCIATIVE ARRAY
return $retvi;
};
print_r(fdb_select("*", "main", array('id'=>"1",
"username"=>"joshfrench")));

the previous code outputs this:

Array
(
[0] =Array
(
[id] =0
[username] =joshfrench
[userpass] =password
[userlevel] =admin
)

[1] =Array
(
[id] =1
[username] =bob_smith
[userpass] =psswrd
[userlevel] =user
)

)

Array Data Matches But Array Created In Loop Doesn't Work
I have the exact same data in two arrays, but only the array created
like so will work:

Multidimensional Array Syntaxt For Preg_split Array Using Submitted Textarea
I have two textarea's called textarea1 and textarea2.  What i did was use preg_split to split the textarea into seperate rows that i could use for analysis like so

$array = preg_split("/[
]?[
]/", $_POST['textarea2'], -1,PREG_SPLIT_NO_EMPTY);
$array2 = preg_split("/[
]?[
]/", $_POST['textarea1'], -1, PREG_SPLIT_NO_EMPTY);

then i used a function created for me by a nice guy on here called get_ending($filepath) which basically stripped off of each peice of text the "http://www" from every URL i put into the textareas

finishing off i wanted to create an array that would input an expression such as:

echo "<a href='$array[1]' target='_blank'><img src='$array2[1]' border='0'>";

into a text area on the next page.  ALL of this works, except that i dont know how to properly loop throught he array so it'll properly insert the text into the textarea on the next page.

For now, all it does is place the array information in the page, rather statically, i would like to run some kind of if then statement that says

"while $array has some kind of text in it, keep running this operation of echoing the following expression adding 1 to the end of the array number"  I hope that makes sense

Any ideas? Code:


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