Jump to content

[SOLVED] Array containing two fields..


simplyrichard

Recommended Posts

I have the following code:

 

foreach( $_SESSION['jobs'] as $job => $value){
$result = mysql_query("SELECT * FROM culvercareers.positions WHERE position_id='$value'") or die(mysql_error());  
$row = mysql_fetch_array( $result );
$job_title = $row['position_name'];
	echo "$job_title<br>";
	echo "<textarea cols='45' rows='5' name='job_xp[]'></textarea>";
	[b]echo "<input type='hidden' name='job_code' value'$value'>";[/b]
	echo "<p>";
}

What I am trying to ask is ... now that I hae job_xp[] in an array... how do I get the job_code included into the same array so that when I do this:

 

$_SESSION['job_xp_info'] = $_POST['job_xp'];

foreach( $_SESSION['job_xp_info'] as $job => $value){
mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, [b]job_code[/b]) VALUES ('$app_id','$userid','$value','[b]$job_code'[/b])") or die (mysql_error());

 

I get the job_xp and the job_code in the array?

 

Richard

Link to comment
https://forums.phpfreaks.com/topic/130908-solved-array-containing-two-fields/
Share on other sites

Change

foreach( $_SESSION['jobs'] as $job => $value){
$result = mysql_query("SELECT * FROM culvercareers.positions WHERE position_id='$value'") or die(mysql_error()); 
$row = mysql_fetch_array( $result );
$job_title = $row['position_name'];
      echo "$job_title<br>";
      echo "<textarea cols='45' rows='5' name='job_xp'></textarea>";
      [b]echo "<input type='hidden' name='job_code' value'$value'>";[/b]
      echo "<p>";
}

 

to

$i = 0;
foreach( $_SESSION['jobs'] as $job => $value)
{
$result = mysql_query("SELECT * FROM culvercareers.positions WHERE position_id='$value'") or die(mysql_error()); 
$row = mysql_fetch_array( $result );
$job_title = $row['position_name'];
      echo "$job_title<br>";
      echo "<textarea cols='45' rows='5' name='job[$i][xp]'></textarea>";
      echo "<input type='hidden' name='job[$i][code]' value'$value'>";
      echo "<p>";
      $i++;
}

 

Now change

$_SESSION['job_xp_info'] = $_POST['job_xp'];

foreach( $_SESSION['job_xp_info'] as $job => $value){
mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, [b]job_code[/b]) VALUES ('$app_id','$userid','$value','[b]$job_code'[/b])") or die (mysql_error());

 

to:

$_SESSION['job_info'] = $_POST['job'];

foreach( $_SESSION['job_info'] as $job)
{
    mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, job_code) VALUES ('$app_id','$userid','{$job['xp']}','{$job['code']}'") or die (mysql_error());
}

 

[/code]

This makes gives a mysql error

 

foreach( $_SESSION['job_info'] as $job)
{
mysql_query("INSERT INTO culvercareers.applicant_xp (app_id, user_id, job_xp, job_code) VALUES ('$app_id','$userid','{$job['xp']}','{$job['code']}'") or die (mysql_error());
}

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

Any suggestions?

 

Richard

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.