1

I want know how I can create this array

$datos = new ArrayIterator(array(
  "08:00:00" => new Vector ("08:00:00","08:30:00","sandrad"),
  "10:00:00" => new ArrayIterator (array( "10:00:00", "10:45:00", "palomas" )),
  "20:00:00" => new Vector("20:00:00","21:15:00","pedrales"),
  "25:30:00" => new ArrayIterator ( .....etc....
))

this is my query and how i am try:

$sql = "SELECT * FROM amigos WHERE fecha='$fecha' AND ORDER BY hora_inicio ASC ";
$result = mysql_query($sql) or die(mysql_error());

$totalRows = mysql_num_rows($result);


while ($row = mysql_fetch_assoc($result)) {
  switch ($funcion) {
    case 'new Vector (':
      $funcion='new ArrayIterator (array(';
      break;
    case 'new ArrayIterator (array(':
      $funcion ='new Vector (';
      break;
    default:
      $funcion ='new Vector (';
}

switch ($fin_funcion) {
  case '),':
    $fin_funcion = ')),';
    break;
  case ')),':
    $fin_funcion = '),';
    break;
  default:
    $fin_funcion = '),';
}

$datos=new ArrayIterator(array(
  $row['hora_inicio'] => $funcion.'"'.$row['hora_inicio'].'","'.$row['hora_final'].'","'.$row['nombre'].'"'.$fin_funcion



));

}

but I am not having any luck. any ideas?

1
  • Programming has nothing to do with luck, it's all about craft. Commented Mar 15, 2011 at 5:00

1 Answer 1

1

You are creating a new $datos ArrayIterator every time through the loops. If you want an ArrayIterator, create the entire array and then initialize it.

$datos = array();
while($row=mysql_fetch_assoc($result)){
    switch($funcion){
        case 'new Vector (':
            $funcion='new ArrayIterator (array(';
            break;
        case 'new ArrayIterator (array(':
            $funcion ='new Vector (';
            break;
        default:
            $funcion ='new Vector (';
    }

    switch($fin_funcion){
        case '),':
            $fin_funcion = ')),';
            break;
        case ')),':
            $fin_funcion = '),';
            break;
        default:
            $fin_funcion = '),';
    }

    $datos[$row['hora_inicio']] = $funcion.'"'.$row['hora_inicio'].
        '","'.$row['hora_final'].'","'.$row['nombre'].'"'.$fin_funcion;
}

$datos = new ArrayIterator($datos);
Sign up to request clarification or add additional context in comments.

1 Comment

nop, don't work.. i still try, thanks any way! i really glad by your care about my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.