justlukeyou
-
Posts
957 -
Joined
-
Last visited
Posts posted by justlukeyou
-
-
Hi,
I dont have a query. This is all the code I have:
$result = mysql_query("SELECT * FROM productfeed"); while($row = mysql_fetch_array($result)) { $id = $row['ID']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; ?> <?php { echo "<div class=\"productdisplayshell\"> <div class=\"productdisplayoutline\"> <div class=\"productborder\"><center> <a href=\"$link\" target=\"_blank\" ><img src=\"$image\" /></a> </center> </div></div> <div class=\"productdescriptionoutline\"><div class=\"productdescriptionbox\"> <a href=\"$link\" target=\"_blank\" >$description</a> </div><div class=\"productfulldescriptionbox\"> $fulldescription </div></div> <div class=\"productpriceoutline\"> <div class=\"productpricebox\"><center>£ $price</center></div> <div class=\"productbuybutton\"><center><a href=\"$link\" target=\"_blank\" ><img src=/images/buybutton.png /></a></center></div></div></div>" ; } }
-
Hi,
I'm now sure what you mean, at this stage I am just trying to print everything that is in the database and limit it to 100.
I've tried lots of different methods of displaying it but this is the only one which prints anything. Should I remove the while option?
-
Hi,
My code is below, Ive tried around 30 variations of the limit function, I have also tried it before and after the query.
while($row = mysql_fetch_array($result)) { $id = $row['ID']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; SELECT '$link' FROM `productfeed` LIMIT 0, 2; ?> <?php { echo "<div class=\"productdisplayshell\"> <div class=\"productdisplayoutline\"> <div class=\"productborder\"><center> <a href=\"$link\" target=\"_blank\" ><img src=\"$image\" /></a> </center> </div></div> <div class=\"productdescriptionoutline\"><div class=\"productdescriptionbox\"> <a href=\"$link\" target=\"_blank\" >$description</a> </div><div class=\"productfulldescriptionbox\"> $fulldescription </div></div> <div class=\"productpriceoutline\"> <div class=\"productpricebox\"><center>£ $price</center></div> <div class=\"productbuybutton\"><center><a href=\"$link\" target=\"_blank\" ><img src=/images/buybutton.png /></a></center></div></div></div>" ; } }
-
Thanks, I have tried both methods but cant get them to work.
At the moment I just echoing all the information in the database, does that count as a query?
If I try SELECT `field` FROM `table` LIMIT 10 do I need to replace field and table with my fields and table. I have tried that it wont work either.
-
I have a database of 100 lines which have echoed onto the page so each line within the database is printed. I would like to limit it to ten. However, I have tried a whole range of different loops but none of them seek to work.
Some of them print the database ten times so I have 1000 lines on the page. Can anyone advise the best method of limiting how many lines within a database are printed on the page?
-
Hi,
I am trying to open a link from my database into a black tab.
Can I try this: "target=\"_blank\">"
Will this use the " without messing up the PHP script?
-
Hi,
This publishes the images with in a column down the page.
I have tried the code above but it only publishes the first image in the database.
Is there a way of using external links in PHP?
-
Hi,
I have a peice of code which publishes an image with a link from my database. However I cant get it to use external links. My code is:
echo "<a href=\"" .$link . "\"> <img src=\"" .$image ."\" /> </a><BR />";
I have tried all the options I can think of but I cant get it work. Can anyone advise please?
-
But the page I found said that you should leave that off and use another method.
You can read pages on your own server without having that on.
Switching it on cases the purposes of PHP 5 switching it off.
-
Hi,
The XML file is in my root folder.
The hosting company has actually come back to me as said I should add a php.ini file and add "allow_url_fopen = On"
But I thought the whole purpose of this code is to not use that as it switches on the PHP 5 security block.
-
Hi,
I have tried this again but it is still coming up with the same error: failed to open stream: No such file or directory
Can anyone please help me with this. I have read that some servers block "file_get_contents" so I emailed my hosting company and they told me that it should work but I still cant get it to work. Is it possible that my server is set up differently?
I dont know why it keeps saying failing to open the stream other than some form of security block.
mysql_connect("$host", "$username", "$password")or die("no connection"); mysql_select_db("$db_name")or die("Database Connection Error"); $xmlReader = new XMLReader(); $filename = "datafeed_98057.xml"; print $_SERVER['DOCUMENT_ROOT']; if(!$xml = file_get_contents('/path/to/datafeed_98057.xml')) { print 'Could not open xml file' ; $url_contents = file_get_contents($url); if ($url_contents === false) { die("file_get_contents($url) failed"); } if ($url_contents === '') { die("file_get_contents($url) returned no data"); } $retval = file_put_contents($filename, $url_contents); if ($retval === false) { die("file_put_contents($filename) failed"); } $xmlReader->open($filename); while ($xmlReader->read()) { switch ($xmlReader->name) { case 'product': $dom = new DOMDocument(); $domNode = $xmlReader->expand(); $element = $dom->appendChild($domMode); $domString = utf8_encode($dom->saveXML($element)); $product = new SimpleXMLElement($domString); $awImage = $product->image; //insert query if(strlen($image) > 0) { $query = mysql_query("REPLACE INTO productfeed (image) VALUES ('$awImage')"); echo $awImage . "has been inserted </br>"; } break; } } } ?>
-
Sorry to reply to my own post but it is now creating new XML feed in the same folder as my php script. but it is blank. I take that it means it is creating the XML file but not reading the information from the existing file.
My long term objective is to automatically create an XML file from a feed but I whilst I am learning I am putting a test XML file on my own server which I copy into a different folder and then insert that information into a database.
I can echo content from my database its just a matter of bloody putting data into the database from an XML feed.
-
Thanks,
I have done that, I have tried placing it everywhere between the opening { and next opening { but its keeps coming up with error that the file cannot be found.
The two opening { do have closing which work but closing the { print opening creates the error that file cant found which means I back to square one.
{ print 'Could not open xml file' ; file_put_contents($filename, file_get_contents($xml)); $url_contents = file_get_contents($url);if ($url_contents === false) { die("file_get_contents($url) failed");}if ($url_contents === '') { die("file_get_contents($url) returned no data");}$retval = file_put_contents($filename, $url_contents);if ($retval === false) { die("file_put_contents($filename) failed");} $xmlReader->open($filename); while ($xmlReader->read()) { switch ($xmlReader->name) {
-
Im pretty sure it comes from this, I need to place an ending to this but wherever I place brings up the error I had "No such file or directory". I have tried placing it in around 5 places.
Do I need to close off a certain section which looks up where the file is and reads it?
{ print 'Could not open xml file';
-
Parse error: syntax error, unexpected $end in /homepages/1/d179449150/htdocs/(domain)/ProductFeed/phpfeed.php on line 59
Its an end error but its just a standard end which I have used a few times before. Does anything interfere with end tags?
-
Ah great, thanks for that, I have removed the exits it now picks up the following as an error:
break; } } ?>
I dont know why its doing that because I have standard tags in place.
Many thanks for all your help with all of this.
-
I cant believe its so difficult to read a file on my own server, its really stressing me out lol
-
Hi,
I have spent a couple of hours on this but I am still no nearer. I have entered the code but it is just printing this /kunden/homepages/1/d179449150/htdocs/(domain)
Does this mean my server is set up wrong and it is unable to identify the root folder?
This is the code Im using:
$xmlReader = new XMLReader();
$filename = "datafeed_98057.xml";
print $_SERVER['DOCUMENT_ROOT'];
exit();
if(!$xml = file_get_contents('/path/to/datafeed_98057.xml'))
{ print 'Could not open xml file';
exit();}
file_put_contents($filename, file_get_contents($xml));
$xmlReader->open($filename);
$url_contents = file_get_contents($url);if ($url_contents === false) { die("file_get_contents($url) failed");}if ($url_contents === '') { die("file_get_contents($url) returned no data");}$retval = file_put_contents($filename, $url_contents);if ($retval === false) { die("file_put_contents($filename) failed");}
while ($xmlReader->read())
{
switch ($xmlReader->name)
{
case 'product':
$dom = new DOMDocument();
$domNode = $xmlReader->expand();
$element = $dom->appendChild($domMode);
$domString = utf8_encode($dom->saveXML($element));
$product = new SimpleXMLElement($domString);
$awImage = $product->image;
//insert query
if(strlen($image) > 0)
{
$query = mysql_query("REPLACE INTO productfeed
(image)
VALUES ('$awImage')");
echo $awImage . "has been inserted </br>";
}
break;
}
}
?>
-
Thanks that great, the tutorial Im using is using an external link which is what I was trying to but use a link on my server.
Thanks for all this, I shall give it a bash tonight. Having error messages will help alot.
I only have a few lines in the XML file to test it.
-
Thanks, how do I go about doing that?
I just thought I use the errors loading the page gives me.
Ive spent 5 hours on this today, Im shocked its so difficult to read a file on your own server. No wonder 90% of what I have read just say to open allow_url_ lol
-
Im sorry but I dont understand what you mean.
Do I need to add something to my code to identify and error?
-
Thanks alot, I see now. This is the script I am using. Its behaving very strangely by deleting the contents of the XML feed each time I run it. Its also comes up with an error for this "while ($xmlReader->read())" However I seen on plenty of sites so it must be a proper piece of code.
Do you have any advice on how to improve and get this code working?
$xmlReader = new XMLReader();
$filename = "datafeed_98057.xml";
include $_SERVER['DOCUMENT_ROOT'] . '/productfeed/datafeed_98057.xml';
file_put_contents($filename, file_get_contents($url));
$xmlReader->open($filename);
while ($xmlReader->read())
{
switch ($xmlReader->name)
{
case 'product':
$dom = new DOMDocument();
$domNode = $xmlReader->expand();
$element = $dom->appendChild($domMode);
$domString = utf8_encode($dom->saveXML($element));
$product = new SimpleXMLElement($domString);
$awImage = $product->image;
//insert query
if(strlen($image) > 0)
{
$query = mysql_query("REPLACE INTO productfeed
(image)
VALUES ('$awImage')");
echo $awImage . "has been inserted </br>";
}
break;
}
}
?>
-
Hi,
I have got it reading the document without having it on. As per this page: http://www.learnphponline.com/errors/url-file-access-is-disabled-in-the-server-configuration
I dont understand, if the designers of PHP set a default off for security reasons why would you switch it on?
-
Hi,
I am trying to update a MySQL database from an XML feed saved on my server.
If the default is changed to off to improve security why is it best to change it to on?
Limiting String Print
in PHP Coding Help
Posted
Brilliant, thanks guys. I tried the following code and it limits it just two so I know it works:
I am concerned now that from your comments that this is an inneficient way of echoing date from my database. Can you advise it is iniffient. I take it I am trying to do a loop instead of just publishing the data.