Jump to content

Recommended Posts

Alright, I have this php code. There are some errors to it. I did a lot of tests and tracked the error to this:

 

				// While loop
			while ($i > 0 ){

				$field = "a" . $i;
				${$field} = $row_attend['$field'];
				$i--;

			}

 

NOTICE:

${$field} = $row_attend['$field'];

 

This is the problem. How can I fetch data from the associative array like I did it. Is this even possible?

well I got it to work. The script is extremely complicated. At least the most complicated I ever done. But it works.

 

Here's a snippet for those curious enough:

 

// If form was submitted
if ( isset($_POST['submit'])) {

$date = $_POST['date'];

// Cut out the id from the variable
$attend_id = substr ( $date, 0, strpos($date, " "));


// Select the row that is to be updated
$info = mysql_query("SELECT * FROM attendance WHERE id='$id'") or die("Error: ". mysql_error(). " with query ". $info);

// Query database for attendace given
$attend = mysql_query( "SELECT * FROM attendance WHERE id='$attend_id'" )  or die("Error: ". mysql_error(). " with query ". $attend);

		// Find number of fields selected
		$num_fields_pre = mysql_num_fields($attend);
		$num_fields = $num_fields_pre - 2;


		// Fetch data in associative array
		$row_attend = mysql_fetch_assoc( $attend );

			// Set loop initializer vraible
			$i = $num_fields;
			echo "i is $i";

			// While loop
			while ($i > 0 ){

				$field = "a" . $i;
				${$field} = $row_attend[$field];
				$i--;

			}

 

I don't have time to explain this code. If the form was submitted, it queries the database and returns values for each member. If they were absent/excused/unexucused for the meeting.

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.