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