Jump to content

monaya

New Members
  • Posts

    8
  • Joined

  • Last visited

monaya's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi I'm using this code to insert multiple records. The code executes but nothing is entered into my database. This usually happens when there's a mismatch in data types. How do I ensure that description goes in as text which in sql is wrapped in single quotes, but also make sure the other variables go in as numeric. // an array items to insert $array = array( 'theid' => $theid, 'descr' => $descr, 'costperunit' => $costperunit, 'quantity' => $quantity, 'costperlot' => $costperlot ); // begin the sql statement $sql1 = "INSERT INTO descriptions (jobid, description, costperunit, quantity, costperlot) VALUES "; $it = new ArrayIterator( $array ); // a new caching iterator gives us access to hasNext() $cit = new CachingIterator( $it ); // loop over the array foreach ( $cit as $value ) { // add to query $sql1 .= "('".$cit->key()."','" .$cit->current()."')"; if( $cit->hasNext() ) { $sql1 .= ","; } }
  2. Ok Thank you. I must be misunderstanding something. Sorry for the confusion. For future reference for anyone else who stumbles on the post, here's the final code, still not working. It's just sample code to see if I could access the keys of an array from one function to another. <?php function firstfunction() { global $array; $array = extract(array( 'title' => 'Site map', 'id' => 'sitemap', 'depth' => 2 ), $params); print $title; } function secondfunction($title) { print $title; } firstfunction(); //works. prints the key secondfunction($title); //empty ?>
  3. If you run the code you'll see that GenerateSitemap(); does return data and the secondfunction still comes up empty even if you pass the the $title argument through the function.
  4. I am using the array later on when I access that function. I can print the key by simply using $title, but I cannot do that in a second function. It simply comes up blank. For example, I tried stripping away all the unnecessary code to demonstrate the problem <?php function GenerateSitemap($params = array()) { $array = extract(array( 'title' => 'Site map', 'id' => 'sitemap', 'depth' => 2 ), $params); print $title; } function secondfunction() { print $title; } GenerateSitemap() // WORKS it prints the $title key secondfunction() //Throws an error $title key is not accessible ?> In the second function $title is empty. P.S. shortcode_atts is a Wordpress function http://codex.wordpre.../shortcode_atts
  5. Can't seem to make it work. The main code is this: function GenerateSitemap($params = array()) { //1 // default parameters $array = extract(shortcode_atts(array( 'title' => 'Site map', 'id' => 'sitemap', 'depth' => 2 ), $params)); global $array; } I'd like to use the title, id or depth KEYS inside a second function. They just come up empty.
  6. I mean individual keys from the array
  7. They're already in an array, no?
  8. I'm trying to access the variables in the array below outside of the function. I've tried everything The variables I'm trying to access are bold and in red in the code below. These variables are just not accessible outside the function. function GenerateSitemap($params = array()) { // default parameters extract(shortcode_atts(array( 'title' => 'Site map', 'id' => 'sitemap', 'depth' => 2 ), $params)); // create sitemap $sitemap = wp_list_pages("title_li=&depth=$depth&sort_column=menu_order&echo=0"); if ($sitemap != '') { $sitemap = ($title == '' ? '' : "<h2>$title</h2>") . '<ul' . ($id == '' ? '' : " id=\"$id\"") . ">$sitemap</ul>"; } return $sitemap; } add_shortcode('sitemap', 'GenerateSitemap'); Thanks!!
×
×
  • 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.