Jump to content

darwin_tech

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by darwin_tech

  1. Hi all, I have a simple mysql table of articles with one Keyword field which can hold an indeterminate number of comma-separated strings per article. I want to create a tag cloud of these keywords and score them according to how many times they appear overall. My question is two-fold. First, I have elected to do this by pulling all the keywords out into an associative array, but I'm not sure how to go about counting the number of times each string appears. Any suggestions? Second. Is this the most efficient way to do this or would it be better to keep another table of keywords and a count field? I guess it wouldn't be much more efficient as I still have to run through all the keywords in the article table to look for new entries and update the keyword table with new words and/ or counter increments. Any suggestions would be much appreciated.
  2. Whoa! Thanks alot mattal999! It would have taken me a while to figure out what I was doing wrong there. I didn't realise you had to call the standalone script in the img tag. You saved me a heap of time, and judging by some of the threads I looked at in relation to this problem, this will be useful to other people too. Thanks again.
  3. Hi, I am using imageMagick extension with php. The problem is that I can get it to run fine as a stand alone script: <?php $im = new imagick('test.pdf[0]'); $im->setImageFormat( "jpg" ); header( "Content-Type: image/jpeg" ); $im->thumbnailImage(400, 0); echo $im; ?> however as soon as I introduce any more php/ html code or call the script from within code it fails with no error message. For example I would like to use it like this: # loop through results and output in a table while ($stmt->fetch()) { $im = new imagick($file[0]); $im->setImageFormat( "jpg" ); header( "Content-Type: image/jpeg" ); $im->thumbnailImage(400, 0); echo $im; } Any clues as to why this won't work? Sam
  4. Hey, thanks for the replies Nghtslyr and Phil88. I hadn't thought about using an array and you are totally right. I have implemented a variation on Phil88's answer. Thankyou, Sam
  5. Hi, I am having some trouble re-using a method of a class which I use to setup my pages. I have an include which instantiates the class and then I make a call at the top of each page depending on the content required. I have several javascripts I want to include for a specific page and would like to just keep calling the same method to load them. If I try to call the method twice on the last one is echoed. I don't really want have to write out different methods for each file I may need. Any help much appreciated. The included class has this: class Page { public function display_top() { # page specific atrributes $this->display_js(); } public function display_js() { echo "<script type='text/javascript' src='{$this->js}'></script>\n"; } } my page has this: require ('classes/page_class.php'); $page = new Page; $page->js = "js/jquery-1.3.2.min.js"; $page->js = "js/revealClass.js";
  6. 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]); }
  7. 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]); }
  8. Hi there, I have a php project with a series of dynamically generated menus from a mysql database. I have two menus, Island Group and Island where the former should dictate the latter. When an option is selected in Island Group, I only want to populate the subsequent Island menu with islands in that group, without having to refresh the page. I am really not sure how to approach this, though I know that some javascript is required. If anyone can point me in the right direction it would be much appreciated. Regards, Sam
  9. OK, for anyone who might have stumbled across the same problem, I have a found a solution! mostly it is detailed at http://php.net/manual/en/mysqli-stmt.bind-param.php One key factor was that $type cannot be passed as an array. Here I use the join function to pass $type as a string. Hope this may be useful... if ($stmt = $mysqli->prepare($sql)) { $type = join('', $type); call_user_func_array('mysqli_stmt_bind_param', array_merge (array($stmt, $type), refValues($params))); $stmt->execute(); } function refValues($arr) { if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+ { $refs = array(); foreach($arr as $key => $value) $refs[$key] = &$arr[$key]; return $refs; } return $arr; }
  10. @PFMaBiSmAd Yes, I had come across this solution but for some reason I cannot get it to work with my code. I still return the error 2031:No data supplied for parameters in prepared statement is there perhaps some small detail I'm missing? I include my modified code below just in case -> # Prepare stmt if ($stmt = $mysqli->prepare($query)) { # merge the type array with the parameters array $params = array_merge($type, $params); # modified bind call_user_func_array(array($stmt, 'bind_param'), refValues($params)); # execute $stmt->execute(); # results and clean up! } function refValues($arr){ if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+ { $refs = array(); foreach($arr as $key => $value) $refs[$key] = &$arr[$key]; return $refs; } return $arr; } Regards, Sam
  11. Hi I have an infuriating problem which is stalling me with two large projects for a well known NGO right now. I am using mysqli and bound variables where the number of variables to bind is dependent on user input. I have a version of the code below working in php 5.2 but as of php 5.3 this method is no longer valid, specifically due to a change in the behavior of call_user_func_array with bound variables as arrays. I have read about this problem eslewhere but cannot get any of the workarounds to work with my example. Any help would be greatly appreciated. # $parts is an array with variable number of values # $type is an array with variable number of values # $params is an array with variable number of values $query = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT taxon.TaxonID, FROM taxon WHERE . join('', $parts) . " ORDER BY taxon.TaxonID"; # Prepare stmt if ($stmt = $mysqli->prepare($query)) { call_user_func_array (array($stmt, 'bind_param'),array_merge(array(join('', $type)), $params)); # execute $stmt->execute(); # bug info echo $stmt->errno, ':', $stmt->error; #store result $stmt->store_result(); # bind results $stmt->bind_result($ID); # fetch values while ($stmt->fetch()) { # results code goes here! } # free memory $stmt->free_result(); # close statement $stmt->close(); }
×
×
  • 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.