Extract from DB to XML - php

I have made a website where users can choose some regions on Google Maps, and save them into a database with a name an a description. What I need now is to be able to take the saved entries from my DB and show them also to an android app I have made with google maps. I am new to all these and from my research I understand that I should extract my data from the DB to an XML file and then parse them on the phone. For doing the first part I should use the following code, if I am not mistaken:
SELECT column1, column2,..
FROM tablename
FOR XML PATH;
What I still dont get is where should I put that piece of code? In a new file? All by itself? And with that code the XML file will be created, or should I do something else too?
Thank you

Well since noone answered my question and I did find the solution I'll post it here.
The answer is via PHP, XMLWriter. There is a question here that helped but I wasnt able to find from the beginning since I didnt know what to search for.

Related

Need advice about making a forum with php

I am trying to create a forum on my page. I need some advice. I have MySQL database and I am able to to work with it. Yet as far as I can make is playing with POST. I mean on click submit a $_POST['submit']) becomes set and so on. Then connect to database, get info and display.This way of making a forum is bad, because it all happens on a single page. As far as I seen any other forum when entering one and so on has it's unique Uri (what comes after domain.com/) so you can simply send someone full url and they are in that thread (unlike if you play with $_POST['submit']).
Sorry if my question is not accurate and I am not asking to write me code. I just need someone to direct me to the right place and any advice would be helpful. Thanks !
Your question is difficult to understand, but I think you are confused about how data and pages are dynamic using GET/POST.
The URLS with different IDs are like an illusion. Really, its the same page, however the page is dynamically taking that ID from the URL, and using it to output certain data.
For example, say we habe the URL: www.example.com/show_thread.php?thread=3
The php would look like
if(isset($_GET['thread'])){
$data = $db>query("SELECT thread_title,thread_text FROM threads WHERE thread_id = $_GET['thread']");
print($data);
}
*Warning: do not use this exact code, it is an example, not secure, etc
Then the database would look like
thread_id thread_title thread_text
1 kngwihywoihwy kngwihywoihwykngwihywoihwy
2 vyfngoieyoiehyon ieonuwrtoi hunwrmt jirwyji
3 nuoaiefguneoihn eoithneiotheo
and the page would show
nuoaiefguneoihn eoithneiotheo
POSTing data is for sending it to the server, and doing something with it. Just like GET. However, GET is helpful for passing things around as they are accessible in links. Like this example.

Getting content from search box finding it in database

I know this is a broad question, but seriously.. I really couldnt find and answer for this, only the LIKE keyword that checks if it contains it..
I want to look for something in a db if it contains it, starts with it, or ends with it and by order by the most populaur result?
I have a search box in bootstrap and when the content is changed, an ajax request is sent for the new content..
It there a way to do this.
Using LIKE is nothing. Use full text search in mysql. There are disadvantages: myisam required, for char/varchar/text fields only. See more info here:
https://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
A great alternative is using a real search engine such as Elasticsearch, built on the top of Apache Lucene: fast, relevant, flexible, adaptable, works with json api. See more info here: https://www.elastic.co/products/elasticsearch

Pull facebook data xml

http://developers.facebook.com/docs/reference/rest/links.getStats/
Okay I have looked at the site above. but im still having some trouble.
I have formated what I need like this
http://api.facebook.com/restserver.php?method=links.getStats&urls=dogtags.com.com,http://www.petsmart.com
My only issue is I need this data to be picked by the zip code another words I only want to see how many likes are on the url http://www.petsmart.com in the zip code 66614. How can I add that variable to the xml data displaying
Thank you all help is greatly appreciated
You are using an outdated facebook API. I would recommend implementing:
http://developers.facebook.com/docs/reference/api/insights/
However, I do not believe there is any way to to look at data from a specific zip-code using the facebook insight API

PHP in URL to locate specific node in XML db

i'm totally new to XML, but am trying it out on a site of mine to iterate through a very easy db. what i can't figure out is how to post a link outside of the site to a specific node in the xml database. the site in question is (http://thenewsomething.com)
please forgive any obvious ignorance as this is my first attempt with xml. what i'd like to do is post a url elsewhere that will link to thenewsomething.com with one of the specific nodes. for instance, if i give each node an id, can i do something like
http://thenewsomething.com?id=5
? thanks for your help in advance!
Sure. In PHP, you can look at $_GET['id'] to read out the ID passed to your script by the URL. (Make sure you escape the input by using something like addslashes). If your script is called index.php and someone browses to index.php?id=5, you can do this:
<?php
$id = addslashes($_GET['id']);
#use code tailored to your specific database to fetch the node with this ID
#display it
?>
You can look into something like SimpleXML and XPath to search within your XML database. For a quick introduction to XPath, consider:
http://www.w3schools.com/xpath/xpath_syntax.asp
If you post details of your XML schema, we may be able to help more.

Tagging system similar to the one used in this site

i need to implement a tagging system looking exactly like the one we are using now. I'm new to the web developing so i'm having a few problems and i would like to start from an example but i can't find one.
In particular i would need the frontend part that, i suppose, parse an xml received from the server and print it like those cool squares with the tag in it. I don't need something exactly like this, an example of something similar would suffice.
why do you use or supposed this data to be sent as xml ? do u save it in xml in the begining ? i suppose you should save your data in database . and create a table for every unique tag and then create a bridge bettween the posts table and the tag table containing every post with every tag linked to it .
Have you looked at the Tag plugin by CakeDC? Might save you some time.

Categories