Jump to content

No values shown in <select> aft using php code


genzedu777

Recommended Posts

Hi all,

 

Currently my dob_day is not showing any value, even though there is a value in the database, it seems like it is unable to retrieve the value.

 

No value was shown in the <select> box. Do you guys have any idea? Thanks

 

 

<?php
$query = "SELECT name, nric, gender, picture, dob_day FROM tutor_profile WHERE tutor_id = '" . $_GET['tutor_id'] . "'";
    
$data = mysqli_query($dbc, $query)
or die(mysqli_error($dbc));

// The user row was found so display the user data
if (mysqli_num_rows($data) == 1) {
	$row = mysqli_fetch_array($data);

    if ($row != NULL) {
      $name = $row['name'];
      $nric = $row['nric'];
      $gender = $row['gender'];
  $old_picture = $row['picture'];
  $dob_day = $row['dob_day'];
    }
    else {
      echo '<p class="error">There was a problem accessing your profile.</p>';
    }

//HTML CODING
<label for="dob" class="label">Date Of Birth</label>
<select id="dob_day" name="dob_day" value="<?php if (!empty($dob_day)) echo $dob_day; ?>">
  <option>
			<option>01</option>
			<option>02</option>
			<option>03</option>
			<option>04</option>
			<option>05</option>
			<option>06</option>
			<option>07</option>
			<option>08</option>
			<option>09</option>
			<option>10</option>
			<option>11</option>
			<option>12</option>
			<option>13</option>
			<option>14</option>
			<option>15</option>
			<option>16</option>
			<option>17</option>
			<option>18</option>
			<option>19</option>
			<option>20</option>
			<option>21</option>
			<option>22</option>
			<option>23</option>
			<option>24</option>
			<option>25</option>
			<option>26</option>
			<option>27</option>
			<option>28</option>
			<option>29</option>
			<option>30</option>
			<option>31</option>
		</select>
?>

 

[attachment deleted by admin]

Link to comment
Share on other sites

Add this above the line starting with "if ($row != NULL)"

 

print_r($row);

 

That should print the array of data you pulled down for tutor_id.

Show me what that gives you.

 

EDIT: Doh!, I missed <option> error that pikachu2000 pointed out :(.

Link to comment
Share on other sites

Hi Atrum,

 

Sorry for the late response.

 

Hey I got values in the date of birth, but it is still not showing in the drop down box. What could possibly be happening? Thanks

 

Array ( [0] => MUHAMMAD  [name] => MUHAMMAD  [1] => S89362A [nric] => S89362A [2] => M [gender] => M [3] => belitapic.jpg [picture] => belitapic.jpg [4] => 16 [dob_day] => 16 )

Link to comment
Share on other sites

Hi Pikachu2000,

 

Thanks for replying. However I still dont really get what you have meant

 

Currently the value for dob_day = '16'

 

However '16' is not reflected in my drop down box, apparently it is 'blank'. Under my option, I do have <option>16</option>, what do you mean by

Currently the <option>s do not have value= attributes.

 

Could you elaborate further? Thank you so much

 

<?php
<?php
$query = "SELECT name, nric, gender, picture, dob_day FROM tutor_profile WHERE tutor_id = '" . $_GET['tutor_id'] . "'";
    
   $data = mysqli_query($dbc, $query)
   or die(mysqli_error($dbc));
   
   // The user row was found so display the user data
   if (mysqli_num_rows($data) == 1) {
      $row = mysqli_fetch_array($data);

    if ($row != NULL) {
      $name = $row['name'];
      $nric = $row['nric'];
      $gender = $row['gender'];
     $old_picture = $row['picture'];
     $dob_day = $row['dob_day'];
    }
    else {
      echo '<p class="error">There was a problem accessing your profile.</p>';
    }

//HTML CODING
<label for="dob" class="label">Date Of Birth</label>
<select id="dob_day" name="dob_day" value="<?php if (!empty($dob_day)) echo $dob_day; ?>">
            <option value=''></option>
            <option>01</option>
            <option>02</option>
            <option>03</option>
            <option>04</option>
            <option>05</option>
            <option>06</option>
            <option>07</option>
            <option>08</option>
            <option>09</option>
            <option>10</option>
            <option>11</option>
            <option>12</option>
            <option>13</option>
            <option>14</option>
            <option>15</option>
            <option>16</option>
            <option>17</option>
            <option>18</option>
            <option>19</option>
            <option>20</option>
            <option>21</option>
            <option>22</option>
            <option>23</option>
            <option>24</option>
            <option>25</option>
            <option>26</option>
            <option>27</option>
            <option>28</option>
            <option>29</option>
            <option>30</option>
            <option>31</option>
         </select>
?>
?>

Link to comment
Share on other sites

Hi Pikachu2000,

 

I have followed your advice, but it still didnt work, I have done up to option value = '16', but there is no value in my drop down box.

 

Did I miss out anything? Thanks

 

<td><select id="dob_day" name="dob_day" value="<?php if (!empty($dob_day)) echo $dob_day; ?>">
			<option value=''></option>
			<option value='1'>01</option>
			<option value='2'>02</option>
			<option value='3'>03</option>
			<option value='4'>04</option>
			<option value='5'>05</option>
			<option value='6'>06</option>
			<option value='7'>07</option>
			<option value='8'>08</option>
			<option value='9'>09</option>
			<option value='10'>10</option>
			<option value='11'>11</option>
			<option value='12'>12</option>
			<option value='13'>13</option>
			<option value='14'>14</option>
			<option value='15'>15</option>
			<option value='16'>16</option>

Link to comment
Share on other sites

Did no-one else spot the closing tag at the end of the script, that should infact be above the above the Label and Select?

 

<?php
$query = "SELECT name, nric, gender, picture, dob_day FROM tutor_profile WHERE tutor_id = '" . $_GET['tutor_id'] . "'";
    
   $data = mysqli_query($dbc, $query)
   or die(mysqli_error($dbc));
   
   // The user row was found so display the user data
   if (mysqli_num_rows($data) == 1) {
      $row = mysqli_fetch_array($data);

    if ($row != NULL) {
      $name = $row['name'];
      $nric = $row['nric'];
      $gender = $row['gender'];
     $old_picture = $row['picture'];
     $dob_day = $row['dob_day'];
    }
    else {
      echo '<p class="error">There was a problem accessing your profile.</p>';
    }
//HTML CODING BELOW
?>

<label for="dob" class="label">Date Of Birth</label>
<select id="dob_day" name="dob_day" value="<?php if (!empty($dob_day)) { echo $dob_day; } ?>">
     <option>
            <option>01</option>
            <option>02</option>
            <option>03</option>
            <option>04</option>
            <option>05</option>
            <option>06</option>
            <option>07</option>
            <option>08</option>
            <option>09</option>
            <option>10</option>
            <option>11</option>
            <option>12</option>
            <option>13</option>
            <option>14</option>
            <option>15</option>
            <option>16</option>
            <option>17</option>
            <option>18</option>
            <option>19</option>
            <option>20</option>
            <option>21</option>
            <option>22</option>
            <option>23</option>
            <option>24</option>
            <option>25</option>
            <option>26</option>
            <option>27</option>
            <option>28</option>
            <option>29</option>
            <option>30</option>
            <option>31</option>
         </select>

 

Try that? Unless you noticed this before the just disregard this post.

 

Regards, PaulRyan.

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.