Jump to content

array, str_replace() problem


darwin_tech

Recommended Posts

Hi,

 

I am converting a mysqli function to mysql SELECT strings.

 

I basically have two arrays (I include with only one item a piece below for clarity). I want to replace the '?' in the first array values with the value in the second array. I know this should be an easy one and I'm missing something simple...

 

Any help much appreciated.

 


$parts = array('AND (taxon.Genus LIKE ?)');

$params = array(' wasmannia%');

$arrayCount = count($parts);

for ($i = 0; $i < $arrayCount; ++$i) {
	str_replace('?', $params[$i], $parts[$i]);
}

Link to comment
Share on other sites

hey, that's a nice solution.

 

I just got a version of my code to work (below). Thanks for the help - always better to have more than one solution ;)

 


$parts = array('AND (taxon.Genus LIKE ?)');

$params = array(' wasmannia%');

$arrayCount = count($parts);

$mysqlParts = array();

for($i=0;$i<count($params);$i++) {
    $mysqlParts[] = str_replace("?",$params[$i],$parts[$i]);
}


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.