Jump to content

Array not showing values later in script.


sillysillysilly

Recommended Posts

Sorry to bother you guys so late at nigth but I have a problem (besides women, drinking, global warming and women)

 

I have a script where I want to pass data to an array; later I will check to see if some of the data is in the database based on a date in a form using check boxes.  Basicly I am creating a series of checkboxes based on a datename.  I can create them once, but later when I call that same variable array there is nothing there.  Here is a snippet of my code.

 

while ($i <15){

     

$inputmorning= array( $i => "Morning <input type='checkbox' name='$orderdate morning' value='' /> ");

echo $inputmorning[$i];

$inputafternoon= array($i => "<input type='checkbox' name='$orderdate afternoon' value=''/> ");

echo $inputafternoon[$i];

$inputafterevening= array($i => "<input type='checkbox' name='$orderdate evening' value=''/> ");

$i++;

}

 

 

Later I try to recall all of those same check boxes with.

 

$i=0;

while ($i<14){

$date = mktime(0,0,0,date("m"),date("d")+$i,date("Y"));

$orderdate = date("Y/m/d", $date);

echo "<tr><td>".$orderdate . "</td><td>$inputmorning[$i]</td><td>$inputafternoon[$i]</td><td>$inputevening[$i]</td></tr>";

//echo "<tr><td>".$orderdate . "</td><td>test $i</td><td>test $i</td><td>test $i</td></tr>";

$i++;

}

 

the date shows up, but no check boxes. 

 

Any ideas.  (on the script - I'm not sure anyone can help us on the global warming or women)

Link to comment
Share on other sites

have you checked the HTML source code to see whats appearing?

 

you might need to use htmlentities when printing the data back to the page.

 

As for Global warming - Who cares lol?

as for Women the secret is to keep swapping the old out with the new, example

 

if($women['days']) < 7)
{
    keepDating();
}
else
{
    findNewWomen("blonde", "bigtits");
}

 

Ben

Link to comment
Share on other sites

Let's change how you create the arrays:

<?php
$inputmorning = array();
$inputevening = array();
$inputafterevening = array();
for ($i=0;$i<15;$i++) {
   $inputmorning[$i] = "Morning <input type='checkbox' name='$orderdate morning' value='' /> ";
   $inputafternoon[$i] = "<input type='checkbox' name='$orderdate afternoon' value=''/> ";
   $inputevening[$i] = "<input type='checkbox' name='$orderdate evening' value=''/> ";
}
echo '<pre>' . print_r($inputmorning,true) . "\n" . print_r($inputafternoon,true) . "\n" . print_r($inputevening,true) . '</pre>'; //debug
?>

rest of code redone:

<?php
for ($i = 0;$i<14;$i++) {
   $orderdate = date("Y/m/d",strtotime("+ $i days"));
   echo '<tr><td>' . $orderdate . '</td><td>' . $inputmorning[$i] . '</td><td>' . $inputafternoon[$i] . '</td><td>' . $inputevening[$i] . "</td></tr>\n";
}
?>

 

Now I will ask you what you're trying to accomplish, since it looks like you've overthought it.

 

Ken

 

Link to comment
Share on other sites

ben,

 

Now that is really funny.  I would put 'days' at closer to 40.  My wife would get so mad at me for that especially since she is about to download brian 1.1 in a few months!!

 

Ken

 

Thanks I have not tried it yet, I had tried a version of just setting the $inputmorning = array(); first but did not work.

 

What I am trying to do is to set up a series of checkboxes that will display in a table somewhat like a calander, then ask the database if any dates on orders matches those dates in the checkboxes.  Based on true or false I will make them checked.  (the customer can add more days if they wish or delete days).  This is a stop gap measure until I can figure out a piece of javascript that I found that has sticky days.  Here is what I want it to look like now.

 

Date          Morning            Afternoon        Evening

2009 july 21    X                                                 

2009 july 22    X                      X                         

2009 july 23    X                        X                X       

2009 july 24    X                                          X       

Link to comment
Share on other sites

Ken

 

The first part really did the trick, I can't figure out what I was doing wrong with my first attempt, you are obviously way better at this than I am.... Want a quick coding job/?

 

I edited the first half to show what you helped with there and all the boxes showed up, even without editing the bottom section.

 

Now my next task is to convert this into checked boxes where corresponding dates exist in the database.

 

I really do appreciate your help.

Link to comment
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.