PHP - Parse Rss And Find Images Based On Join/like Clause
Hi
I'm not sure if this needs to be in the MySQL forum so bare with me. I have small script which parses an RSS feed and inserts data into a table. This all works fine, but my problem now, is that I have another table, which has logos and when i parse the RSS, I'd like to be able to pass in the logo from the logos table into the RSS parse table. The problem is the RSS feed are products, with different suppliers, so I need to somehow check which manufacturer it is and then insert the image_id from the images table. I have a field in the main table, which has things like 'Available at Amazon' and 'Available at Play.com' What I want is some kind of join/like clause, where I can check, for example the word 'Amazon' in one field and match it to the images table. schema of both tables rss_table id, title, message, price, logos_id 1, iPad, Available at Apple, 400.00, BLANK_ID logos id, name, src 2, Apple, apple-logo.jpg So you can see, any product that gets parsed that has is available at apple, needs to have the logos_id of 2, if that makes sense? Below is a small snippet of my code (it isn't brilliant but works) I just need to then need to find the corresponding image to the manufacturer <?php $test = $_POST['post_title']; $articles = array(); $easy_url = $_POST["url"]; $rawFeed = file_get_contents($easy_url); $xml = new SimpleXmlElement($rawFeed); $channel = array(); $channel['title'] = $xml->channel->title; $channel['link'] = $xml->channel->link; $channel['description'] = $xml->channel->description; foreach ($xml->channel->item as $item) { $article = array(); $article['title'] = $item->title; $article['link'] = $item->link; $article['description'] = (string) trim($item->description); preg_match_all('/&#xA3;([0-9.]+)/', $item->description, $results); foreach ($results as $k => $v) { } $all = '&#xA3;'.$v[0]; $price_stripped = str_replace($all, '', $item->description); $desc = preg_match('/&#xA3;([0-9.]+)/', $item->description); preg_match_all('/~#£([0-9.]+)/', $item->description, $discount); foreach ($discount as $d => $disc) { str_replace("~#£","", $disc[0]); } preg_match_all('/£([0-9.]+)/', $item->description, $delivery_cost); foreach ($delivery_cost as $del => $deliv) { } preg_match_all('/\|(.*?)\./',$item->description,$match); foreach ($match as $rel => $retail) { $retail[0] = str_replace("|","", $retail[0]); } //$retail_logo = str_replace('On sale at', '', $retail[0]); $connection = mysql_connect("localhost","root","password"); if (!$connection) { die('Could not connect: ' . mysql_error()); } $total = $v[0] + $deliv[0] - $disc[0]; mysql_select_db("db_test", $connection); mysql_query("INSERT INTO rss (title, price, retailer_message, logo_id) VALUES ('$item->title', '$price_stripped', '$retail[0]', '$logo_id')"); mysql_close($connection); } ?> Any help is appreciated. Thanks Similar Tutorialsline 11 the while loop <?php //include connect $connect = mysql_connect("localhost","root","") or die ("Could Not Connect To Server"); mysql_select_db('npcs') or die ("Could Not Select Database"); $query = mysql_query("SELECT * FROM npc WHERE LEVEL=1") or die ("Could Not query Database"); echo "<table width='220' border='1' align='center'><tr><th>NPC NAME</th><th>JOB DESCRIPTION</th></tr><tr><th>LEVEL</th></tr><tr><th>EXPERIENCE</th></tr><tr><th>CASH</th></tr><tr><th>REPUTATION</th></tr>" while ($row = mysql_fetch_array($query)) { //set varibles from query $npcname = $row['npcname']; $level = $row['level']; $jobdes = $row['jobdes']; $exper = $row['exper']; $cash = $row['cash']; $rep = $row['rep']; //end getting varibles echo "<tr align='center'><td>{$row['npcname']}</td><td>{$row['jobdes']}</td><td>{$row['level']}</td><td>{$row['exper']}</td><td>{$row['cash']}</td><td>{$row['rep']}</td></tr>"; } ?> Folks, I need to Find and Replace some words in Source HTML, which is saved in a PHP Variable. Example: Quote $html = '<img src="some_source" title="paintball mask Picture" alt="Image for Paintball Mask"> <strong> Best Paintball Mask</strong>'; Find Condition: I want to FInd word "Paintball Mask" in vairiable $html, only where if the word "Paintball Mask" is there in Htaml Tag <Strong> </Strong>. As you can observe in $html, we have "Paintball Mask" in <IMG> Tag also, i want to Skip this because I only Need to COnsider if the word "Paintball Mask" there in <strong></strong> or not. One the words is found in <strong></strong> tag, i need to replace that word, to make it a hyperlink. (I think this bit can be done with strreplace()) But how can i restict my search to only <strong></strong> tag? Let me give Data Again: Quote $html = '<img src="some_source" title="paintball mask Picture" alt="Image for Paintball Mask"> <strong> Best Paintball Mask</strong>'; Find What: Paintball Mask Find in Which Tag: <strong> </strong> Replace it with: <a href="/">Paintball Mask</a> can someone help me with the code? Cheers Natasha Thomas I need PHP script that will parse XML-based (.xspf format) live stream playlist stored on web server, retrieve track data and print it on my web page. Print inside div as scrolling text (one line). The track data on page need be refreshed synchronously to show current track info. XSPF playlist example: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <playlist xmlns="http://xspf.org/ns/0/" version="1"> <title/> <creator/> <trackList> <track> <location>http://geodesid5.streams.audioveduct.com:80/di_ambient7</location> <title>Bruno Sanfilippo - Piano Textures 2 II</title> <annotation>Stream Title: Ambient - DIGITALLY IMPORTED - a blend of ambient, downtempo, and chillout Content Type:audio/mpeg Current Listeners: 0 Peak Listeners: 0 Stream Gen Electronic Ambient Downtempo</annotation> <info>http://www.di.fm</info> </track> </trackList> </playlist> I need get data from fields 'title' and 'annotation' (only text between Stream Title and Content Type). Also, after these two, I want scroll small custom text, when required. I searched some close example, but didn't find yet. Will be DOMDocument method suitable for this task? Can someone show me the right method to do this? Hi all I am currently in the process of scoping out a script and I am needing some help. I have a mysql table, that has several rows, each with the following: title | description | price | rss_url | delivery_cost | retailer_message | discount | total --------------------------------------------------------------------------------------------------------------- Halo: Reach (XBOX 360) | Description text | 35.99 | http://www.easycontentunits.com/rss/54626/669/rss2.rss | On sale at Gameplay | 0 | 35.99 ---------------------------------------------------------------------------------------------------------------------------------------------- Halo: Reach | Description text | 36.89 | http://www.easycontentunits.com/rss/54626/669/rss2.rss | On sale at Toys R Us | 0 | 36.89 What I need to do is the following: Select each row and extract the rss_url Parse the rss_url and extract the above details from the rss feed If the details in the rss feed has changed, update the row If the actual rss feed item is no longer in the rss feed, delete it from the table. So If the rss feed changes the first rows details in my db has the price field updated to 40.00, I need to update the row and the price field will change from 35.99 to say 40.00 If the row is no longer in the rss feed, then I need to delete it from the db. Can anyone provide me a small snippet or any advice on how to go about doing this? I can provide the code I'm using to actually insert the rows from the RSS feed if it helps? Thanks This portion is kind of stumping me. Basically, I have a two tables in this DB: users and users_access_level (Separated for DB normalization) users: id / username / password / realname / access_level users_access_level: access_level / access_name What I'm trying to do, is echo the data onto an HTML table that displays users.username in one table data and then uses the users.access_level to find users_access_level.access_name and echo into the following table data, I would prefer not to use multiple queries if possible or nested queries. Example row for users: 1234 / tmac / password / tmac / 99 Example row for users_access_level: 99 / Admin Using the examples above, I would want the output to appear as such: Username: Access Name: Tmac Admin I am not 100% sure where to start with this, but I pick up quickly, I just need a nudge in the right direction. The code I attempted to create just shows my lack of knowledge of joining tables, but I'll post it if you want to see that I did at least make an effort to code this myself. Thanks for reading! Hi, I have a php code that is used to find all the images in a website using simple_html_dom. When I tried to run it, this error occured:
Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\myPHP\index.php on line 20
This is my code:
<!DOCTYPE html> <html> <body> <?php include_once("simple_html_dom.php"); //use curl to get html content function getHTML($url,$timeout) { $ch = curl_init($url); // initialize curl with given url curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error return @curl_exec($ch); } $html=getHTML("http://www.website.com",10); // Find all images on webpage foreach($html->find("img") as $element) echo $element->src . '<br>'; ?> </body> </html>I have the simple_html_dom.php file in my directory. How can I correct this? thanks Edited by Raex, 20 August 2014 - 09:05 PM. hey, I get this error on line 69 which is the end of my code, but I just can't find the missing or wrong curly bracket :s <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <p> <?php if(isset($_POST['_submit_check'])){ if($form_errors = validate_form()){ show_form($form_errors);} else{ process_form();}} else{ show_form();} function process_form(){ print "Hello, ".$_POST['user'];} if(array_key_exists('user', $_POST)){ process_form();} else{ show_form(); } function validate_form(){ $errors = array(); if(strlen($_POST['user']) < 1){ $errors[] = 'Your name must be at least 1 letter long.'; } return $errors;} if(array_key_exists('_submit_check', $_POST)){ if(validate_form()){ proces_form(); } else{ show_form();} } else{ show_form(); } function show_form($errors = ''){ if($errors){ print 'please correct these errors: <ul><li>'; print implode('</li><li>', $errors); print '</li></ul>'; } print<<<_HTML_ <form method = "POST" action="$_SERVER[PHP_SELF]"> Your name: <input type="text" name="user"> </br> <input type="submit" value="Verzenden"/> </br> <input type="hidden" name="_submit_check_" value="1"> </form> _HTML_; } ?> </p> </body> </html> Hello,
I'm embarking on a pretty ambitious task and I need some bits of information here and there.
One of the functions I need to achieve is to build a query or array of photos based on a background image and user input.
So imagine that I have a box and within that box is a column of three rows.
I need to have three different bits of data be placed into each of the subsequent rows and then an image is taken of these three pieces of data overlaying the background photo.
Then stored somewhere with an incremented identifier to be pulled later.
I think I can already begin to imagine how it would work but what eludes me is a "screenshot" function to generate the images. I'm looking for .png or .jpg end result files with fixed width/height and item placement.
Thank you for any help
the idea on what im doing is like a converter, like showing what your name would look like with certain images per letter, when you input text (your name for example) and when you press the submit button you would get a series of images in a row that represent each character that you typed.
here is the example that i did...
<html> <?php This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308855.0 Hi. I am building an update table form. In this table there are only two fields, Header and Intro. Now I have the form and currently it displays whats already in the database. Now when the user edits these two fields and presses edit. Obviously I want it to update these fields. I have the code here but there is an issue with it. At the end of the update I believe I need a update fields WHERE....... which would be used if there was more than one entrance in the table but there is and only ever will be one entry. WHERE what? I dont have a where anything. Do I need this or can it be omitted somehow? <?php if(isset($_POST['edit'])){ //Process data for validation $header = trim($_POST['header']); $intro = trim($_POST['intro']); //Perform validations next //Prepare data for db insertion $header = mysql_real_escape_string($header); $intro = mysql_real_escape_string($intro); //insert $qUpdateDetails = "UPDATE index SET `header` = '".$header."', `intro` = '".$intro."', WHERE ???????='".?????????."'"; $rUpdateDetails = mysql_query($qUpdateDetails) or die(mysql_error()); //next page $page_edit = "Index page has been edited"; $url = "signed.php?edit='".$page_edit."'" or die(mysql_error()); header("Location: ".$url."") or die(mysql_error()); exit(); } } ?> This may be super simple, but it's stumping me. Is this an If/Then clause: Code: [Select] ($month != 1 ? $month - 1 : 12) Is it saying if $month does not equal 1 then $month-1; if so, then what does the colon mean? If not, then what is this piece of code doing? Hi
I am now on to viewing listings but want to to show listings that are just submitted by that user and display them on their profile page but can't get the WHERE clause working
Below is the coding for what I have
Profile page
echo "<p><a href='view-private-listings.php?id={$_SESSION['user_id']}'>View Listings</a></p>";Add Listing page HTML Submitted By: <input type="text" name="submittedby">View Listings Page <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php $title = "Private Seller Listings"; include ( 'includes/header.php' ); ?> <?php require_once("functions.php"); $con=mysqli_connect("host","username","password","database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Start a session for error reporting session_start(); $submittedby=$_POST['submittedby']; $listingtitle=$_POST['listingtitle']; $query = mysqli_query($con,"SELECT listingtitle FROM privatelistings WHERE item LIKE '%$submittedby%'"); echo "<p>Title: {$listingtitle['listingtitle']}</p>"; mysqli_close($con); ?> <?php include( 'includes/footer.php' ); ?>All I get is the following error Notice: Undefined index: listingtitle in /zacs-car-site/view-private-listings.php on line 26 Thank you in advance Kind regards Ian hi, how can I add more than one ID to a WHERE clause? Code: [Select] "SELECT * FROM t_mytable WHERE id_product = 1 "; I need to select products with different id's i.e Code: [Select] "SELECT * FROM t_mytable WHERE id_product = 1,2,3,4,5 "; Thanks Hi, I have a SQL statement: $sql='SELECT PROPID, ADDRESS_1, ADDRESS_2, TOWN, POSTCODE1, POSTCODE2, BEDROOMS, BATHROOMS, RECEPTIONS, PRICE, TRANS_TYPE_ID FROM properties WHERE TRANS_TYPE_ID=2 AND BEDROOMS =3 AND PROP_SUB_ID IN (1,2,3,4,5,6,21,22,23,24,27,30,95,128,131) ORDER BY DATE_ADDED, PROPID DESC'; I want to be able to get the fields and their corresponding values as such: $result['TRANS_TYPE_ID']=2; $result['BEDROOMS']=3; And then capture the values in PROB_SUB_IN IN(*) How can I do this? Any help will be greatly appreciated. Thanks Code: [Select] $search = "`title` LIKE '%Silvin AND wts%'"; I want to search for both of those keywords why not work? Hi, I have an empty array and i populated the array through code and i printed to check if everything ok. So far so good. I now have an array say $ids = ('123','456'). Now, i have a table in db that has ids as well, I need to make a query to check for id's that are not inside the array, so if the db table have '123','456','789' i want the result of the query to be only the last one '789'. $arr = array(); array_push($arr,$previd2); print_r ($arr); I get the result as follows: Array ( [0] => 533349 [1] => 533355 ) so what query i can use to get the other id's from db table that is not part of that array? here is what i tried: $qry = "select staffname, joindate from staff WHERE OracleID NOT IN ($arr)"; $answ = mysqli_query($con, $qry); I get error: Notice : Array to string conversion in C:\xampp\htdocs\AttendanceSystem\login\reportsforallid.php Edited March 30, 2020 by ramiwahdan more info I am brand new to mysql and php but I have created a database and loaded two tables using cPanel and phpMyAdmin. Now I need some programs to access my data. I have a couple of simple ones that work, but I can't figure out what I really need, I am trying to Select a table Where the Value is a $variable, not a fixed value. Of course the end result will be to pass the value from a Form, but I have to get this to work first. <?php // Connect to database============================= include("connect_db.php"); $table='airplanes'; $amano='123456' $iden='1' // Send query =========================================================== // $result = mysql_query("SELECT * FROM {$table} where ama='123456'"); == this works // $result = mysql_query("SELECT * FROM {$table} where ama='940276'"); == this works // $result = mysql_query("SELECT * FROM {$table} where id='1'"); // this works // $result = mysql_query("SELECT * FROM {$table} where id = '{$iden}'"); == doesnt work // $result = mysql_query("SELECT * FROM {$table} where id = $iden"); == doesnt work // $result = mysql_query("SELECT * FROM {$table} where id = ($iden)"); // == doesnt work // $result = mysql_query("SELECT * FROM {$table} where id = $iden"); // == doesnt work // $result = mysql_query("SELECT * FROM {$table} where ama='$amano'"); // == doesnt work $result = mysql_query("SELECT * FROM {$table} where ama=($amano)"); // == doesnt work Thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330779.0 Hi,
Im having a problem and I can't seem to figure it out or find anything on the net.
If I use the following code the script successfully updates every row in the table:
mysqli_query($con,"UPDATE Ads SET Ads_LocalArea='Stroud'");However if I try updating the table using the WHERE clause in any of the combinations below nothing happens. mysqli_query($con,"UPDATE Ads SET Ads_LocalArea='Stroud' WHERE Ads_ID=$DBROWID");---------------------------------------------------------------------- My Script: mysqli_query($con,"INSERT INTO Ads (Ads_ID, Ads_AID, Ads_Title) VALUES ('', '$Polished_AdRef', '$Polished_AdTitle')"); $DBROWID = mysqli_insert_id($con); mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID=$DBROWID"); // TRIED THESE TOO // mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID='$DBROWID'"); // mysqli_query($con,"UPDATE Ads SET Ads_AID='Stroud' WHERE Ads_ID='5'");Does any one know where I am going wrong? |