Jump to content

jaxdevil

Members
  • Posts

    268
  • Joined

  • Last visited

Everything posted by jaxdevil

  1. I am trying to replace the character underscore ( _ ) with a space. It is not working, it is making the whole string blank. Any thing I am doing wrong? <? $string = $row['subcat']; $replacement = ' '; $pattern = '_'; echo preg_replace($pattern, $replacement, $string); ?>
  2. I don't know what is wrong, this is returning an empty set of rows, no results. I have used this many times before, this is just slightly modified, I don't know whats wrong. Do you see anything? <SELECT NAME="location" style="width:140px; border:0px solid; height:17px; padding:0px 3px; position:relative;"> <OPTION VALUE="NONE">-----Select Category----- <?php mysql_connect('localhost','xxx_xxx','xxxxxx'); mysql_select_db('xxx_xxx') or die(mysql_error()); $sql = "SELECT DISTINCT `subcat` FROM 'products'" or die(mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { ?> <OPTION VALUE="<?=$row['subcat']?>"><?=$row['subcat']?> <?php } ?>
  3. I cannot connect to the yahoo shopping API because you have to send user agent data. I tried with the below but thats not working. It keeps telling me invalid user-agent (and this one is specifically on the list of valid agents so its not that). Anyone have any idea? <?php $Zombie ="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) (for IE)"; $Zombie_Striper = addslashes($Zombie); header("$Zombie_Striper"); require("pulldata.php"); $filename = "http://shopping.yahooapis.com/shoppingservice/v3/productsearch?appid=q_h1FXbV34EyS_7Dqt8W5dU.vFvpLm4dGuo_iUFiNANhMmBgBlV1atezl4zTW3tEgOc1nGU-&query=GDM"; function Juggler($pulls) { print "".$pulls["ERROR"]." at ".$pulls["MESSAGE"]." <br>"; } PullData_parse($filename,"Juggler","xml|ERROR/"); print PullData_getErrorMessage(); echo $Zombie_Striper; ?>
  4. never mind, I got it. I wasn't putting in a query string to look for. My bad
  5. ok, I am trying to select distinct column data. I.e. I have in my database many columns and one of the columns is 'man' (for manufacturers) I am trying to pull a query that will return all the unique manufacturer entries. Say I have 'Nike' and 'Reebok' and 'Whatever'. And I have Nike 60 times, Rebook 12 times, and Whatever 2 times. I want it to return just 1 Nike, 1 Reebok and 1 Whatever. Below is the code I am using, obviously it is not working. Who knows what to do here? I appreciate it... <?php require($_SERVER['DOCUMENT_ROOT'] . "/config.inc.api.php"); ?> <?php $sql = "SELECT DISTINCT `man` FROM products LIMIT 5"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)) { echo '<li onClick="fill(\''.$row['man'].'\');">'.$row['man'].'</li>'; } ?>
  6. I know this one I just can't remember it. How do I make this: $FinalCat = '$SubSubCat|$SubSubSubCat'; Display the actual variable with a | and then the other variable. I.e. if the variable $SubSubCat means 'hello' and $SubSubSubCat means 'goodbye' then I want to make $FinalCat mean 'hello|goodbye' How do I accomplish this? Thanks in advance guys! SK
  7. Well it was a pretty easy fix, once I stared at it long enough..hehehe! $size = sizeof($seen)-1; for($i=0;$i<=$size;$i++) I just subtracted one from the $size variable. Problem solve.d Thank god that is over
  8. Below is the entire code I am using. It works like gangbusters but it always displays one extra row than there is, so a blank row comes up. How do I get rid of that? I also notice there is a $multiple variable in there but have no idea what that is for. Someone on here made this code and it has always been there, but it can't be doing anything good as an unregistered variable, can it? Maybe thats why it is displaying one more row than the query brings up? Any help is greatly appreciated. I have been up and working on this project since 8am yesterday. I am exhausted. <table width="215" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="215" height="14" background="images/menu_top.gif"> </td> </tr> <?php $sql = "SELECT DISTINCT `cats` FROM products ORDER BY `cats`" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); $seen = array(); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); $main_cat = $cats[0]; if(!in_array($main_cat,$seen) && !in_array($main_cat,$multiple)) { array_push($seen,$main_cat); } else { array_push($multiple,$main_cat); unset($seen[$main_cat]); } } $size = sizeof($seen); for($i=0;$i<=$size;$i++) { ?> <tr> <td width="215" height="24" background="images/menu_back.gif"> <font face="Tahoma,Verdana,Arial" color="#6e6e6e" style="font-size: 0.75em;"> <div style="padding-left: 35px;"> <a href="cats.php?cat=<?=$seen[$i]?>&subcat=1"><?=$seen[$i]?></a> </div> </td> </tr> <? } ?> <tr> <td width="215" height="6" background="images/menu_bottom.gif"> </td> </tr> </table> <img src="images/contactinfo.gif"> </td> </tr> </table>
  9. Works like gang busters! Thanks a million man!
  10. I have a code that is stripping all HTML markup away from a database field before outputting it, but there are still ASCII character markups left like: &#153; I tried using preg_replace but I must be doing it wrong because it is not removing anything. Here is the code, can you tell me what I am doing wrong? $description = $row['description']; $details = $row['details']; $description = strip_tags($description); $details = strip_tags($details); $pattern = '&#*;'; $replacement = ''; $description = preg_replace($pattern, $replacement, $description); $details = preg_replace($pattern, $replacement, $details);
  11. Ok, I have a field with multiple categories and subcateories, split with a delimeter. I am using an explode to split them up from the delimiter, selecting the first category before the first delimeter, and displaying all the unique ones, below is my code, but something is going wrong now, I copied it to a new page and modifie, td it some, and there is multiple instances of it on the same page. I modified the names so it wouldn't interfere with each other, but something is wrong. On the `cats` query, the second one on the page, it only pulls up three rows. There are 5. Now I have noticed there is an extra blank row that keeps coming up on all of them on the main pages, except on this particular query, the second one, it has no blank row, the query above it using the same code is pulling up the 2 unique first instances, and then the 3rd blank row, now this query is showing three rows. I think that has something to do with it. Three rows on the first one, and then three rows limited on the second, something looks like it is linked some how. Below is my code, I am trying to figure out how to have all the results come up not just those first three. <tr> <td> Supplier: </td> <td> <SELECT NAME="supplier"> <OPTION VALUE="NONE">-----Select Product Supplier---- <?php $sql = "SELECT DISTINCT `supplier` FROM products" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); $seen = array(); while($row = mysql_fetch_array($query)) { $supplier = explode("|",$row['supplier']); $list_suppliers = $supplier[0]; if(!in_array($list_suppliers,$seen) && !in_array($list_suppliers,$multiple)) { array_push($seen,$list_suppliers); } else { array_push($multiple,$list_suppliers); unset($seen[$list_suppliers]); } } $size = sizeof($seen); for($i=0;$i<=$size;$i++) { ?> <OPTION VALUE="<?=$seen[$i]?>"><?=$seen[$i]?> <?php } ?> </SELECT> </td> </tr> <tr> <td> Category: </td> <td> <SELECT NAME="cats"> <OPTION VALUE="NONE">-----Select Category---- <?php $sql2 = "SELECT DISTINCT `cats` FROM products" or die ( "Query failed due to: ".mysql_error()); $query2 = mysql_query($sql2); $seen2 = array(); while($row2 = mysql_fetch_array($query2)) { $cats = explode("|",$row2['cats']); $list_cats = $cats[0]; if(!in_array($list_cats,$seen2) && !in_array($list_cats,$multiple)) { array_push($seen2,$list_cats); } else { array_push($multiple,$list_cats); unset($seen2[$list_cats]); } } $size2 = sizeof($seen2); for($a=0;$a<=$size;$a++) { ?> <OPTION VALUE="<?=$seen2[$a]?>"><?=$seen2[$a]?> <?php } ?> </SELECT> </td> </tr>
  12. Well I figured it out. Here is the fixed code below if anyone else ever needs it: <?php mysql_connect('localhost','xxx','xxx'); mysql_select_db('xxx') or die(mysql_error()); ?> <? header("Content-Type: application/rss+xml"); ?> <? echo "<?";?>xml version="1.0" encoding="UTF-8"<? echo "?>";?> <rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0"> <channel> <title>GS Wholesale</title> <description>Your Consumer Electronics and More Store!</description> <link>http://GSWholesale.com</link> <?php $sql = "SELECT * FROM products WHERE `active`='Yes' ORDER BY `cats` LIMIT 5" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); $cat = end($cats); $description = $row['description']; $details = $row['details']; $description = strip_tags($description); $details = strip_tags($details); ?> <item><title><?=$row['man']?> <?=$row['mod']?> <?=$row['name']?></title> <g:brand><?=$row['mod']?></g:brand> <g:condition>new</g:condition> <g:description><?=$description?> <?=$details?></g:description> <g:model_number><?=$row['mod']?></g:model_number> <g:id><?=$row['mod']?></g:id> <g:image_link><?=$row['img_url']?></g:image_link> <g:pickup>true</g:pickup> <g:link>http://GSWholesale.com/product.php?id=<?=$row['mod']?></g:link> <g:mpn><?=$row['mod']?></g:mpn> <g:price><?=$row['price']?></g:price> <g:product_type><?=$cat?></g:product_type> <g:upc><?=$row['upc']?></g:upc> <g:quantity>1000</g:quantity> <g:payment_notes>Google Checkout</g:payment_notes> <g:payment_accepted>PayPal</g:payment_accepted> <g:payment_accepted>Visa</g:payment_accepted> <g:payment_accepted>Mastercard</g:payment_accepted> <g:payment_accepted>American Express</g:payment_accepted> <g:payment_accepted>Discover</g:payment_accepted> <g:payment_accepted>Cash</g:payment_accepted> <g:payment_accepted>Wire Transfer</g:payment_accepted> </item> <? } ?> </channel> </rss> </xml>
  13. I need to remove anything that is a '<' or a '>' or anything that comes between those two symbols in my query (like < br > or < li > or < hr > etc.). In my database the field 'description' contains text that is html formated so when it display it is in lines, and has breaks, etc. What I need to do is remove all of that HTML formating for this particular query. I am sure there is some simple way. Anyone know how to do this? I am sure it is something like a replace function but I can't figure it out. Any ideas? I copied my ENTIRE code below. The row query I am trying to remove those html codes from is $row['description'] Thanks for any help you can give! <?php mysql_connect('localhost','xxx','xxx'); mysql_select_db('xxx') or die(mysql_error()); ?> <? header("Content-Type: application/rss+xml"); ?> <? echo "<?";?>xml version="1.0" encoding="UTF-8"<? echo "?>";?> <rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0"> <channel> <title>GS Wholesale</title> <description>Your Consumer Electronics and More Store!</description> <link>http://GSWholesale.com</link> <?php $sql = "SELECT * FROM products WHERE `active`='Yes' ORDER BY `cats` LIMIT 5" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); $cat = end($cats); ?> <item><title><?=$row['man']?> <?=$row['mod']?> <?=$row['name']?></title> <g:brand><?=$row['mod']?></g:brand> <g:condition>new</g:condition> <g:description><?=$row['description']?> <?=$row['details']?></g:description> <g:model_number><?=$row['mod']?></g:model_number> <g:id><?=$row['mod']?></g:id> <g:image_link><?=$row['img_url']?></g:image_link> <g:pickup>true</g:pickup> <g:link>http://GSWholesale.com/product.php?id=<?=$row['mod']?></g:link> <g:mpn><?=$row['mod']?></g:mpn> <g:price><?=$row['price']?></g:price> <g:product_type><?=$cat?></g:product_type> <g:upc><?=$row['upc']?></g:upc> <g:quantity>1000</g:quantity> <g:payment_accepted>Google Checkout</g:payment_accepted> <g:payment_accepted>PayPal</g:payment_accepted> <g:payment_accepted>Visa</g:payment_accepted> <g:payment_accepted>Mastercard</g:payment_accepted> <g:payment_accepted>American Express</g:payment_accepted> <g:payment_accepted>Discover</g:payment_accepted> <g:payment_accepted>Cash</g:payment_accepted> <g:payment_accepted>Checks</g:payment_accepted> <g:payment_accepted>Cashiers Checks</g:payment_accepted> <g:payment_accepted>Money Orders</g:payment_accepted> <g:payment_accepted>Wire Transfer</g:payment_accepted> </item> <? } ?> </channel> </rss> </xml>
  14. I have a field called `cats` and in it it has all of the categories and subcategories, seperated by the delimiter '|' and they are in hierarchical order, the main category is first, then the subcategory, then the sub-subcategory, etc. I need to display the final subcategory in a row display, I can break up the data with explode but I do not know how to select the last text, the final subcategory after the last |. Here is an example of how the categories field (called `cats` in the database) looks for one example. The problem is some of the fields have a category, and a subcategory, and some have category, subcategory, and sub-subcategory, etc. So I can't just display say the 4th array, I have to make it display what is after the last delimiter. here is an exmaple of the categories field: consumer electronics|portable audio|mp3 and mp4 players|ipod And here is the entire code I have now: <?php mysql_connect('localhost','xxx','xxx'); mysql_select_db('xxx') or die(mysql_error()); ?> <&#157;xml version="1.0" encoding="UTF-8"&#157;> <rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0"> <channel> <title>GS Wholesale</title> <description>Your Consumer Electronics and More Store!</description> <link>http://GSWholesale.com</link> <?php $sql = "SELECT * FROM products WHERE `active`='Yes' ORDER BY `cats` LIMIT 5" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); ?> <item><title><?=$row['man']?> <?=$row['mod']?> <?=$row['name']?></title> <g:brand><?=$row['mod']?></g:brand> <g:condition>new</g:condition> <g:description><?=$row['description']?> <?=$row['details']?></g:description> <g:model_number><?=$row['mod']?></g:model_number> <g:id><?=$row['mod']?></g:id> <g:image_link><?=$row['img_url']?></g:image_link> <g:pickup>true</g:pickup> <g:link>http://GSWholesale.com/product.php?id=<?=$row['mod']?></g:link> <g:mpn><?=$row['mod']?></g:mpn> <g:price><?=$row['price']?></g:price> <g:product_type><?=$cats?></g:product_type> <g:upc><?=$row['upc']?></g:upc> <g:quantity>1000</g:quantity> <g:payment_accepted>Google Checkout</g:payment_accepted> <g:payment_accepted>PayPal</g:payment_accepted> <g:payment_accepted>Visa</g:payment_accepted> <g:payment_accepted>Mastercard</g:payment_accepted> <g:payment_accepted>American Express</g:payment_accepted> <g:payment_accepted>Discover</g:payment_accepted> <g:payment_accepted>Cash</g:payment_accepted> <g:payment_accepted>Checks</g:payment_accepted> <g:payment_accepted>Cashiers Checks</g:payment_accepted> <g:payment_accepted>Money Orders</g:payment_accepted> <g:payment_accepted>Wire Transfer</g:payment_accepted> </item> </channel></rss> <? } ?> Any help is greatly appreciated!
  15. I think this is too complex. I am going to post a new topic but for a different approach. I can't figure this out and I don't expect anyone on here to go through this kind of a physical pain headache as this takes. I mean for one like this you really have to keep like 8 things in your mind at all times. Too much. Must be a simpler way. Lets see. I am leaving this one because if someone can modify this code that would be great.
  16. This one takes a big mind to wrap their head around. I get head aches when I do stuff this complex. Ok here is what I am trying to do. I have category and subcategory fields in a field in my database called `cats`, for example, an ipod would be 'consumer electronics|portable audio|mp3 and mp4 players|ipod' and I have below a copy of my code, it is to generate an xml output for google. The code works, but not the displaying the product part. The code I use to display the subcategory works on my main pages of my site, but when I try to add it to this I get no result in the $product_type field. Maybe someone on here can figure it out? Also, the code , you see where I have it subtracting 1? $numberz = $size2-1; on that part? I know that is one thing that is wrong. That counts the number of fields, I need the number for $numberz to display the number of delimiters in the array return, so when I select the depth to go using the $cats[$numberz] it shows the subcategory for that item. I can't just make it a standard number, it has to be dynamic because some things have a category and are 3 subcategories deep, and others are only 1 subcategory deep. I can tell which one by how many '|' delimiters are in the display. So anyone can figure this one out? Must be Albert Einstein if you can. I am going to take some Excedrin right now..lol!! <?php $database = "xxx"; $dbconnect = mysql_pconnect('localhost','xxx','xxx'); mysql_select_db($database, $dbconnect); $query = "select * FROM `products` WHERE `active`='Yes'"; $result = mysql_query($query, $dbconnect); while ($line = mysql_fetch_assoc($result)) { $return[] = $line; } $query2 = mysql_query($query); $seen = array(); $size2 = sizeof($seen); $numberz = $size2-1; while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); $main_cat = $cats[$numberz]; if(!in_array($main_cat,$seen) && !in_array($main_cat,$multiple)) { array_push($seen,$main_cat); } else { array_push($multiple,$main_cat); unset($seen[$main_cat]); } } $size = sizeof($seen); for($i=0;$i<=$size;$i++) { $product_type = $seen[$i]; } $output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <rss version =\"2.0\" xmlns:g=\"http://base.google.com/ns/1.0\"> <channel> <title>GS Wholesale</title> <description>Your Consumer Electronics and More Store!</description> <link>http://GSWholesale.com</link>"; foreach ($return as $line) { $output .= "<item><title>".htmlentities($line['man'])." ".htmlentities($line['mod'])." ".htmlentities($line['name'])."</title> <g:brand>".htmlentities($line['mod'])."</g:brand> <g:condition>new</g:condition> <g:description>".htmlentities($line['specs']).". About the manufacturer ".htmlentities($line['man'])." ".htmlentities($line['full'])."</g:description> <g:model_number>".htmlentities($line['mod'])."</g:model_number> <g:id>".htmlentities($line['mod'])."</g:id> <g:image_link>".htmlentities($line['img_url'])."</g:image_link> <g:pickup>true</g:pickup> <g:link>http://GSWholesale.com/product.php?id=".htmlentities($line['mod'])."</g:link> <g:mpn>".htmlentities($line['mod'])."</g:mpn> <g:price>".htmlentities($line['price'])."</g:price> <g:product_type>".$product_type."</g:product_type> <g:upc>".htmlentities($line['upc'])."</g:upc> <g:quantity>1000</g:quantity> <g:payment_accepted>Google Checkout</g:payment_accepted> <g:payment_accepted>PayPal</g:payment_accepted> <g:payment_accepted>Visa</g:payment_accepted> <g:payment_accepted>Mastercard</g:payment_accepted> <g:payment_accepted>American Express</g:payment_accepted> <g:payment_accepted>Discover</g:payment_accepted> <g:payment_accepted>Cash</g:payment_accepted> <g:payment_accepted>Checks</g:payment_accepted> <g:payment_accepted>Cashiers Checks</g:payment_accepted> <g:payment_accepted>Money Orders</g:payment_accepted> <g:payment_accepted>Wire Transfer</g:payment_accepted> </item>"; } $output .= "</channel></rss>"; header("Content-Type: application/rss+xml"); echo $output; ?>
  17. That worked like gang busters! I had to modify one or two things, there was a comma were a semicolon was supposed to be, simple mistake I am sure you were typing fast, and I just took the html part out of the php code altogether, I always like to do that, just to save any mistakes I make. Here it is in final form, you the man! <SELECT NAME="location"> <OPTION VALUE="NONE">-----Select Category----- <?php $sql = "SELECT DISTINCT `cats` FROM categories" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); $seen = array(); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); $main_cat = $cats[0]; if(!in_array($main_cat,$seen) && !in_array($main_cat,$multiple)) { array_push($seen,$main_cat); } else { array_push($multiple,$main_cat); unset($seen[$main_cat]); } } $size = sizeof($seen); for($i=0;$i<=$size;$i++) { ?> <OPTION VALUE="<?=$seen[$i]?>"><?=$seen[$i]?></OPTION> <? } ?> </SELECT> <?=$size?>
  18. DAMN YOU ARE GOOD! That was quick. I thought this one would take a while. I am pretty kindergarten knowledge on some things, like this one. Well here is what I have now... <SELECT NAME="location"> <OPTION VALUE="NONE">-----Select Category----- <?php $sql = "SELECT DISTINCT `cats` FROM categories" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); $main_cat = $cats[0]; $sub_cat = $cats[1]; $subsubcat = $cats[2]; $size = sizeof($cats); ?> <OPTION VALUE="<?=$main_cat?>"><?=$main_cat?> <?php } ?> </SELECT> Which does pull up just the main categories, but what I am trying to do is just display distinctive categories. Right now I have say 300 entries of one category, 100 of another, etc. I want it to just display 1 entry for each distinctive category, not display 100 entries for sports, or 300 entries for crafts. Any ideas? I appreciate the help
  19. Ok, this one is tricky. I am trying to pull distinct records but the field I am pulling from has everything broken down as follows and using a '|' as the delimiter between the values... main cat|subcat|subsubcat|subsubsubcat|etc I want to display all of the distinct 'main cat', so I want the query to look for just what is before the first | delimiter. Any ideas? Here is the code I have now.. <SELECT NAME="location"> <OPTION VALUE="NONE">-----Select Category----- <?php $sql = "SELECT DISTINCT `cats` FROM categories" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { ?> <OPTION VALUE="<?=$row['cats']?>"><?=$row['cats']?> <?php } ?> </SELECT>
  20. Duh! My bad. Consumer electronics was that I was testing the search with, and it only has the delimiter AFTER the name, not before. Dooh (as homer would say) Ah well, third times the charm Thank anyways people, hope this helps someone looking for the same answer.
  21. I am trying to make a search query that can display all the items in the database that match a phrase that is between two '|' symbols. I have a field in my database that is called 'cats' for categories, and since everything has multiple categories I seperate the different ones from each other with a '|' symbol. Now I am trying to pull them up based on that using the following code and by sending the data to the page. I can't get it to work. Any ideas? By the way I use the same code and it works when there is just a single thing to search for in the cats field, not multiples with a delimeter and I just do a plain search like %cat1%. Here is an example of whats in the `cats` field now: consumer electronics|videogame console software|ps3 games And here is the query string: $result = mysql_query("SELECT count(*) FROM products WHERE `cats` LIKE '%|$cat1|%' OR `cats` LIKE '%|$cat2|%' OR `cats` LIKE '%|$cat3|%'") or die(mysql_error I appreciate any help guys
×
×
  • 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.