[PHP] Help using a function within a function, both within a class

2006-04-19 Thread Adele Botes

To anyone who can help, I would like to know why or how I can execute a
function within a function used within this class. I want to redirect if
the results of a insert query was successful, so i made a simple redirect
function for later use, once I've build onto the class. The problem is that
i am not sure why or how to get the redirect($url) to work within
insert_data($table,$values,$where)

Even if I call the function: print redirect($url); and add the $url 
argument

to insert_data it still doesn't work. I get undefined function error. What
am I doing wrong?

?php
require_once('../config.inc.php'); // contains define(WEB_ROOT, 
'http://www.example.com'); and $db_connection


class DATA {
   // variables
   var $table;
   var $fields;
   var $where;
   var $url;
  
   // Constructor must be the same name as the class
  
   // Functions

   function insert_data($table,$values,$where) {
   global $redirect;
   $insert = INSERT INTO $table VALUES('',.$values.) $where;
   $result = mysql_query($insert);
   if ($result) {
   # redirect here
   print $redirect;
   } else {
   print die(mysql_error());
   }
   }
  
   function redirect($url) {
   $redirect = META HTTP-EQUIV=\refresh\ content=\0; 
URL=.WEB_ROOT.$url\;

   return $redirect;
   }
  
}

?

table
   tr
   td
   ?php
   $add_location = new DATA; // creates new object named DATA 
without (constructor arguments)

   $add_location-redirect('site/index.php');
   $add_location-insert_data('locations','Vredendal','02721','');
   ?
   /td
   /tr
/table

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help using a function within a function, both within a class

2006-04-19 Thread Adele Botes

chris smith wrote:


On 4/19/06, Adele Botes [EMAIL PROTECTED] wrote:
 


To anyone who can help, I would like to know why or how I can execute a
function within a function used within this class. I want to redirect if
the results of a insert query was successful, so i made a simple redirect
function for later use, once I've build onto the class. The problem is that
i am not sure why or how to get the redirect($url) to work within
insert_data($table,$values,$where)

Even if I call the function: print redirect($url); and add the $url
argument
to insert_data it still doesn't work. I get undefined function error. What
am I doing wrong?

?php
require_once('../config.inc.php'); // contains define(WEB_ROOT,
'http://www.example.com'); and $db_connection

class DATA {
   // variables
   var $table;
   var $fields;
   var $where;
   var $url;

   // Constructor must be the same name as the class

   // Functions
   function insert_data($table,$values,$where) {
   global $redirect;
   



You don't use globals inside a class to reference other data inside
the same class.

Instead you need to do something like this:

$add_location-url = 'blah';

then inside the class:

if ($result) {
  # redirect here
  print $this-redirect($this-url);
...

--
Postgresql  php tutorials
http://www.designmagick.com/


 


Chris

Thanx allot for your help. I works gr8.

Adele
--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP MYSQL Dynamic Select Boxes: Please Help

2005-11-03 Thread Adele Botes

I have 2 tables:

products table
product_id (INT 11 AUTOINCRE PRI)
product_name (VARCHAR 255)
product_desc (VARCHAR 255)

color table
color_id (INT 11 AUTOINCRE PRI)
color (VARCHAR 255)
image (VARCHAR 255)
product_id (INT 11)

I would like to create the first select box (pulling the options from 
the products table).


Then I would like the second select box to display the color option 
related to the product_id in the first select box, thus changing the 
options dynamically.


I've tried the following and it doesn't seem to work.
What am I doing wrong? Please help:

?php
include_once(../../config.inc.php);
$DB_NAME = $DB_NAME[0];
if($DB_NAME[0]) {
global $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME;
mysql_connect($DB_HOST, $DB_USER, $DB_PASS);
mysql_select_db($DB_NAME) OR die(MYSQL Error: error selecting DB);
} // this works
?
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN 
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;

html xmlns=http://www.w3.org/1999/xhtml; lang=en xml:lang=en
head
titleCempave :: Quality cement products/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
link rel=stylesheet type=text/css href=?php print 
WEB_ROOT;?html/style.css
script type=text/javascript 
src=unobtrusivedynamicselect_ex2to4.js/script

script type=text/javascript
window.onload = function() {
dynamicSelect(pda-brand, pda-type);
}
/script
/head
body topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0
form action=#
select id=product_name name=product_name
option value=select selectedSelect a product.../option
?php
$sql1 = mysql_query(SELECT * FROM `products`);
while ($row = @mysql_fetch_array($sql1))
{
$product_id = $row['product_id'];
$product_name = $row['product_name'];
print option 
value='$product_name'$product_name/option;
}
?
/select
!--table--
select id=color name=color
option class=select value=select selectedSelect a 
color.../option

?php
		$sql1 = mysql_query(SELECT * FROM `products` LEFT JOIN `color` ON 
products.product_id = color.product_id WHERE color.product_id = 
'$product_id');

while ($row = @mysql_fetch_array($sql1))
{
$product_id = $row['product_id'];
$color_id = $row['color_id'];
$color = $row['color'];
//print trtd$product_id $color_id 
$color/td/tr;
print option class='$product_id' 
value='$color'$color/option;
}
?
/select
!--/table--
/form
/body
/html

This is all the JavaScript code i used:
function dynamicSelect(id1, id2) {
// Feature test to see if there is enough W3C DOM support
if (document.getElementById  document.getElementsByTagName) {
// Obtain references to both select boxes
var sel1 = document.getElementById(id1);
var sel2 = document.getElementById(id2);
// Clone the dynamic select box
var clone = sel2.cloneNode(true);
// Obtain references to all cloned options
var clonedOptions = clone.getElementsByTagName(option);
		// Onload init: call a generic function to display the related options 
in the dynamic select box

refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		// Onchange of the main select box: call a generic function to display 
the related options in the dynamic select box

sel1.onchange = function() {
refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
};
}
}
function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
// Delete all options of the dynamic select box
while (sel2.options.length) {
sel2.remove(0);
}
	// Create regular expression objects for select and the value of the 
selected option of the main select box as class names

var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp(( |^)( + 
sel1.options[sel1.selectedIndex].value + )( |$));

// Iterate through all cloned options
for (var i = 0; i  clonedOptions.length; i++) {
		// If the classname of a cloned option either equals select or 
equals the value of the selected option of the main select box
		if (clonedOptions[i].className.match(pattern1) || 
clonedOptions[i].className.match(pattern2)) {
			// Clone the option from the hidden option pool and append it to the 
dynamic select box

sel2.appendChild(clonedOptions[i].cloneNode(true));
}
}
}
// Attach our behavior onload
window.onload