Jump to content

jaxdevil

Members
  • Posts

    268
  • Joined

  • Last visited

Everything posted by jaxdevil

  1. I've been trying to come at this problem from multiple angles and can't seem to figure it out. I have my update statement and it updates the other fields but not the field that is set as a decimal(20,5) type. I have tried formatting the number to be 5 decimal places, padded left with zeros so it is 20 characters long with 5 decimals, but it will not update. I can copy the query into phpmyadmin and run the update statement and it works fine, but in php it will update every field that is modified within the exact same query but not the decimal(20,5) field. Any ideas how to get around this issue? Thanks in advance to anyone who can help here.
  2. Never mind... got it... SELECT DISTINCT(`pc`.`pid`) AS `dpid`, `c`.`category_path` AS `category_path`, `c`.`parent` AS `cid`, `pa`.`name` AS `pa_name`, `pa`.`options_con` AS `pa_options_con`, `pa2`.`name` AS `pa2_name`, `pa2`.`options_con` AS `pa2_options_con` FROM `catalog` AS `c`, `products` AS `p`, `products` AS `p2`, `products_categories` AS `pc`, `brand_names` AS `bn`, `products_attributes` AS `pa`, `products_attributes` AS `pa2` WHERE `c`.`cid`=`pc`.`cid` AND `p`.`pid`=`pc`.`pid` AND `pc`.`bid`=`bn`.`id` AND `bn`.`brand_name`='begreen' AND `c`.`level`='3' AND `c`.`url_default` LIKE 'ca%' AND `p`.`pid`=`pa`.`pid` AND `pa2`.`pid`=`p`.`pid` AND (`pa`.`name`='Ink Type' AND ((`pa`.`options_con` LIKE '%|Other|%')) OR (`pa2`.`name`='Point Type' AND (`pa2`.`options_con` LIKE '%|0.7mm|%'))) ORDER BY `c`.`category_path` ASC That was a pain.. grrrr
  3. Tried revising it with this: SELECT`pc`.`pid` AS `dpid`, `c`.`category_path` AS `category_path`, `c`.`parent` AS `cid`, `pa`.`options_con` AS `pa_options_con`, `pa2`.`options_con` AS `pa2_options_con` FROM `catalog` AS `c`, `products` AS `p`, `products` AS `p2`, `products_categories` AS `pc`, `brand_names` AS `bn`, `products_attributes` AS `pa`, `products_attributes` AS `pa2` WHERE `c`.`cid`=`pc`.`cid` AND `p`.`pid`=`pc`.`pid` AND `pc`.`bid`=`bn`.`id` AND `bn`.`brand_name`='begreen' AND `c`.`level`='3' AND `c`.`url_default` LIKE 'ca%' AND `p`.`pid`=`pa`.`pid` AND `p2`.`pid`=`pa2`.`pid` AND `p`.`pid`=`p2`.`pid` AND (`pa`.`name`='Ink Type' AND (`pa`.`options_con` LIKE '%|Green|%')) AND (`pa2`.`name`='Point Type' AND (`pa2`.`options_con` LIKE '%|0.7mm|%')) ORDER BY `c`.`category_path` ASC Since the products_attributes table contains both the pid (product ID) a name (the name of option type) and also the different options concatenated with a pipe "|" to separate them for searches. So i figured limiting those two to looking for the ones that are of the Ink Color or Tip Type that match the selected options the user sent as variables it would work, NOT. I'm suckin today. Someone with a big brain lend a lesser mind a hand
  4. Ok, I am trying to find all the results in a table that match specific variables (obviously) but there is a table that contains both ink types and tip types, and I am trying to locate those that match the ink type and color types selected. I have tried numerous queries with the same zero result, even though I know those brands have those ink and color types available. Here is my query: SELECT DISTINCT(`pc`.`pid`) AS `dpid`, `c`.`category_path` AS `category_path`, `c`.`parent` AS `cid` FROM `catalog` AS `c`, `products` AS `p`, `products_categories` AS `pc`, `brand_names` AS `bn`, `products_attributes` AS `pa`, `products` AS `p2`, `products_attributes` AS `pa`, `products_attributes` AS `pa2` WHERE `c`.`cid`=`pc`.`cid` AND `p`.`pid`=`pc`.`pid` AND `pc`.`bid`=`bn`.`id` AND `bn`.`brand_name`='begreen' AND `c`.`level`='3' AND `c`.`url_default` LIKE 'ca%' AND `p`.`pid`=`pa`.`pid` AND `p2`.`pid`=`pa2`.`pid` AND (`pa`.`options_con` LIKE '%|Green|%') AND (`pa2`.`options_con` LIKE '%|0.7mm|%') ORDER BY `c`.`category_path` ASC Any help will be greatly appreciated.
  5. Just FYI. I have learned the hard way that you will need to pay for Google API access to use this for any real number of queries. If you are going to use it for a couple words and a couple sites you will probably be fine. But anything more than 100 queries in a day will lock your IP (the IP of the machine the scripts reside on) for the rest of the day. Also, if you want to use Yahoo instead of Google change the $url ="" variable to this: $url = "http://search.yahoo.com/search?n=100&ei=UTF-8&va_vt=any&vo_vt=any&ve_vt=any&vp_vt=any&vf=all&vm=p&fl=0&fr=yfp-t-435&p=".$word."&vs=".$domain; Yahoo has the same type of limitation though they use a free (or so it appears) API (called BOSS) Thanks, SK
  6. I found an issue which could affect some people. I know it did mine. If you are searching for strings and not words (i.e. "black dog" and not just "black" or "dog") the search will fail, so I added in the following code just under the $url = "" variable setting within the wordLocator.class.php $url = str_replace(" ", "%20", $url); I updated the ZIP and RAR files on my site, and I am uploading a new ZIP file. If you plan to use strings and not just single words then either download this new set of scripts in the file attached, download using the links on my server, or copy the new wordLocator.class.php from the below code: wordLocator.class.php <?php /* * wordLocator: Locate links in specific domains containing specific key words * (C) 2011 Scott Alan Kline, http://scottalankline.me/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * See http://www.gnu.org/copyleft/lesser.html * */ /* * Example usage: * Include this class on a seperate php page and create an array of words to search for and an array of domains to search through. * Then call this function like this: wordLocator($words, $domains) with the $words variable being your search words and * the $domains being the domains you want to search through. * The output will be an array of all the full URL's of the pages containing those words. * This script can be used for locating blacklisted words on your domains without needing to search one domain at a time or * even one word at a time. The output can be displayed but could be a huge output so it would be best to input the data into a MySQL * table that you can go through using a seperate script. */ function wordLocator($words, $domains) { foreach($domains as $key => $domain) { foreach($words as $key2 => $word) { $url = "http://www.google.com/search?sclient=psy-ab&hl=en&source=hp&q=".$word."+site:".$domain."&pbx=1&oq=".$word."+site:".$domain."&aq=f&aqi=&aql=&gs_sm=e&gs_upl=663384l665689l3l667034l3l3l0l0l0l0l186l511l0.3l3l0&biw=1360&bih=494&cad=cbv&sei=mhoHT6CJNeHe0QH8urmkAg#sclient=psy-ab&hl=en&source=hp&q=".$word."+site:".$domain."&pbx=1&oq=".$word."+site:".$domain."&aq=f&aqi=&aql=&gs_sm=s&gs_upl=0l0l0l185738l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=78028554459641b2&biw=1360&bih=494"; $url = str_replace(" ", "%20", $url); $input = @file_get_contents($url) or die("Could not access file: $url"); $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; if(preg_match_all("/$regexp/siU", $input, $matches)) { $domaintld = str_replace(".com", "", $domain); $pattern = "#^https?://([a-z0-9-]+\.)*".$domaintld."\.com(/.*)?$#"; foreach($matches as $matche) { foreach($matche as $match) { if(preg_match($pattern, $match)) { $urlArray[] = $match; } else { $urlArrayX[] = $match; } // if pregmatch pattern match } // end of foreach matche as match } // end of foreach matches as matche } // end of if pregmatchall } // end of foreach words as key2 to word } //end of foreach domains as key to domain $urlArray = array_unique($urlArray); return $urlArray; } // end of wordLocator function ?> 17279_.zip
  7. OK, I was able to figure this out using a second regexp to basically filter the results. I compiled this all into a compact function/class and am sharing it for anyone else who wants to utilize the same functionality. Here are the files RAR'd: http://scottalankline.me/scripts/speyeder.rar and ZIP'd: http://scottalankline.me/scripts/speyeder.zip I am copying the code for the 2 files below also. The reason I built this (which could be useful for someone else) is site compliance. If you have to verify that you're sits do not contain specific words to comply with your hosting or credit card processor requirements and have a LOT of sites and either forums or lots of individual copywriters/contributors then this would be handy for you. You can enter all of your domains into the $domains array and then all of the blacklisted words in the $words array and the script will search through Google for all of your sites pages that contain those terms and place them in an array. You can then view it on the screen, although I wouldn't recommend it. The results could be quite voluminous if you have a lot of terms to search for our a lot of domains, or both, then it could crash your browser or bog your computer down. The best way - the way I will utilize - will be to loop through the array and insert the results into a database table. I/You can then run through those entries using a separate script to check the links to confirm if the words still are on the pages (Google's indexing might not have been done since you removed the words previously) and then remove the entries that the words are not still on the pages which would leave a table of links for the pages you do need to fix. How you work through them will vary for each person, obviously. But hopefully this script comes in handy for someone else and not just myself. Here are the two scripts and their file names: speyeder.php <?php include('wordLocator.class.php'); //Create an array of the words we will be searching for $words = array('its', 'the', 'end', 'of', 'the', 'world', 'as', 'we', 'know', 'it'); //Create an array of the domains to search through in google $domains = array('example.com', 'anothersite.com', 'andanotherone.com'); //Lets output the results we obtained. echo "<pre>"; print_r(wordLocator($words, $domains)); echo "</pre>"; ?> wordLocator.class.php <?php /* * wordLocator: Locate links in specific domains containing specific key words * (C) 2011 Scott Alan Kline, http://scottalankline.me/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * See http://www.gnu.org/copyleft/lesser.html * */ /* * Example usage: * Include this class on a seperate php page and create an array of words to search for and an array of domains to search through. * Then call this function like this: wordLocator($words, $domains) with the $words variable being your search words and * the $domains being the domains you want to search through. * The output will be an array of all the full URL's of the pages containing those words. * This script can be used for locating blacklisted words on your domains without needing to search one domain at a time or * even one word at a time. The output can be displayed but could be a huge output so it would be best to input the data into a MySQL * table that you can go through using a seperate script. */ function wordLocator($words, $domains) { foreach($domains as $key => $domain) { foreach($words as $key2 => $word) { $url = "http://www.google.com/search?sclient=psy-ab&hl=en&source=hp&q=".$word."+site:".$domain."&pbx=1&oq=".$word."+site:".$domain."&aq=f&aqi=&aql=&gs_sm=e&gs_upl=663384l665689l3l667034l3l3l0l0l0l0l186l511l0.3l3l0&biw=1360&bih=494&cad=cbv&sei=mhoHT6CJNeHe0QH8urmkAg#sclient=psy-ab&hl=en&source=hp&q=".$word."+site:".$domain."&pbx=1&oq=".$word."+site:".$domain."&aq=f&aqi=&aql=&gs_sm=s&gs_upl=0l0l0l185738l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=78028554459641b2&biw=1360&bih=494"; $input = @file_get_contents($url) or die("Could not access file: $url"); $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; if(preg_match_all("/$regexp/siU", $input, $matches)) { $domaintld = str_replace(".com", "", $domain); $pattern = "#^https?://([a-z0-9-]+\.)*".$domaintld."\.com(/.*)?$#"; foreach($matches as $matche) { foreach($matche as $match) { if(preg_match($pattern, $match)) { $urlArray[] = $match; } else { $urlArrayX[] = $match; } // if pregmatch pattern match } // end of foreach matche as match } // end of foreach matches as matche } // end of if pregmatchall } // end of foreach words as key2 to word } //end of foreach domains as key to domain $urlArray = array_unique($urlArray); return $urlArray; } // end of wordLocator function ?> 17278_.zip
  8. Hello everyone! Its been over a year since I have been on here but I need some help with a regex and regex is definitely my weak spot. I am crawling search results looking for specific results where the link belongs to a specific domain. As it is my script crawls the pages, scrapes them, places them (all the <a href=""></a> hyperlinks). The problem is there are a ton of hyperlinks on the search results page that are not the actual results links, like the links to loggin to your account, or for google plus, or for news.google.com, etc. So I want to modify the regex in the preg_match_all that is matching the hyperlinks and grabbing them to ONLY grab hyperlinks that contain the domain that was targeted. So I have the variable $domain which contains the domain name I need to match in the a href so how can I include that in the following regex code to ONLY grab the links that have that domain name in the hyperlink? $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; if(preg_match_all("/$regexp/siU", $input, $matches)) { echo "<pre>"; print_r($matches); echo "</pre>"; } // end of if pregmatchall As I said before, regex is definitely my weak point. I know I should spend a weekend doing noting but regex practicing to master it myself, but for now is there someone who is a regex master who can lend me a hand? I read the topic on this specific board about asking for regex help so I will expand on that below, but hopefully you have what you need from above to help me with this. Thank you in advance guys, SK So you got a problem with regex? Great, here's some guidelines on asking: 1. Describe your problem or background that is important to it. A) See above. 2. Give sample data (the input data, the haystack...etc..) A) Also see above 3. Give the expected output/matches from your sample data. What I should end up with is arrays of hyperlinks that only contain the domain name in the $domain variable (for example lets say $domain = example.com - So only links like http://example.com/page.php or http://www.example.com/page.html etc should be contained within the arrays) 4. Give the actual output that you have if you've attempted something already. A) Well, I echoed out everything (all of the variables) for debugging purposes - I will be turning them off - but you can see the output here (not the actual script but a copy of it in a public directory) http://specialcreative.com/php/spider.php 5. Provide code if necessary, if your problem concerns it. A) See Above. 6. We assume its a php regex related as this is phpfreaks, but you still need to specifiy (if not obvious) if you are talking about POSIX (ereg) or PCRE (preg) flavor. A) Its definitely in PHP - always 7. Be patient/grateful and don't demand things. Regex questions may take longer than expected to be answered, they're tougher sometimes. A) Tell me about it. I believe it, if it was easy I would have mastered it myself by now, its the calculus of the coding world in my opinion.
  9. That was it. I have been without a day off for too long, its always something small that takes up the bulk of time to figure out. I marked this as solved, if you want a couple of months of free hosting (for PFMaBiSmAd only) message me on here and I will hook you up. You saved me some time this evening thats for certain! Thanks again, SK
  10. I have a problem, its very strange. When my script tries to write back the values I have it does all of them but the datetime string I compile to insert back to the table. It simply does not update the datetime field with this data, and when I switch the value from being updated into the datetime field and instead inserted into a varchar field, it does update, but every time it updates only with the character 0 (zero). Below is my code. Anyone know a reason why a script would write a number 0 (zero) to a table instead of the value you select? I can manually update the table in phpmyadmin with the data, but through the script it just inserts a number zero. Its a very short script below. BTW, I had it echo the variable that it is inserting and it echos as it should, as "2009-11-05 11:59:59", which is perfectly formatted for a datetime field, but in any evnet it should still not insert as a numeral 0 (zero) in a plain varchar field. Any help is GREATLY appreciated! If someone wants it I will give you a month or two of free hosting on my servers, you can use it to host your site or just use it as off-site testing space. It is filled with all the add-ons (imagemagick ,suhosin, imagick, magicwand, zend, everything) I REALLY need to figure this problem out! Thanks in advance guys, SK <?php //move to grab all the entries of events that do not have a day of the weekday listed $query = "SELECT * FROM mst_events WHERE `weekday`=''"; $result = mysql_query($query); $n=0; while ($aEvent = mysql_fetch_array($result)){ $aEventt[$n]['id'] = $aEvent['id']; $aEventt[$n]['month'] = $aEvent['month']; $aEventt[$n]['day'] = $aEvent['day']; $aEventt[$n]['year'] = $aEvent['year']; $n++; } //now determine the weekday for the given month, day, and year combination foreach($aEventt as $key => $value) { $aEventt[$key]['weekday'] = date("l", mktime(0, 0, 0, $aEventt[$key]['month'], $aEventt[$key]['day'], $aEventt[$key]['year'])); } // now compile a datetime format fro mysql and insert the weekday and the datetime stamp into the table for each line item we just retrieved the values for (all the ones without weekdays listed yet) foreach($aEventt as $keye => $valuee) { $day = str_pad($aEventt[$keye]['day'], 2, "0", STR_PAD_LEFT); $month = str_pad($aEventt[$keye]['month'], 2, "0", STR_PAD_LEFT); $year = $aEventt[$keye]['year']; $datenotime = $year."-".$month."-".$day." 11:59:59"; mysql_query("UPDATE mst_events SET `weekday`='".$aEventt[$keye]['weekday']."' AND `datetime`='$datenotime' WHERE id='".$aEventt[$keye]['id']."'") or die(mysql_error()); } ?>
  11. That was sort of it, I did not have mod_speling module active in apache on the external web host, and it is active in wamp. The urls it is pulling were all in lower case and the diretcory is a clone of the files on the local files server, so they were a mix of capital and lowercase characters. Added mod_speling and it works perfect now Thanks!
  12. I am having a strange problem. On my local wamp installation this below code works, and on my web host it does not. The bottom code ($files1) works on my web host but not on my wamp. So where it works on one system it doesn't work on the other, and where it doesn't work on one system it does work on the other. Its very odd. I turned error reporting on and receive this message: for each iteration of the foreach statement where it runs a new scandir and chdir for each path that is stored in the database table. And on the bottom code I get that error, but only on the last test code ($file1) where it is looking for the folder in the same directory it is in, the main code works like a charm on my local host, it grabs the folder paths, changes directory to them, and scans the contents, adding them to the array. I put my code right below, and under that a copy of the output on my remote host, and then a copy of the output on my local wamp install. <?php // Mysql connection string session_start(); require('bouncer/inner_security_check.php'); // Pull seperator passed from last page. If no seperator then we are on the first page so the seperator is 0 (this will pull rows 1-100 for 100, and for 100 it will pull 101-200, etc.) $seperator_num = $_GET['seperator_num']; if ($seperator_num='') { $seperator_num='0'; } $offset = 1; $rowsPerPage = '100'; // Now we are going to access the folders_table and put each folders full path one at a time into an array $query = "SELECT `folder_path` FROM `master_templates` LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error:'.mysql_error()); $my_count = mysql_num_rows($query); while($row = mysql_fetch_array($result)){ $folders[] = $row['folder_path']; } print_r($folders); // Now we are going to iterate through these array values (the folder paths) and scan directory on them. Adding an array to the array using their entry as the arrays id. foreach($folders as $key => $value) { $full_path = $value; $marker = strrpos( $value, '/' ) ; $value2 = substr( $value, 0, $marker ) ; $value = substr( $value, $marker ) ; $directory = $_SERVER['DOCUMENT_ROOT'].$value2; $folder = preg_replace('/\//', '', $value); echo "Directory: ".$directory; chdir($directory); $folder_data[$full_path] = scandir($folder); } print_r($folder_data); echo "<br>"; $files1 = scandir("cronjobs"); print_r($files1); ?> Link to the 'view source' contents of the web server install of the above, including ERRORS ALL on. (this is the one that doesn't work). Also includes a link to a html version of my phpinfo page http://temp-server.info/folder_paths.txt http://temp-server.info/phpinfo.php.htm Link to the 'view source' contents of the local WAMP install of the above, including ERRORS ALL on (this one is working how I want). Also includes an html generation of my local wamp phpinfo page. http://temp-server.info/folder_paths_local_wamp.txt http://temp-server.info/phpinfo_local_wamp.php.htm Anyone have an idea or see what I am missing?
  13. I figured it out. The problem was with escapeshellarg on $db_name , it places single quotes around the variable so it was screwing up the execution of the page. I also switched the last three $result to their own functions, and used file_get_contents() for them instead of CURL. I only used curl on the first one. I don't think those were working in CURL because of the ampersands they contained. It works perfect now. I plugged this into the aMember signup page so when a user signs up a new database is created for them and when they loggin they are using their own database, it also uplaods the structure and default data to their new database. Problem solved!
  14. I have a code snippet which is supposed to create a database, add a user to MySQL, and add that user to the new database with all privileges. I am copying it below. It is creating the new database, but not creating the user or adding it to the database. Can anyone tell what I am doing wrong on there? Oh yeah, the final $result I added is to a page that is a seperate query altogether that inserts the tables and data, but that is run last so I don't think that is affecting the user creation. Here is the code (I changed the username, password, and URL to dummy data): ############################################################### # cPanel Database Creator 1.2 ############################################################### # Visit http://www.zubrag.com/scripts/ for updates ############################################################### // cPanel username (you use to login to cPanel) $cpanel_user = "username"; // cPanel password (you use to login to cPanel) $cpanel_password = "xxxxxx"; // cPanel domain (example: mysite.com) $cpanel_host = "somedomain.com"; // cPanel theme/skin, usually "x" // Check http://www.zubrag.com/articles/determine-cpanel-skin.php // to know it for sure $cpanel_skin = "x"; // Script will add user to database if these values are not empty // User wil have ALL permissions $db_name = $u['login']; $db_username = $u['login']; $db_userpass = 'xxxxxx'; // Update this only if you are experienced user or if script does not work // Path to cURL on your server. Usually /usr/bin/curl $curl_path = "/usr/local/bin/curl"; ////////////////////////////////////// /* Code below should not be changed */ ////////////////////////////////////// function execCommand($command) { global $curl_path; if (!empty($curl_path)) { return exec("$curl_path '$command'"); } else { return file_get_contents($command); } } // escape db name $db_name = escapeshellarg($db_name); // will return empty string on success, error message on error $result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/x/sql/adddb.html?db=$db_name"); // create user $result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/x/sql/adduser.html?user=$db_username&pass=$db_userpass"); // assign user to database $result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/x/sql/addusertodb.html?user=$cpanel_user_$db_username&db=$cpanel_user_$db_name&ALL=ALL"); // insert tables and data $result .= execCommand("http://$cpanel_host/members/dbstructure.php?acct=$db_name");
  15. Thanks! Using your suggesttion I was able to locate the issue. On this line: preg_match_all( "/\<SPAN.*?>(.*?)\<\/SPAN\>.*?\<A.*?\>(.*?)\<BR\>/is", $byname[0], $moviedata ); The $byname should be double arrayed like this: preg_match_all( "/\<SPAN.*?>(.*?)\<\/SPAN\>.*?\<A.*?\>(.*?)\<BR\>/is", $byname[0][0], $moviedata ); That fixed it! Thanks, SK
  16. I am trying an example scraper project from a book I bought (PHP Hacks) but it is not working. I typed the data exactly as in the book. I am sure the problem is in these two lines, something in the expression I changed. (It did NOT work as it was written) I have echoed out the $str data and it is grabbing the pages contents, and I do see the codes I want to scrape. Here is the preg_match_all code: // Get just the list sorted by name preg_match_all( '/<div id="sortbyname1">(.*?)<\/div>/s', $str, $byname ); // Get each of the movie entries preg_match_all( '/<SPAN.*?>(.*?)<\/SPAN>.*?<A.*?>(.*?)<BR>/s', $byname[0], $moviedata ); and here is the original way the book had it: // Get just the list sorted by name preg_match_all( "/\<DIV ID=\"sortbyname1\"\>(.*?)\<\/DIV\>/is", $str, $byname ); // Get each of the movie entries preg_match_all( "/\<SPAN.*?>(.*?)\<\/SPAN\>.*?\<A.*?\>(.*?)\<BR\>/is", $byname[0], $moviedata ); and here is the code as it is in the $str variable (or at least the portion I am scraping) <div id="sortbyname1"> <p class="listing"> <SPAN CLASS="noscore">xx</SPAN> <A HREF="/video/titles/alphabetkiller">Alphabet Killer [51] => The</A><BR> <SPAN CLASS="red">20</SPAN> <A HREF="/video/titles/americancarol">American Carol [52] => An</A><BR> <SPAN CLASS="yellow">43</SPAN> <A HREF="/video/titles/anamorph">Anamorph</A><BR> <SPAN CLASS="green">64</SPAN> <A HREF="/video/titles/appaloosa">Appaloosa</A><BR> <SPAN CLASS="red">26</SPAN> <A HREF="/video/titles/babylonad">Babylon A.D.</A><BR> <SPAN CLASS="red">24</SPAN> <A HREF="/video/titles/bangkokdangerous2008">Bangkok Dangerous</A><BR> <SPAN CLASS="yellow">60</SPAN> <A HREF="/video/titles/blindmountain">Blind Mountain</A><BR> <SPAN CLASS="green">64</SPAN> <A HREF="/video/titles/bridesheadrevisited">Brideshead Revisited</A><BR> <SPAN CLASS="green">63</SPAN> <A HREF="/video/titles/burnafterreading">Burn After Reading</A><BR> <SPAN CLASS="green">61</SPAN> <A HREF="/video/titles/bustindownthedoor">Bustin&#039; Down the Door</A><BR> <SPAN CLASS="yellow">49</SPAN> <A HREF="/video/titles/childrenofhuangshi">Children of Huang Shi [53] => The</A><BR> <SPAN CLASS="yellow">58</SPAN> <A HREF="/video/titles/cityofember">City of Ember</A><BR> <SPAN CLASS="green">82</SPAN> <A HREF="/video/titles/darkknight"><B>Dark Knight [54] => The</B></A><IMG SRC="/_images/scores/star.gif" WIDTH="11" HEIGHT="11" ALIGN="absmiddle"><BR> <SPAN CLASS="yellow">43</SPAN> <A HREF="/video/titles/deathrace">Death Race</A><BR> <SPAN CLASS="red">15</SPAN> <A HREF="/video/titles/disastermovie">Disaster Movie</A><BR> <SPAN CLASS="green">62</SPAN> <A HREF="/video/titles/duchess2008">Duchess [55] => The</A><BR> <SPAN CLASS="yellow">43</SPAN> <A HREF="/video/titles/eagleeye">Eagle Eye</A><BR> <SPAN CLASS="noscore">xx</SPAN> <A HREF="/video/titles/edenlake">Eden Lake</A><BR> <SPAN CLASS="yellow">58</SPAN> <A HREF="/video/titles/express">Express [56] => The</A><BR> <SPAN CLASS="yellow">49</SPAN> <A HREF="/video/titles/familythatpreys">Family That Preys [57] => The</A><BR> <SPAN CLASS="green">67</SPAN> <A HREF="/video/titles/flowforloveofwater">Flow: For Love of Water</A><BR> <SPAN CLASS="green">72</SPAN> <A HREF="/video/titles/ghosttown">Ghost Town</A><BR> <SPAN CLASS="yellow">54</SPAN> <A HREF="/video/titles/hamlet2">Hamlet 2</A><BR> <SPAN CLASS="green">71</SPAN> <A HREF="/video/titles/hortonhears">Horton Hears a Who!</A><BR> <SPAN CLASS="yellow">55</SPAN> <A HREF="/video/titles/housebunny">House Bunny [58] => The</A><BR> <SPAN CLASS="yellow">40</SPAN> <A HREF="/video/titles/igor">Igor</A><BR> <SPAN CLASS="yellow">51</SPAN> <A HREF="/video/titles/mammamia">Mamma Mia!</A><BR> <SPAN CLASS="green">89</SPAN> <A HREF="/video/titles/manonwire"><B>Man on Wire</B></A><IMG SRC="/_images/scores/star.gif" WIDTH="11" HEIGHT="11" ALIGN="absmiddle"><BR> <SPAN CLASS="red">31</SPAN> <A HREF="/video/titles/maxpayne">Max Payne</A><BR> <SPAN CLASS="red">35</SPAN> <A HREF="/video/titles/mirrors">Mirrors</A><BR> <SPAN CLASS="red">31</SPAN> <A HREF="/video/titles/mummy3">Mummy: Tomb of the Dragon Emperor [59] => The</A><BR> <SPAN CLASS="red">34</SPAN> <A HREF="/video/titles/mybestfriendsgirl">My Best Friend&#039;s Girl</A><BR> <SPAN CLASS="green">66</SPAN> <A HREF="/video/titles/pattismith">Patti Smith: Dream of Life</A><BR> <SPAN CLASS="green">64</SPAN> <A HREF="/video/titles/pineappleexpress">Pineapple Express</A><BR> <SPAN CLASS="yellow">55</SPAN> <A HREF="/video/titles/pingpongplaya">Ping Pong Playa</A><BR> <SPAN CLASS="red">32</SPAN> <A HREF="/video/titles/repo">Repo! The Genetic Opera</A><BR> <SPAN CLASS="red">36</SPAN> <A HREF="/video/titles/righteouskill">Righteous Kill</A><BR> <SPAN CLASS="yellow">51</SPAN> <A HREF="/video/titles/savagegrace">Savage Grace</A><BR> <SPAN CLASS="yellow">56</SPAN> <A HREF="/video/titles/saveme">Save Me</A><BR> <SPAN CLASS="red">19</SPAN> <A HREF="/video/titles/sawv">Saw V</A><BR> <SPAN CLASS="red">16</SPAN> <A HREF="/video/titles/surferdude">Surfer [60] => Dude</A><BR> <SPAN CLASS="yellow">47</SPAN> <A HREF="/video/titles/swingvote">Swing Vote</A><BR> <SPAN CLASS="yellow">57</SPAN> <A HREF="/video/titles/towelhead">Towelhead</A><BR> <SPAN CLASS="yellow">60</SPAN> <A HREF="/video/titles/traitor">Traitor</A><BR> <SPAN CLASS="green">61</SPAN> <A HREF="/video/titles/wackness">Wackness [61] => The</A><BR> <SPAN CLASS="green">72</SPAN> <A HREF="/video/titles/womanonthebeach">Woman on the Beach</A><BR> <SPAN CLASS="red">27</SPAN> <A HREF="/video/titles/women2008">Women [62] => The</A><BR> </p> </div> Anyone see how they preg_match_all should be? Below is the entire script if you want to see that: <html> <?php // Set up the CURL object $ch = curl_init( "http://www.metacritic.com/video/" ); // Fake out the User Agent $userAgent = 'Internet Explorer'; curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent ); // Start the output buffering ob_start(); // Get the HTML from MetaCritic curl_exec( $ch ); curl_close( $ch ); // Get the contents of the output buffer $str = ob_get_contents(); ob_end_clean(); // Get just the list sorted by name preg_match_all( "/\<DIV ID=\"sortbyname1\"\>(.*?)\<\/DIV\>/is", $str, $byname ); // Get each of the movie entries preg_match_all( "/\<SPAN.*?>(.*?)\<\/SPAN\>.*?\<A.*?\>(.*?)\<BR\>/is", $byname[0], $moviedata ); // Work through the raw movie data $movies = array(); for( $i = 0; $i < count( $moviedata[1] ); $i++ ) { // The score is ok already $score = $moviedata[1][$i]; // We need to remove tags from the title and decode // the HTML entities $title = $moviedata[2][$i]; $title = preg_replace( "/<.*?>/", "", $title ); $title = html_entity_decode( $title ); // Then add the movie to the array $movies []= array( $score, $title ); } ?> <body> <table> <tr> <th>Name</th><th>Score</th> </tr> <?php foreach( $movies as $movie ) { ?> <tr> <td><?php echo( $movie[1] ) ?></td> <td><?php echo( $movie[0] ) ?></td> <tr> <? } ?> </table> </body> </html> Thanks in advance, SK
  17. What I am trying to do is query my database, pull all the rows that match to a specific bill, and total the values of the 'dollar amount' column ($num_amt in the query below) to determine the total dollar amount paid towards that specific bill. I cannnot figure out how to do this. Any ideas? Here is my code: $paid_lookup = mysql_query("SELECT * FROM `check_database` WHERE `bill_code` = '$bill_code'") or die('MySQL Connection Error:'.mysql_error()); while($paid = mysql_fetch_array($paid_lookup)){ $amount_paid = $paid[num_amt]; } Thanks, SK
  18. Below is my query string, it doesn't seem to work properly. As it is now the column `status` in my table is blank, and when I make the code with it only having AND `status`='$status' at the end of the string, or putting `status`='$status' AND at the beginning of the string, it still pulls up all records (thats with sending nothing for $searchstring, so thats just all wildcards, but the $status variable is set as UNPAID, and since none of them are marked unpaid it should return no results. So I assumed (I assume now that I assumed wrongly the first time, the mother all f ups) that it was looking for blank OR blank OR blank OR 'blank AND something' meaning it took the last statement of OR and combined just that one with the AND, or at the beggining of the code it just took the AND and combined it with the terms before the first or and looked for that one OR any of the other ones. So I tried to blank and blank OR blank and blank OR blank and blank but that is giving an error, so I am still doing this wrong. What are you supposed to do to locate records that definetly match one aspect along with several possible matches? $result = mysql_query("SELECT count(*) FROM receipt_of_bill WHERE `status`='$status' AND `bill_code` LIKE '%$searchstring%' OR `status`='$status' AND `vendor_name` LIKE '%$searchstring%' OR `status`='$status' AND `date_of_bill` LIKE '%$searchstring%' OR `status`='$status' AND `ref_number` LIKE '%$searchstring%' OR `status`='$status' AND `amount_due` LIKE '%$searchstring%' OR `status`='$status' AND `bill_due` LIKE '%$searchstring%' OR `status`='$status' AND `memo` LIKE '%$searchstring%'");
  19. Yes I see what it is using error reporting, the is_array is set as a variable ( it says $is_array instead of is_array) Thanks for the tip! SK
  20. Below is my full code on the page I am working on. Its a very small page with a single form input. ARRAY _POST variables are sent to it and the foreach is there to turn the posted variables into hidden form fields so I can post the data back to the original page along with the new data entered in the single form field. The problem is the page stops begining where the foreach starts, and I cannot figure out why. I ran it through PHPDesigner 2008 and it shows it as valid code. What is wrong on this script? Thanks in advance, SK <center> <form name="newscancodes" action="http://<?=$_SERVER['HTTP_HOST']?>/pages/new_scancodes.php" target="opener" method="post"> <? foreach ($_POST as $key => $value) { if ($is_array($value)) { foreach ($value as $subkey => $subvalue) { ?> <input type="hidden" name="<?php echo $subkey; ?>" value="<?php echo $subval; ?>"> <? } } else { ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"> <? } } ?> <font style="font-size: 0.8em;" face="Tahoma"> <b>Type the custom scancode value below</b> <br> <small><i><font color="red">Alphnumeric characters ONLY!</font></i></small> </font> <br> <input type="text" name="custom_scancode"> <br> <br style="line-height:3px"> <input type="image" src="http://<?=$_SERVER['HTTP_HOST']?>/images/submit_button.gif" value="submit" onclick="self.close();"> </form> </center>
  21. That works. Thanks guy, but I don't know what to say exactly. You helped me which is a nice thing, and you insulted me at the same time. Just weird I guess, usually nice people help others and are polite, and rude people insult other people and do not help them. That means you are not normal either. We can smell are own I guess. Thanks for the help anyways. SK
  22. This one is irritating me. I made a loop to count from 0 to 40, and inside the loop I have hidden from fields. The names of the fields are like model_number_1, description_1, qty_item_1, etc. The values for those are in $model_number_[0], $description_[0], $qty_item_[0], etc. I made a seperate variable that adds +1 onto the loop variable so it syncs up the _1 and the _[0] value that goes with it. The problem is, how do I get the array variables to populate into the hidden form fields? Normally I use the code just inside of the loop as below, but I guess because it is the array it does not function right, the data for the value is always either blank, or if I modify the code some I actually get it to print out $model_number_[0], $description_[0], $qty_item_[0] , the actual text just like I just typed it, it outputs to the browser verbatim as $model_number_[0], $description_[0], $qty_item_[0], it does not actually call the variable or display the variable that matches to that variable/array. If I make $model_number = $model_number_[0] it will display the correct variable data, but for whatever reason, the way the code is below, does not. Anyone have an idea why it doesn't? Or know a way I can call the array variables that match to each hidden form field WITHIN the loop statement so the same code doesn't have to be replicated by hand 40 times? Here is the code I am using: <? for ($i = 0; $i <41; $i++) { $t = $i+1; ?> <? $model_number = "model_number_[".$i."]"; $model_number = $$model_number; $description = "description_[".$i."]"; $description = $$description; $qty_item = "qty_item_[".$i."]"; $qty_item = $$qty_item; $price_item = "price_item_[".$i."]"; $price_item = $$price_item; $total_item = "total_item_[".$i."]"; $total_item = $$total_item; $po_number = "po_number_[".$i."]"; $po_number = $$po_number; ?> Model Number <?=$t?>: <?=$model_number?><br> Description <?=$t?>: <?=$description?><br> Qty Item <?=$t?>: <?=$qty_item?><br> Price Item <?=$t?>: <?=$price_item?><br> Total Item <?=$t?>: <?=$total_item?><br> PO Number <?=$t?>: <?=$po_number?><br> <input type="hidden" name="model_number_<?=$t?>" value="<?=$model_number?>"> <input type="hidden" name="description_<?=$t?>" value="<?=$$description?>"> <input type="hidden" name="qty_item_<?=$t?>" value="<?=$$qty_item?>"> <input type="hidden" name="price_item_<?=$t?>" value="<?=$$price_item?>"> <input type="hidden" name="total_item_<?=$t?>" value="<?=$$total_item?>"> <input type="hidden" name="po_number_<?=$t?>" value="<?=$$po_number?>"> <? } ?> Whats weird is on a different page I use this code, and it works for displaying the variable data, the only difference is that data is not in an array, so that has to be the reason. <? $price_item_x = "price_item_".$x; $price_item_x = $$price_item_x; ?>
×
×
  • 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.