Jump to content

How to iterate though array..?


guitarlass

Recommended Posts

Hello..

i have this problem.. im doing some kind of late static binding. im really a new to this and don't know how to solve this problem. please help me to solve it...

What i want to do is instead of using static::$arr[0].",".static::$arr[1] i want to iterate though the array.. i tried using a foreach loop but it doesn't work.. i don't understand why.. i will really appreciate if someone demonstrate a code to do this in a better way.

this is my code.

 

<?php

class MainModel {

 

public static function create($custArray){

global $connection;

 

$query="INSERT INTO ".static:: $tblname."(";

$query.=static::$arr[0].",".static::$arr[1];

$query.=") VALUES ('".$custArray['name']."','".$custArray['details']."')";

 

if(mysql_query($query)>0)

{

return true;

}

else

{

return false;

}

 

}

class ChildModel extends MainModel{

 

protected static $tblname = 'test';

protected static $arr=array('name','details');

 

}

 

//here im calling the method.. just for testing..

if(ChildModel::create(array('name'=>'d','details'=>'s')))

 

{

echo("its working! ");

}

else

{

echo("its not working! ".mysql_error());

}

?>

Link to comment
https://forums.phpfreaks.com/topic/202346-how-to-iterate-though-array/
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.