Search found 22 matches

by sweetpeet
Mon Apr 01, 2013 11:40 am
Forum: PHP coding => General
Topic: Array issue
Replies: 13
Views: 2033

Re: Array issue

try this:     $Edit_included = array( "null", $bread, $saladDressing, $tomato, $lettuce, $onion);     echo 'Included: ';     foreach( $Edit_included as $new_details ){        $variable .= (!empty($new_details))?$new_details . ', ':'';        }        $variable = trim($variable, ',');        echo $v...
by sweetpeet
Mon Apr 01, 2013 11:29 am
Forum: PHP coding => General
Topic: Array issue
Replies: 13
Views: 2033

Re: Array issue

please show the output you're receiving, and the output you'd like. This is what I'm getting (it doesn't seem to be appending any more, which is good): Included: null, , , tomato, lettuce, onion, This is what I want: Included: null, tomato, lettuce, onion, And this is the code I have: $Edit_include...
by sweetpeet
Mon Apr 01, 2013 10:59 am
Forum: PHP coding => General
Topic: Array issue
Replies: 13
Views: 2033

Re: Array issue

It seems like i may have missed your intent.. I thought you wanted to output the whole list. if you only want to output the last, then remove the period before the equals in line 4. No, you were partially correct. I do want to output the whole string, and what you provided was good. I just don't wa...
by sweetpeet
Mon Apr 01, 2013 10:53 am
Forum: PHP coding => General
Topic: Array issue
Replies: 13
Views: 2033

Re: Array issue

if it's only outputting the last, that tells me that you missed the '.' before the '='. So on each iteration it is overwriting the existing value instead of appending the new value. take another look at line 4 of my example Actually thats exactly what it is doing, it is appending the new value to t...
by sweetpeet
Mon Apr 01, 2013 10:29 am
Forum: PHP coding => General
Topic: Array issue
Replies: 13
Views: 2033

Re: Array issue

you don't want to assign a foreach loop to a variable (which would be done by having a function containing only the foreach loop that returns the value) you want to append values to a variable during a foreach loop.     $Edit_included = array( "null" ,$bread, $saladDressing, $tomato, $lettuce, $oni...
by sweetpeet
Mon Apr 01, 2013 10:07 am
Forum: PHP coding => General
Topic: Array issue
Replies: 13
Views: 2033

Re: Array issue

Thanks for the help, I decided to do something else that worked. $x=1; $Edit_included = array( "null" ,$bread, $saladDressing, $tomato, $lettuce, $onion, ); echo 'Included: '; foreach( $Edit_included as $new_details ){ echo $new_details; echo', '; $x++; } However, now that I have that(above). Is it ...
by sweetpeet
Mon Apr 01, 2013 7:32 am
Forum: PHP coding => General
Topic: Array issue
Replies: 13
Views: 2033

Array issue

I am having a problem with creating this array.
This is what I have:

Code: Select all

$c = 'swiss cheese';

	$value = array('$c', 'test2' );

	echo $value . '<br/>';
	echo("this is what is included $value");
For some reason when it runs it just outputs the word "Array". Does anyone know why?
by sweetpeet
Mon Mar 04, 2013 8:42 am
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

Re: New row array

yes, $_SESSION['sandwiches'] should be an array of sandwich objects. I'm working right now, but i'll write up a sample sandwich class in a little bit if you want so you see what i mean So, I did get the cart to work with the String variable but it does not really function like a typical shopping ca...
by sweetpeet
Thu Feb 28, 2013 4:53 pm
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

Re: New row array

The $_SESSION['sandwiches'] would contain a whole list of objects. If you set a __toString() method in your sandwich class, then you could just explode $_SESSION['sandwiches'] with a delimiter string of '<br />' to have it print a whole list of all of them except that my $_SESSION['sandwich'] does ...
by sweetpeet
Thu Feb 28, 2013 1:36 pm
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

Re: New row array

I really think that an object oriented approach would be best. assuming you have a sandwich object, that has its own properties to store components etc; you could have a function that adds it to a session variable also like... $_SESSION['sandwiches'] = array(); $blah = $_SESSION['sandwiches'];  pub...
by sweetpeet
Thu Feb 28, 2013 10:30 am
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

Re: New row array

Do you thing that using array_push() will work all the same? this is basically what im thinking: <?php switch( $_SESSION['Sandwich']){ case 'sandwich1': $string1 = 'sandwich1'; array_push($new_array, $string1); case 'Sandwich2': $string2 = 'sandwich2'; array_push($new_array, $string2);} $array = arr...
by sweetpeet
Wed Feb 27, 2013 9:14 am
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

Re: New row array

It depends on how long you'd like to persist the data. If it's data you only need short term for a single visitor, then a session or cookie will do the job perfectly. If you're trying to create a persistent table that will be viewable by everyone, then a database is the way to go, and you can dynam...
by sweetpeet
Wed Feb 27, 2013 7:40 am
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

Re: New row array

You're using some variables in there that aren't defined in the provided code, so I'm assuming they've got valid values. This should work. <?php           $sandwich=array('Palfy', 'calapso', 'moneray');           $ItemCount=count($sandwich);            echo '<table border="2" cellspacing="0" cellpa...
by sweetpeet
Tue Feb 26, 2013 10:21 am
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

Re: New row array

ok I just came up with something but I'm having a problem with the incremental number repeating duplicates and the item also repeating. any thoughts? $Item=array("Palfy"=>1,"Calapso"=>2,"Moneray"=>3); $sandwich=array('Palfy', 'calapso', 'moneray'); $ItemCount=count($sandwich); for($i=1; $i < $ItemCo...
by sweetpeet
Mon Feb 25, 2013 3:26 pm
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

Re: New row array

Kind of... Yes I want the next available index but I want that index to show up with a table around each individual index.
by sweetpeet
Wed Feb 20, 2013 2:45 pm
Forum: PHP coding => General
Topic: New row array
Replies: 15
Views: 2384

New row array

I am trying to create an array that will create a new row as new variables are entered into the array or one that saves the old row and adds the new one. I know in general how to create an array buy only for listing integers and strings. My problem is that I can't really organize the data. Here's wh...
by sweetpeet
Fri Feb 15, 2013 11:31 pm
Forum: PHP coding => General
Topic: referencing a variable from 1 php file to another
Replies: 11
Views: 2549

Re: referencing a variable from 1 php file to another

I presume you want to get the value selected from the dropdown menu, not just echo out the dropdown menu in future, in which case you don't assign the whole menu to a variable you just have the menu on your form and then get the valu posted from it. In the form: <select name="bagelT"><option value=...
by sweetpeet
Fri Feb 15, 2013 5:44 pm
Forum: PHP coding => General
Topic: referencing a variable from 1 php file to another
Replies: 11
Views: 2549

Re: referencing a variable from 1 php file to another

no, just the session variables. ok, but when I enter something like this: $_session['bagel'] = $bagelT where, $bagelT = '<select name="bagelT"><option value="select">Select One</option><option value="wheat">Wheat Bagel</option><option value="blueberry"> Blueberry Bagel</option><option value="asiago...
by sweetpeet
Fri Feb 15, 2013 3:44 pm
Forum: PHP coding => General
Topic: referencing a variable from 1 php file to another
Replies: 11
Views: 2549

Re: referencing a variable from 1 php file to another

so, every single variable must look like this: $_SESSION['firstname'] = 'whatever';?
by sweetpeet
Thu Feb 14, 2013 4:36 pm
Forum: PHP coding => General
Topic: referencing a variable from 1 php file to another
Replies: 11
Views: 2549

Re: referencing a variable from 1 php file to another

Everything you all have given me has been very helpful. How do I assign a variable to a session? I have attempted it two ways: $_SESSION['bagelT'] = $bagelT; $_SESSION['selectBread'] = '$selectBread';. but neither of them return what is defined to the variable. For the case of bagelT it is as follow...
by sweetpeet
Thu Feb 14, 2013 11:50 am
Forum: PHP coding => General
Topic: referencing a variable from 1 php file to another
Replies: 11
Views: 2549

Re: referencing a variable from 1 php file to another

It depends how you want to get them to page B. If page A has another form that is posted to page B then you can just put the variables in has hidden inputs in the form. If you are not using another form then your only option is to use sessions. Do you need help on using sessions? yes, I guess than ...
by sweetpeet
Wed Feb 13, 2013 7:17 pm
Forum: PHP coding => General
Topic: referencing a variable from 1 php file to another
Replies: 11
Views: 2549

referencing a variable from 1 php file to another

Hello all, I am a newbie to PHP, so I apologize ahead of time if this question seems to be quite elementary. I have two PHP files, we'll call them file A and file B. The first file, file A grabs all it's values from an html file that uses <form method=post> with name and value, etc.. then I use $_PO...