Jump to content

stubarny

Members
  • Posts

    122
  • Joined

  • Last visited

Everything posted by stubarny

  1. Hello, I'm getting the following error message on the commented line of code below. 2 results are being returned by the sql command ($nrows = 2). The strange thing is that the error message only triggers on the second result ($i=1). Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... (i've removed the file address) <?php $haystack = $_GET[q]; $query ="SELECT * FROM research_job_searches"; $result=mysql_query($query) or die ("Connection to database table failed. 35. " . mysql_error()); $nrows=mysql_num_rows($result); if ($nrows<>'0') { for ($i=0;$i<$nrows;$i++) { # error occurs on line below for $i=1 $record = mysql_fetch_array($result, MYSQL_BOTH); $needle = $record[research_job_search_url_keyword] . "-jobs"; } } ?> Any ideas? Thanks, Stu
  2. Hello, I have several job categories on a recruitment website: $job_category[0]="accountant"; $job_category[1]="php programming"; $job_category[2]="baseball"; these job categories are contained within the urls imediately after the recruiting company's name and before the word "jobs", so we could have the following urls: www.url.com/company_name_accountant_jobs www.url.com/another_company_name_baseball_jobs www.url.com/yet_another_company_name_php programming_jobs Using the array $job_categories and the page path after the foward slash (e.g. yet_another_company_name_php programming_jobs) please could you tell me how to strip out the job category and the company name? (I'll extract the page path using a mod_rewrite) Thanks Stu
  3. Hi, I have a table of factfiles on my database. In another table in the same database I have a list of factfile updates - including the id number of the factfile and the timestamp of when the update occured. If a factfile has been updated 60 times then there will be 60 records in this table. I now want to create a list of factfiles that have been updated with the most recently updated at the top. So I have the following SQL code: $query ="SELECT article_id FROM article_updates ORDER BY timestamp_of_update ASC"; Please could you tell me how to modify this code so that I only return one record for each different value of article_id? And also please could you tell me how to ignore all updates for a given factfile within 7 days of the first update of a given factfile (to stop notifications of article updates appearing more than once per a week for a given factfile). (so if an article is first updated on Monday and then on the Wednesday, Thursday, Saturday and following Tuesday the update notification should only appear on the first Monday and the following Tuesday). Thanks, Stu
  4. Hi fenway, Thanks for your help - I appear to have fixed it but have just 1 more question Instead of selecting all columns using "*", I'd like to select all columns from table alias b - please could you tell me if this is possible? $query = "SELECT * FROM research_job_searches a LEFT OUTER JOIN research_job_searches_history b ON (a.research_job_search_index = b.research_job_search_history_research_job_search_index AND b.research_job_search_history_timestamp < $timestamp_1_day_ago ) LEFT OUTER JOIN research_job_searches_history c ON ( (a.research_job_search_index = c.research_job_search_history_research_job_search_index) AND b.research_job_search_history_timestamp < c.research_job_search_history_timestamp ) WHERE c.research_job_search_history_timestamp IS NULL"; Many thanks for your help - you saved me a lot of time today! Stu
  5. Hi fenway, Many thanks. I'm having some trouble combining your previous solution (a self-join) with my query. Here's where I've got to: $query = "SELECT * FROM research_job_searches a LEFT OUTER JOIN research_job_searches_history b ON ( a.research_job_search_index=b.research_job_search_history_research_job_search_index AND a.research_job_search_history_timestamp < b.research_job_search_history_timestamp ) WHERE b.research_job_search_history_timestamp is null"; The problem is that a.research_job_search_history_timestamp is not a field in my table a. Please could you show me how to integrate your self-join query within my query? Many thanks, Stu
  6. Hello, I have a query that finds details of job searches made on my (recruitment) site. It currently returns all matches on "a.research_job_search_index=b.research_job_search_history_research_job_search_index" that are more than 24hrs old. Please could you tell me how to change this query so that it returns only the most recent match for each set of matches of "a.research_job_search_index=b.research_job_search_history_research_job_search_index" that are more than 24hrs old? $query = "SELECT * FROM research_job_searches a LEFT OUTER JOIN research_job_searches_history b ON a.research_job_search_index=b.research_job_search_history_research_job_search_index WHERE b.research_job_search_history_timestamp < $timestamp_1_day_ago"; Many thanks for your help, Stu
  7. Hi Fenway, I would agree with you if I was trying to return a record from research_job_searches_history, but I'm trying to return a record that does not exist in research_job_searches_history. Therefore surely I can't perform a select operation without referring to the other table (research_job_searches_history)? Stu
  8. Hi fenway, sorry I'm lost - I thought a self-join statement is used on two copies of the same table? how would I apply a self-join statement to Zane's code? I just need 1 matching record to be returned (it doesn't matter which matching record is returned) Thanks, Stu
  9. Wow, thanks Zane that link cleared up 2 years of confusion! How would I limit this to return no more than one (joined) record?
  10. Hello, This code below selects all the records in table "research_job_searches" that have corresponding records in table "research_job_searches_history". $query = "SELECT * FROM research_job_searches INNER JOIN research_job_searches_history ON research_job_searches.research_job_search_index=research_job_searches_history.research_job_search_history_index"; Please could you tell me how to re-write this code so that it selects all the records in table "research_job_searches" that do not have corresponding records in table "research_job_searches_history"? Thanks, Stu
  11. Hi Gotharious, Thanks - That simple method used to work but Twitter has removed support for it now. Does anybody else have any recent experience with posting to Twitter using PHP? Thanks, Stu
  12. Hello, I need to find the target html address within some raw html. I know it lies between Needle 1 and Needle 2 below. Needle 1: </span></a> <a href=" Needle 2: " rel="nofollow"><span class=pn><span class=np>Next ยป</span></span></a></div> Nornally I would just use the explode() function but my headache is that there are many instances of Needle 1 in the raw html code and I want my output array always have the same number of elements. However I do know that my target html address is directly after the last instance of Needle 1. How should I go about splitting the html code into an array that always has 3 elements? I'd like the first element to include code up to and including the last instance of Needle 2, the 2nd element to have the target html address, and the 3rd element to have Needle 2 and any following code. Thanks for any pointers (my main struggle is identifying the last instance of needle 1), Thanks, Stu
  13. Hello, I've found the following list of php directories for Twitter - please could someone tell me which one I should be using for posting tweets (using PHP script)? It seems they are trying to make this hard work! https://dev.twitter.com/docs/twitter-libraries#php Many thanks, Stu
  14. Hello, I have found the following code which creates a sitemap from the home directory of files. Please could you point me in the right direction for changing this so that it looks up from my sql database and for each name within the database creates an entry in the sitemap (e.g. www.mysite.com/[NAME]). Thanks for your help, Stu <?php /******************************************************************************\ * Author : Binny V Abraham * * Website: http://www.bin-co.com/ * * E-Mail : binnyva at gmail * * Get more PHP scripts from http://www.bin-co.com/php/ * ****************************************************************************** * Name : PHP Google Search Sitemap Generator * * Version : 1.00.A * * Date : Friday 17 November 2006 * * Page : http://www.bin-co.com/php/programs/sitemap_generator/ * * * * You can use this script to create the sitemap for your site automatically. * * The script will recursively visit all files on your site and create a * * sitemap XML file in the format needed by Google. * * * * Get more PHP scripts from http://www.bin-co.com/php/ * \******************************************************************************/ // Please edit these values before running your script. //////////////////////////////////// Options //////////////////////////////////// $url = "http://www.WEBSITE_NAME.com/"; //The Url of the site - the last '/' is needed $root_dir = ''; //Where the root of the site is with relation to this file. $file_mask = '*.php'; //Or *.html or whatever - Any pattern that can be used in the glob() php function can be used here. //The file to which the result is written to - must be writable. The file name is relative from root. $sitemap_file = 'sitemap.xml'; // Stuff to be ignored... //Ignore the file/folder if these words appear in the name $always_ignore = array( 'local_common.php','images' ); //These files will not be linked in the sitemap. $ignore_files = array( '404.php','error.php','configuration.php','include.inc' ); //The script will not enter these folders $ignore_folders = array( 'Waste','php_uploads','images','includes','lib','js','css','styles','system','stats','CVS','.svn' ); //The default priority for all pages - the priority of all pages will increase/decrease with respect to this. $starting_priority = ($_REQUEST['starting_priority']) ? $_REQUEST['starting_priority'] : 70; /////////////////////////// Stop editing now - Configurations are over //////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// function generateSiteMap() { global $url, $file_mask, $root_dir, $sitemap_file, $starting_priority; global $always_ignore, $ignore_files, $ignore_folders; global $total_file_count,$average, $lowest_priority_page, $lowest_priority; /////////////////////////////////////// Code //////////////////////////////////// chdir($root_dir); $all_pages = getFiles(''); $xml_string = '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"> <?php # '; $modified_priority = array(); for ($i=30;$i>0;$i--) array_push($modified_priority,$i); $lowest_priority = 100; $lowest_priority_page = ""; //Process the files foreach ($all_pages as $link) { //Find the modified time. $handle = fopen($link,'r'); $info = fstat($handle); fclose($handle); $modified_at = date('Y-m-d\Th:i:s\Z',$info['mtime']); $modified_before = ceil((time() - $info['mtime']) / (60 * 60 * 24)); $priority = $starting_priority; //Starting priority //If the file was modified recently, increase the importance if($modified_before < 30) { $priority += $modified_priority[$modified_before]; } if(preg_match('/index\.\w{3,4}$/',$link)) { $link = preg_replace('/index\.\w{3,4}$/',"",$link); $priority += 20; } //These priority detectors should be different for different sites :TODO: if(strpos($link,'example')) $priority -= 30; //If the page is an example page elseif(strpos($link,'demo')) $priority -= 30; if(strpos($link,'tuorial')) $priority += 10; if(strpos($link,'script')) $priority += 5; if(strpos($link,'other') !== false) $priority -= 20; //Priority based on depth $depth = substr_count($link,'/'); if($depth < 2) $priority += 10; // Yes, I know this is flawed. if($depth > 2) $priority += $depth * 5; // But the results are better. if($priority > 100) $priority = 100; $loc = $url . $link; if(substr($loc,-1,1) == '/') $loc = substr($loc,0,-1);//Remove the last '/' char. $total_priority += $priority; if($lowest_priority > $priority) { $lowest_priority = $priority;//Find the file with the lowest priority. $lowest_priority_page = $loc; } $priority = $priority / 100; //The priority is given in decimals $xml_string .= " <url> <loc>$loc</loc> <lastmod>$modified_at</lastmod> <priority>$priority</priority> </url>\n"; } $xml_string .= "</urlset>"; if(!$hndl = fopen($sitemap_file,'w')) { //header("Content-type:text/plain"); print "Can't open sitemap file - '$sitemap_file'.\nDumping result to screen...\n<br /><br /><br />\n\n\n"; print '<textarea rows="25" cols="70" style="width:100%">'.$xml_string.'</textarea>'; } else { print '<p>Sitemap was written to <a href="' . $url.$sitemap_file .'">'. $url.$sitemap_file .'></a></p>'; fputs($hndl,$xml_string); fclose($hndl); } $total_file_count = count($all_pages); $average = round(($total_priority/$total_file_count),2); } ///////////////////////////////////////// Functions ///////////////////////////////// // File finding function. function getFiles($cd) { $links = array(); $directory = ($cd) ? $cd . '/' : '';//Add the slash only if we are in a valid folder $files = glob($directory . $GLOBALS['file_mask']); foreach($files as $link) { //Use this only if it is NOT on our ignore lists if(in_array($link,$GLOBALS['ignore_files'])) continue; if(in_array(basename($link),$GLOBALS['always_ignore'])) continue; array_push($links, $link); } //asort($links);//Sort 'em - to get the index at top. //Get All folders. $folders = glob($directory . '*',GLOB_ONLYDIR);//GLOB_ONLYDIR not avalilabe on windows. foreach($folders as $dir) { //Use this only if it is NOT on our ignore lists $name = basename($dir); if(in_array($name,$GLOBALS['always_ignore'])) continue; if(in_array($dir,$GLOBALS['ignore_folders'])) continue; $more_pages = getFiles($dir); // :RECURSION: if(count($more_pages)) $links = array_merge($links,$more_pages);//We need all thing in 1 single dimentional array. } return $links; } //////////////////////////////// Display ///////////////////////////// ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.1 Transitional//EN"> <html> <head> <title>Sitemap Generation Using PHP</title> <style type="text/css"> a {color:blue;text-decoration:none;} a:hover {color:red;} </style> </head> <body> <h1>PHP Google Search Sitemap Generator Script</h1> <?php if($_POST['action'] == 'Create Sitemap') { generateSiteMap(); ?> <h2>Sitemap Created...</h2> <h2>Statastics</h2> <p><strong><?php echo $total_file_count; ?></strong> files were found and indexed.<br /> Lowest priority of <strong><?php echo $lowest_priority; ?></strong> was given to <a href='<?php echo $lowest_priority_page; ?>'><?php echo $lowest_priority_page; ?></a></p> Average Priority : <strong><?php echo $average; ?></strong><br /> <h2>Redo</h2> <?php } else { ?> <p>You can use this script to create the sitemap for your site automatically. The script will recursively visit all files on your site and create a sitemap XML file in the format needed by Google. </p> <p>You can customize the result by changing the starting priorities.</p> <h2>Set Starting Priority</h2> <?php } ?> <form action="create_sitemap.php" method="post"> Starting Priority : <input type="text" name="starting_priority" size="3" value="<?php echo $starting_priority; ?>" /> <input type="submit" name="action" value="Create Sitemap" /> </form> </body> </html>
  15. Yep that's the plan - manual over-rides in the short-term, then move over to the automated system. I kind of thought this would be a common problem?
  16. Hello, I'm developing a website that asks the user to submit a keyword for a search. The results should display matches for this keyword, but also show matches for related keywords (in order of relevenace!). I'm planning on building up a library of which search terms users use in the same sessions (e.g. if someone searches for "it jobs" and "php jobs", I'll know the terms are correlated), and I'll also measure the click-through rates of the items on the results list. I've been spending all weekend trying to map out the design for this but it's proving incredibly complicated and I think the solution is likely to be on the internet somewhere already?! Please could someone point me in the right direction if you've come accross this problem before? Thanks a million, Stu
  17. Hello, Please can someone tell me how to create a form field suggestion box (like to box of suggestions that appears under the google search bar)? Many thanks, Stu
  18. Hello everyone, I can get Test 2 to successfully operate the if statement using a variable variable. But when I try the same method using a session variable (Test 1) the if statement is not executed. Please could you tell me why the if statement in Test 1 is not being executed? <?php # TEST 1 $_SESSION[test_variable] = "abcd"; $session_variable_name = "_SESSION[test_variable]"; if ($$session_variable_name == "abcd") { echo "<br>line 373, abcd<br>"; } # TEST 2 $test_variable = "efgh"; $test_variable_name = "test_variable"; if ($$test_variable_name == "efgh") { echo "<br>line 379, efgh<br>"; } ?> Many thanks, Stu
  19. Blimey, Thanks tomfmason! :-)
  20. Hi tomfmason, Many thanks, very interesting. If I use file_get_contents would the user be able to see the file directory of the target file? (either in the download window or in the downloaded file properties?) - just thinking of security... Stu
  21. Hello, I have a form for uploading CV files into a CV database. Once the files are uploaded to their directory (e.g. www.jobsboard.com/cvdatabase/) please could someone tell me how to restrict access to users? e.g. once a user logs into their userpanel they should be able to click on a hyperlink to download a CV e.g. (www.jobsboard.com/cvdatabase/CV1.doc) but a user who isn't logged in shouldn't be able to access www.jobsboard.com/cvdatabase/CV1.doc Please could you tell me whether this is possible? Many thanks, Stu
×
×
  • 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.