Jump to content

Help with array


whizzfrapp

Recommended Posts

Is there any way to use the keys that i want in a keyed array?

I'm doing this but it gives me an error

 

$result = db_query('SELECT * FROM {team}');

 

  $rows = array();

 

  while ($team = db_fetch_object($result)) {

    array_push($rows, $team);

  } 

 

  $check = array();

 

  foreach($rows as $team)

  {

  $id = $team->team_id;

  $name = $team->name;

  array_push($check, $id => t($name));

  }

Link to comment
https://forums.phpfreaks.com/topic/158427-help-with-array/
Share on other sites

Thank you.

Do you mean like this ?

 

$result = db_query('SELECT * FROM {ge_team}');

 

  $rows = array();

 

  while ($team = db_fetch_object($result)) {

    array_push($rows, $team);

  } 

 

  $check = array();

 

  foreach($rows as $key=>$value)

  {

  $key = $team->team_id;

    $value = $team->name;

    array_push($check, $key=>$value);

  }

Link to comment
https://forums.phpfreaks.com/topic/158427-help-with-array/#findComment-835538
Share on other sites

I'm working on drupal and I want to have a set of checkboxes related to the teams that exist in the database.

And that array of checkboxes should be in this form:

 

array($team_id => $team_name, $team_id => $team_name)

 

so that when I click the checkboxes that i want, those teams be written in the database.

Link to comment
https://forums.phpfreaks.com/topic/158427-help-with-array/#findComment-835541
Share on other sites

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.