Jump to content

Quary display error


R0n1n66

Recommended Posts

This is a snippet from a site i built the code is suppose to take information from a database and display it  then if the user changes it via a drop down menu and an update button it will change the information and again display it.  The first display labeled infants works correctly but then nothing else does.  It all updates the DB like it is suppose to but just wont display it.  I have been banging my head for days on this any help would be great.  FYI  This all worked properly for about 8 months then just one day stopped.

 

mysql_query("update schedule set ".$field_name." = '".$_POST['infant_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='infants' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['wobbler_ch']."' where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='wobler' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['orange_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='orange' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['green_ch']."'   where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='green' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['red_ch']."'     where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='red' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['blue_ch']."'    where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='blue' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['purple_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='purple' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['yellow_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='yellow' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['silver_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='silver' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['school_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='clubhouse' ");
 
 
$enroll_query = mysql_query("select * from schedule Where employee = 'Enrollment' and CURDATE() between start_date and end_date and schedule_track_id = '".$track_id."' ");
while($data = mysql_fetch_assoc($enroll_query))
{
$enroll_data[] = $data;
}
 
$new_field_name = $field_name.'_s';
 
 
// This is the display section//
 
<td align="center" valign="top"><table width="90" border="1" cellpadding="0">
              <tr>
                <td height="200" align="center" valign="middle"><label for="infant_ch"></label>
                  <select name="infant_ch" id="infant_ch">
                    <?php 
if($enroll_data[0]['class'] == 'infants')
{
$data_field = $enroll_data[0][$field_name];
 
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" <?php if ($i==$data_field) { echo "selected";}?>><?php echo $i; ?></option>
                    <?php
}
}
else
{
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
                    <?php
}
}
?>
                  </select></td>
              </tr>
              <tr>
                <td height="200" align="center"><label for="wobbler_ch"></label>
                  <select name="wobbler_ch" id="wobbler_ch">
                    <?php 
if($enroll_data[1]['class'] == 'wobler')
{
$data_field = $enroll_data[1][$field_name];
 
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" <?php if ($i==$data_field) { echo "selected";}?>><?php echo $i; ?></option>
                    <?php
}
}
else
{
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
                    <?php
}
}
?>
                  </select></td>
              </tr>
              <tr>
                <td height="200" align="center"><label for="orange_ch"></label>
                  <select name="orange_ch" id="orange_ch">
                    <?php 
if($enroll_data[2]['class'] == 'orange')
{
$data_field = $enroll_data[2][$field_name];
 
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" <?php if ($i==$data_field) { echo "selected";}?>><?php echo $i; ?></option>
                    <?php
}
}
else
{
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
                    <?php
}
}
?>
                  </select></td>
              </tr>
              <tr>

 

Link to comment
Share on other sites

Please use code tags.

 

mysql_query("update schedule set ".$field_name." = '".$_POST['infant_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='infants' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['wobbler_ch']."' where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='wobler' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['orange_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='orange' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['green_ch']."'   where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='green' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['red_ch']."'     where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='red' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['blue_ch']."'    where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='blue' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['purple_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='purple' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['yellow_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='yellow' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['silver_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='silver' ");
mysql_query("update schedule set ".$field_name." = '".$_POST['school_ch']."'  where schedule_track_id = '".$track_id."' and employee = 'Enrollment' and class='clubhouse' ");
 
 
$enroll_query = mysql_query("select * from schedule Where employee = 'Enrollment' and CURDATE() between start_date and end_date and schedule_track_id = '".$track_id."' ");
while($data = mysql_fetch_assoc($enroll_query))
{
$enroll_data[] = $data;
}
 
$new_field_name = $field_name.'_s';
 
 
// This is the display section//
 
<td align="center" valign="top"><table width="90" border="1" cellpadding="0">
              <tr>
                <td height="200" align="center" valign="middle"><label for="infant_ch"></label>
                  <select name="infant_ch" id="infant_ch">
                    <?php 
if($enroll_data[0]['class'] == 'infants')
{
$data_field = $enroll_data[0][$field_name];
 
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" <?php if ($i==$data_field) { echo "selected";}?>><?php echo $i; ?></option>
                    <?php
}
}
else
{
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
                    <?php
}
}
?>
                  </select></td>
              </tr>
              <tr>
                <td height="200" align="center"><label for="wobbler_ch"></label>
                  <select name="wobbler_ch" id="wobbler_ch">
                    <?php 
if($enroll_data[1]['class'] == 'wobler')
{
$data_field = $enroll_data[1][$field_name];
 
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" <?php if ($i==$data_field) { echo "selected";}?>><?php echo $i; ?></option>
                    <?php
}
}
else
{
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
                    <?php
}
}
?>
                  </select></td>
              </tr>
              <tr>
                <td height="200" align="center"><label for="orange_ch"></label>
                  <select name="orange_ch" id="orange_ch">
                    <?php 
if($enroll_data[2]['class'] == 'orange')
{
$data_field = $enroll_data[2][$field_name];
 
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" <?php if ($i==$data_field) { echo "selected";}?>><?php echo $i; ?></option>
                    <?php
}
}
else
{
for($i=0;$i<=30;$i++)
{
?>
                    <option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
                    <?php
}
}
?>
                  </select></td>
              </tr>
              <tr>
Is your query failing? Try:
$enroll_query = mysql_query("select * from schedule Where employee = 'Enrollment' and CURDATE() between start_date and end_date and schedule_track_id = '".$track_id."' ") or die(mysql_error());
Link to comment
Share on other sites

Ok the Quary is not failing from what i can tell it seems the display is whats failing. The database updates when you change the selection on the site and press update.  The page for some reason is only displaying the first selection correctly the rest just say 0.  Also noob question here do you me comment my code when you say use code tags.  

Link to comment
Share on other sites

When you make a post, on the editor there is a "<>" symbol. Click that and it will create a code start/stop tag. You post your code between those tags so it gets formatted and highlighted like in scootstahs post.

Edited by CroNiX
Link to comment
Share on other sites

Can you show me what the output of this is:

while($data = mysql_fetch_assoc($enroll_query))
{
    $enroll_data[] = $data;
}

echo '<pre>' . print_r($enroll_data, true) . '</pre>'; exit;

Also noob question here do you me comment my code when you say use code tags.

No, I mean to use this forum's BBCode code tags when you post code snippets. Just wrap the code you post in code tags, like this:

code here

EDIT: go with what CroNiX said since you're probably using the WYISWYG editor

 

See how the code I posts is all in a nice pretty syntax-highlighted box, and yours is a huge wall of text?

Edited by scootstah
Link to comment
Share on other sites

I see thanks.

 

 

 
Array
(
[0] => Array
(
[schedule_id] => 4572
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-02 12:05:56
[employee] => Enrollment
[monday] => 11
[tuesday] => 15
[wednesday] => 11
[Thursday] => 12
[friday] => 11
[class] => infants
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[1] => Array
(
[schedule_id] => 4573
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 11
[tuesday] => 0
[wednesday] => 0
[Thursday] => 12
[friday] => 10
[class] => orange
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[2] => Array
(
[schedule_id] => 4574
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 12
[tuesday] => 0
[wednesday] => 0
[Thursday] => 12
[friday] => 14
[class] => green
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[3] => Array
(
[schedule_id] => 4575
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 12
[tuesday] => 0
[wednesday] => 0
[Thursday] => 15
[friday] => 9
[class] => red
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[4] => Array
(
[schedule_id] => 4576
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 12
[tuesday] => 0
[wednesday] => 0
[Thursday] => 14
[friday] => 13
[class] => blue
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[5] => Array
(
[schedule_id] => 4577
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 14
[tuesday] => 0
[wednesday] => 0
[Thursday] => 16
[friday] => 12
[class] => purple
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[6] => Array
(
[schedule_id] => 4578
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 18
[tuesday] => 0
[wednesday] => 0
[Thursday] => 17
[friday] => 15
[class] => yellow
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[7] => Array
(
[schedule_id] => 4579
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 15
[tuesday] => 0
[wednesday] => 0
[Thursday] => 15
[friday] => 14
[class] => silver
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[8] => Array
(
[schedule_id] => 4580
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 20
[tuesday] => 0
[wednesday] => 0
[Thursday] => 26
[friday] => 19
[class] => clubhouse
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)

[9] => Array
(
[schedule_id] => 4630
[schedule_track_id] => 50
[saved_name] => July 6-July 10
[time_stamp] => 2015-07-08 10:51:31
[employee] => Enrollment
[monday] => 11
[tuesday] => 15
[wednesday] => 8
[Thursday] => 12
[friday] => 10
[class] => wobler
[start_date] => 2015-07-06
[end_date] => 2015-07-10
[monday_s] => y
[tuesday_s] => y
[wednesday_s] => y
[Thursday_s] => y
[friday_s] => y
[monday_bold] => y
[tuesday_bold] => y
[wednesday_bold] => y
[Thursday_bold] => y
[friday_bold] => y
)
 
Link to comment
Share on other sites

So one thing I'm noticing is that the order of the data returned from your query is not the same order that you expect it to be in the code. I see this: if($enroll_data[1]['class'] == 'wobler'), but the 1th index of the data you just showed me is of class "orange".

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.