Page 1 of 1

values in arrays

Posted: Wed Mar 07, 2007 12:37 am
by me!
what is the proper way to do this:

Code: Select all

$var[key] = "value";




:?:

Posted: Wed Mar 07, 2007 12:39 am
by volka
There's a wonderful online manual telling you (almost) all the basic stuff you need to know about php.
see http://www.php.net/manual/en/language.types.array.php

Posted: Wed Mar 07, 2007 7:21 pm
by me!
I started at that link, that is how I came up with the code in the first post. But I am getting
Notice Use of undefined constant key - assumed 'value'

Posted: Wed Mar 07, 2007 9:52 pm
by dude81
put key in single quotes as

Code: Select all

$var['key']='value';

Posted: Wed Mar 07, 2007 11:03 pm
by volka
There's a whole paragraph about Why is $foo[bar] wrong? on that man page.

Posted: Thu Mar 08, 2007 10:08 pm
by me!
:oops: Ok, I feel stupid now I totally missed that!

Thanks!

Posted: Fri Mar 09, 2007 11:35 am
by RobertGonzalez
that's why we're here... :D

Posted: Fri Mar 09, 2007 9:42 pm
by aaronhall
Everah wrote:that's why we're here... :D
To make people feel stupid, that is :D

Posted: Sat Mar 10, 2007 3:51 pm
by me!
Ok I still don't know what I am doing wrong.... :cry:

Also If anyone knows a better way to do this let me know...

Items are set as follows:

Code: Select all

// start  arrays 
$weeks = array();
$days = array();
$rate = array();
						

//get system settings from db
$results = mysql_query("SELECT * FROM settings");
	while ($mysql = mysql_fetch_array($results)) 
		{
		 // week 1 THIS IS REPEATED FOR ALL 10 WEEKS
		if ($week_1 == '1') {	$days['w1'] = 'Full Day, Full Week';
						$rate['r1'] = ($mysql[fd_mf]); 
						$weeks['week_1'] = ($mysql[week_1]);}
		if ($week_1 == '2') {	$days['w1'] = 'Full Day, Monday, Wednesday, Friday';
						$rate['r1'] = ($mysql[fd_mwf]);
						$weeks['week_1'] = ($mysql[week_1]) ; }
		if ($week_1 == '3') {	$days['w1'] = 'Full Day, Tuesday & Thursday';
						$rate['r1'] = ($mysql[fd_tt]);
						$weeks['week_1'] = ($mysql[week_1]) ; }
		if ($week_1 == '4') {	$days['w1'] = '<b>Half Day</b>, Full Week';
						$rate['r1'] = ($mysql[hd_mf]);
						$weeks['week_1'] = ($mysql[week_1]) ; }
		if ($week_1 == '5') {	$days['w1'] = '<b>Half Day</b>, Monday, Wednesday, Friday';
						$rate['r1'] = ($mysql[hd_mwf]); 
						$weeks['week_1'] = ($mysql[week_1]) ;}
		// You get the idea...
                }		

And this is the code that is sending the "notice Undefined index" warnings in the email:

Code: Select all

//Turn on output buffering
ob_start(); 

						
// show weeks selected
if ($week_1 != '0') echo ''.$weeks['week_1'].', '.$days['w1'].' - $'.$rate['r1'].' ';	
if ($week_2 != '0') echo ''.$weeks['week_2'].', '.$days['w2'].' - $'.$rate['r2'].' ';
if ($week_3 != '0') echo ''.$weeks['week_3'].', '.$days['w3'].' - $'.$rate['r3'].' ';
if ($week_4 != '0') echo ''.$weeks['week_4'].', '.$days['w4'].' - $'.$rate['r4'].' ';
if ($week_5 != '0') echo ''.$weeks['week_5'].', '.$days['w5'].' - $'.$rate['r5'].' ';
		
							
//copy current buffer contents into $message variable and delete current output buffer
$selections = ob_get_clean();	
						
													
// send E-mail to the person that registered	
$to  = "$email";							                  
$subject = 'Registration';						
$message = 'Some stuff plus '.$selections.'';

Posted: Sat Mar 10, 2007 4:17 pm
by John Cartwright
viewtopic.php?p=362999#362999

Do not double post, topic locked.