passing variables back to same original page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

superdesign, thanks but im aware of that
example :

Code: Select all

$name = $_POST['name'];
or the request:

Code: Select all

$name = $_REQUEST['name'];
I'm aware of the Super_Globals
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Well, it sounds like you're asking to be taught, so I offered you a place to learn. W3School's tutorials are very short and simple, and don't take more than a few minutes to read.

No need to be so sarcastic. We help those who help themselves.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

I'm aware of Arrays , newArrays, associative arrays

Code: Select all

$price = array('product1' => $100.00, 'product2' => $200) etc.
but see what I been saying is, its just this code for this one page, I've never written before, not exactly sure what it should look like/ be coded like.

Thanks.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

super , Im not asking to be taught, I'm cert in php basics, and php/mySQL programming

but thanks for making yourself feel sporty :)
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

correct if your next comment is to say im not an 'expert'

otherwise i wouldnt be here chasing around the mullberry bush getting 'schooled'.

kinda odd, my first day signing up to this forum , 4 hours later, and i have people basically scolding me like a school kid.

for asking a simple coding question, which turned into the 'youre an idiot' charade.

Im not trying to be rude, im just tyring to ask nicely if somebody could help me to see what that code would look like.

thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<select name="a"  STYLE="width: 110 px">
      <option selected="selected" value="">Please Select</option>
      <option value="100">100</option>
      <option value="500">500</option>
      <option value="1,000">1,000</option>
      <option value="2000">2,000</option>
      <option value="3000">3,000</option>
      <option value="4000">4,000</option>
      <option value="5000">5,000</option>
      <option value="10000">10,000</option>
</select>
Can be translated like this, into PHP using an array...

Code: Select all

<?php
$selects = array();
$selects['a'] = array('100', '500', '1,000', '2000', '3000', '4000', '5000', '10000');
// So on with the other select lists

echo '<select name="a">';
foreach ($selects['a'] as $value) {
    echo '<option value="' . $value . '">' . $value . '</option>';
}
echo '</select>';
?>
To check equality in that loop, you would first need to know what the posted value for a is, if there is one at all.

Code: Select all

<?php
// Default values for posted form elements
$a = '100';
if (!empty($_POST['a'])) {
  $a = $_POST['a']; // This really should be validated before using it
}

// Other code from above, and now on to the loop
echo '<select name="a">';
foreach ($selects['a'] as $value) {
    $selected =  ($a == $value) ? ' selected="selected"' : ''; // Ternary operator used to set selected item
    echo '<option value="' . $value . '"' . $selected . '>' . $value . '</option>';
}
echo '</select>';
?>
Last edited by RobertGonzalez on Tue May 29, 2007 2:08 pm, edited 1 time in total.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

thank you very much Everah :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

@superdezign and @revocause: Please stop the bickering or I will close this thread. The goal is to help people. Let's get back to doing that here shall we?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

revocause wrote:thank you very much Everah :)
Get the new code I posted as there was a small problem with it. It is clean now though.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

Everah,

in that code you made

whats the code look like to add values to 'string' display names ?

example if select options have
<option value ="1.50" > "widget 1"</option>
<option value ="2.50" > "widget 2"</option>
etc.

and from your code example, I'd have to use the PHP script for every individual select menu.
because i used it in <HEAD> PHP </HEAD>
and also put the HTML select menu in the body , and it caused 2 menus of the same type.
except the PHP menu was floating off in left field

How much do you charge to write this darn code?
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

and whats with that avatar = forum commoner?

are moderators insulting new members?
you never know who's on here right?
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

everah,

I will pay you to code the select menu.
That way i can see it in its entirety, and at that point I can rad the language well enough
to understand whats being done.

but this stuff is wasting a whole day.

let me know
thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

revocause wrote:and whats with that avatar = forum commoner?

are moderators insulting new members?
you never know who's on here right?
Forum Commoner is a title for users. It is based on post count and nothing more.

PM me with what you want out of your script and what you currently have. I'll take a look and let you know if I will do it.
Post Reply