Jump to content

Recommended Posts

Hi 

 

Hoping someone can help so frustrated with this as I cant figure it out.

 

This is what has to happen.

 

Create a function of your choice. The function must accept  5 arguments. Create a form that accepts 5 arguments, each via a drop-down menu and echo the results back to the user.

 

This is what I have so far.

 

 

 

<?php

// Declare the function and variables


error_reporting (0);
$msg = "";
$activity = "";


// Make sure the submit button has been selected


if (isset ($_POST ['submit'])){


function activites ($paintballing , $ice_skating, $horse_riding, $para_gliding, $water_rafting ){


// Make the activity array


$activites = array (1=> 'Paintballing', 'Ice_skating', 'Horse_riding', 'para_gliding', 'water_rafting');






// use a foreach loop to loop through the activity


foreach ($activites as $key =>$value) {
$msg = "We trust you will enjoy $activity today. Have fun and create memories";
}


}


if ($activity == ""){
$msg = "<font color = 'red'> Please select an activity from the drop down menu</font>";


}


?>






<html>
<head>
<title>Function </title>
</head>
<body>
<center> <a href="index.php">Home </a>  |  <a href ="calc.php">Calc</a> | <a href="string.php">String</a> | <a href ="array.php"> Array </a> | <a href = "function.php">Function </a></center>
</center>


<form name = 'function' method = "POST" action = 'function.php' >


<p>Select one of the activity you would like to do today:</p>


<select name="Activity" size="5">
<option selected value = "">
<option> Paintballing </option>
<option> Ice-skating </option>
<option> Horse-riding </option>
<option> Para-gliding </option>
<option> Water-rafting </option>
</select>
</form>
<input type = "submit" name = "submit" value = "submit" />
</option>
<?php echo $msg;?>
<p align ="center"><a href ="function.txt" Onclick ="window.open ('function.txt', 'function', resizable =no, height=500, width=500, scrollercars=yes'); retrun false;">Function.txt</a></p>

 
Edited by KevinM1
Code tags
Link to comment
https://forums.phpfreaks.com/topic/276025-php-function/
Share on other sites

In the future, when attempting to post code on these forums, press the <> button on the editor.  That will format the code so it looks readable.

 

Also, we generally do not answer homework questions.  The general thought is that if the person looking for help paid attention in class and took good notes, they should be able to successfully complete their assignment.  We're here to help, but not do all of the work.  With classwork, we don't want to be a crutch that stops people from actually learning.

 

So, like Psycho said, do you have a question more specific than "How do I do the rest?"

Link to comment
https://forums.phpfreaks.com/topic/276025-php-function/#findComment-1420355
Share on other sites

Well for one it doesn't appear that your calling the function any where i.e.:

 

function test(){

echo 'hi';

}

test();

 

and also your missing a "}" for one of your items not sure which one also if your running $_POST you need to retrieve the data to I'm assuming push into that function so:  

 

activites($_POST['paintballing'], $_POST['ice_skating'], $_POST['horse_riding'], $_POST['para_gliding'], $_POST['water_rafting'] );

 

would be your function call. Is this useful?

Link to comment
https://forums.phpfreaks.com/topic/276025-php-function/#findComment-1420356
Share on other sites

I don't know why but I found myself messing around with this code :confused:

 

I know this isn't the way it's supposed to be done, but this is definitely screaming database... :happy-04:

 

I wasn't going to post this, but I thought well it might help you out a little.

 

activities.php

<?php
$msg = "";
$activites = array ('Paintballing', 'Ice_skating', 'Horse_riding', 'para_gliding', 'water_rafting');

$output = "<nav><ul>" ;
foreach ($activites as $key => $value)
{
    $output .= "<li><a href=\"activities.php?page=" . ($key+1) . "\" >" . $value . "</a></li>";    
    $message[$key+1] = "We trust you will enjoy " . $value . " today. Have fun and create memories";
}


$output .= "</ul></nav>";

if (isset($_GET['page']))
{    
    switch ($_GET['page']) {
      case 1:
           $msg = $message[1];
           break;
      case 2:
           $msg = $message[2];
           break;
      case 3:
           $msg = $message[3];
           break;
      case 4:
           $msg = $message[4];
           break;
      case 5:
           $msg = $message[5];
           break;                       
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">

<style type="text/css">
nav {
    clear: both;
    display: block;
    width: 200px;
    height: 120px;
    padding: 0px;
    margin: 0px;    
}
nav ul {
    list-style: none;
    padding: 0px;
    margin: 0px;
}
nav ul li {
    padding: 0px;
    margin: 0px;    
}

nav ul li a {
    float: left;
    display: block;
    width: 180px;
    height: 25px;
    background: #ebebeb;    
    border-bottom: 1px solid #40352F;
    font-family: Arial, Helvetica, sans-serif;
        font-size: 1.0em;
        line-height: 25px;
        color: #1C11B5;
        font-weight: bold;
        text-decoration: none;
    padding: 0px 10px 0px 10px;
    margin: 0px;    
}

nav ul li a:hover {
    color: #40352F;
    background: #FEE494;
    padding: 0px 10px 0px 10px;
    margin: 0px;    
}

</style>

<title>Untitled Document</title>
</head>
 
<body>

<H1>Please select an activity from the drop down menu</H1>
<?php echo $output; ?>

<p><?php echo $msg; ?></p>



</body>
</html>
 
Edited by Strider64
Link to comment
https://forums.phpfreaks.com/topic/276025-php-function/#findComment-1420375
Share on other sites

 

I don't know why but I found myself messing around with this code :confused:

 

I know this isn't the way it's supposed to be done, but this is definitely screaming database... :happy-04:

 

I wasn't going to post this, but I thought well it might help you out a little.

 

activities.php

<?php
$msg = "";
$activites = array ('Paintballing', 'Ice_skating', 'Horse_riding', 'para_gliding', 'water_rafting');

$output = "<nav><ul>" ;
foreach ($activites as $key => $value)
{
    $output .= "<li><a href=\"activities.php?page=" . ($key+1) . "\" >" . $value . "</a></li>";    
    $message[$key+1] = "We trust you will enjoy " . $value . " today. Have fun and create memories";
}


$output .= "</ul></nav>";

if (isset($_GET['page']))
{    
    switch ($_GET['page']) {
      case 1:
           $msg = $message[1];
           break;
      case 2:
           $msg = $message[2];
           break;
      case 3:
           $msg = $message[3];
           break;
      case 4:
           $msg = $message[4];
           break;
      case 5:
           $msg = $message[5];
           break;                       
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">

<style type="text/css">
nav {
    clear: both;
    display: block;
    width: 200px;
    height: 120px;
    padding: 0px;
    margin: 0px;    
}
nav ul {
    list-style: none;
    padding: 0px;
    margin: 0px;
}
nav ul li {
    padding: 0px;
    margin: 0px;    
}

nav ul li a {
    float: left;
    display: block;
    width: 180px;
    height: 25px;
    background: #ebebeb;    
    border-bottom: 1px solid #40352F;
    font-family: Arial, Helvetica, sans-serif;
        font-size: 1.0em;
        line-height: 25px;
        color: #1C11B5;
        font-weight: bold;
        text-decoration: none;
    padding: 0px 10px 0px 10px;
    margin: 0px;    
}

nav ul li a:hover {
    color: #40352F;
    background: #FEE494;
    padding: 0px 10px 0px 10px;
    margin: 0px;    
}

</style>

<title>Untitled Document</title>
</head>
 
<body>

<H1>Please select an activity from the drop down menu</H1>
<?php echo $output; ?>

<p><?php echo $msg; ?></p>



</body>
</html>
 

 

Thank you Strider64. 

 I am batlling with php :-( and having to learn it online is harder.

I am trying to use a function tho and not a case statement.

 

Your post gave me some much needed light.

Link to comment
https://forums.phpfreaks.com/topic/276025-php-function/#findComment-1420382
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.