[SOLVED] Nested variables that return another variable

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

Post Reply
THEMADGEEK
Forum Newbie
Posts: 21
Joined: Thu Oct 30, 2003 6:04 pm

[SOLVED] Nested variables that return another variable

Post by THEMADGEEK »

I am using a calendar script that dynamically builds the calendar for each month, I use it for scheduling purposes. I have placed a checkbox in each day so users can indicate they are available that day. This all works great for putting the info INTO the database.

My problem lies in pulling it out so a user can change update their schedules.

My database (MySQL) returns data from an ENUM field that is y or n and I am trying to dynamically turn the 'y's into a "checked" variable so the boxes that they had previously selected will show up checked in the calendar.

I am having a time getting the two nested variables to return another variable that coincides with the output from the database thus properly checking the boxes I want checked.

Basically I have $var1, $var2, $var3... (with numbers 1-31) etc. returned from the DB and I have a variable $i that returns each day for the calendar. I am attempting to replace the number in the $var* field with the $i from the calendar so I get $var# again with the proper corresponding day of the month (1,2,3... etc) instead of them all returning what the answer is for the 1st of the month.

How do I drop the number from the one DB variable and replace it with the corresponding number from the calendar?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i have a problem trying to visualize this. i know what you are doing, but in the process of trying to solve the issue in my head a long with your problem it kinda hurts me hehe. got any code to make my life easier? it sounds like you are going about this a very long and unecessary way ;)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Same here ;)
I tried to visualize it and ended up seeing an elephant in a pink leotard and i'm pretty sure that's not the intended result.
THEMADGEEK
Forum Newbie
Posts: 21
Joined: Thu Oct 30, 2003 6:04 pm

Post by THEMADGEEK »

LOL why am I not surprised... I've been doing the same thing and I'm working on it!

I probably am going about it longhand as that is my luck Here's some snippets to maybe help get rid of the pink elephant...

Here is what I am getting out of the DB:

Code: Select all

while ($row = mysql_fetch_array($result))

{

$mbr_id = $rowї'mbr_id'];
$d1 = $rowї'1st'];
$d2 = $rowї'2nd'];
$d3 = $rowї'3rd'];
$d4 = $rowї'4th'];
$d5 = $rowї'5th']; etc...
d1 is the first d2 is the second etc. I had to have each day represented in the DB and wanted to understand what the field was.

Then there's the if stuff...

Code: Select all

if ($d1 == "y") {
$d1 =  "checked"; }
if ($d2 == "y") {
$d2 =  "checked"; } etc...
Here is what the calendar does for the days:

Code: Select all

for ($i = 1; $i <= $days_in_month; $i++) &#123;
	$days_so_far = $days_so_far + 1;
	$count_boxes = $count_boxes + 1;
	IF($_GET&#1111;'month'] == $todays_month+1)&#123;
	IF($i == $todays_date)&#123;
	$class = "highlighteddayboxes";
	&#125; ELSE &#123;
	$class = "dayboxes";
	&#125;
	&#125; ELSE &#123;
	IF($i == 1)&#123;
	$class = "highlighteddayboxes";
	&#125; ELSE &#123;
	$class = "dayboxes";
	&#125;
	&#125;
As you can see $i returns the day i.e. 1, 2, 3 etc for each day of the calendar.

Lastly here is the input tag, this is dynamically placed in every calendar day.

Code: Select all

<input type="checkbox" name="d$i" value="y" $marked>
What I need to do is make $marked return $d1, $d2, $d3 dynamically so it properly checks the checkboxes for the appropriate days.

Is that any clearer or has the elephant just changed clothes?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i guess it's wherei 'm still at school and my contact is bothering me.. i'm leaving class. if no one has answere before i get home, i'll see if i can't help you out.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Not too sure if this is what you want or not, but here's a relevant example. Once you've got all your $d1 = 'checked'; $d2 = ''; whatever (by the way i'd change that to ' checked') then here's a little example that creates the checkboxes and if $d6 is ' checked' for example then the checkbox is checked..if $d6 is '' , then it isn't.

Code: Select all

for($i=1; $i<31; $i++)&#123;
  $marked = 'd'.$i;
  echo "<input type="checkbox" name="whatever" value="y"$&#123;$marked&#125;>";
&#125;
Hope this is along the lines of what you're after, if not .. :o
THEMADGEEK
Forum Newbie
Posts: 21
Joined: Thu Oct 30, 2003 6:04 pm

Post by THEMADGEEK »

That did it markl999!

Thanks so much both of you...

:D
Post Reply