Jump to content

problem with array


Spikerok

Recommended Posts

I have array which contains next entry

'rowcount'        => array(    0 => 'SELECT domain_id FROM tbl_domain WHERE domain_id = \'\" . $this->feld[\'txtDomain\'] . \"\'|Domain already exists'

 

 

Given array is processed using next code. I'm calling this process after declaring array and filling it with values.

                 $felder = explode('|', $this->array['rowcount'][0]);
                 $sql = stripslashes($felder[0]);
                 $result = $this->registry['conn']->query($sql);
                 $numrows = $result->rowCount();

 

 

$this->feld[txtDomain] = 123

$sql = stripslashes($felder[0]); will show SELECT domain_id FROM `tbl_domain` WHERE `domain_id` = '" . $this->feld['txtDomain'] . "'

when it should of changed '" . $this->feld['txtDomain'] . "' to 123

 

 

What could be done?

 

 

 

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

I have first page which calls object and contains array.

$array = array('rowcount'		=> array(	0 => 'SELECT domain_id FROM tbl_domain WHERE domain_id = \'\" . $this->feld[\'txtDomain\'] . \"\'|Domain already exists',
											1 => 'SELECT user_id FROM buga WHERE user_id = \'\" .  $this->feld[\'txtID\'] . \"\'|User does not exist'));
new process($this->registry, $array);

 

then in class process

i have function rowcount

private function rowcount()
{
$max = count($this->array['rowcount']);
for($i = 0; $i < $max; $i++)
{	
	$felder = explode('|', $this->array['rowcount'][$i]);
	$sql = stripslashes($felder[0]);

	$result = $this->registry['conn']->query($sql);
	$numrows = $result->rowCount();

	if($numrows < 1){
		$_SESSION['errorMessage']= $felder[1];
	}
}		
}

 

 

array '$this->feld' is declared in class with values.

Link to comment
https://forums.phpfreaks.com/topic/193681-problem-with-array/#findComment-1019453
Share on other sites

because array is created before starting class and class contains variable which is used in array,

array thinks that the sql string with variable ( which are undefined ) in it is just a string. Well every thing that contained in array is a string, so i have changed array slightly.

$array = array('rowcount'		=> array(	0 => 'SELECT domain_id FROM tbl_domain WHERE domain_id =|txtDomain|Domain already exists');
new process($this->registry, $array);

 

and in function.

			$felder = explode('|', $this->array['rowcount'][$i]);
			$sql = $felder[0];
			$sql .= "'" . $this->feld[$felder[1]] . "'";

 

Link to comment
https://forums.phpfreaks.com/topic/193681-problem-with-array/#findComment-1019494
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.