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
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]

Link to comment
Share on other sites

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

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.