Jump to content

Only for those who are awesome at php a.k.a COOL


TheFilmGod

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.