ReeceSayer Posted January 7, 2012 Share Posted January 7, 2012 Hi guys, I'm currently in the process of making a simple social networking type site for a uni project and have basically everything i want except the ability to use AJAX to link to my profiles in the search bar. I have this code to generate my XML: <?php // create simplexml object $xml = new SimpleXMLElement('<rss version="2.0"></rss>'); // add channel information $xml->addChild('channel'); $xml->channel->addChild('title', 'The Social Network'); $xml->channel->addChild('link', 'http://reecesayer.com/projects/template/XML/news.rss'); $xml->channel->addChild('description', 'example'); // query database for article data include("phpfunctions.php"); db_connect(); $link = "www.reecesayer.com/projects/template/testprofile.php?id="; $select='SELECT email, id FROM users'; $result = mysql_query($select) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { // add item element for each article $item = $xml->channel->addChild('item'); $item->addChild('email', $row['email']); $item->addChild('link', $row['id']); //I wanted to add a link before the $row['id'] } // save the xml to a file $xml->asXML('profiles.xml'); header ('Location: http://reecesayer.com/projects/template/XML/profiles.xml'); ?> I need to add a partial URL (http://reecesayer.com/projects/template/testprofile.php?id=) before the row is called so that when the email is searched it provides a link to the profile depending upon the id (http://reecesayer.com/projects/template/testprofile.php?id= Is there an easier way to do this or am i going the long way around? I'm only storing the data in XML as i saw a tutorial for a livesearch script on another site. Cheers, Reece Quote Link to comment https://forums.phpfreaks.com/topic/254560-creating-links-including-variables-simple-xml/ Share on other sites More sharing options...
trq Posted January 7, 2012 Share Posted January 7, 2012 Iv'e really got no idea what your doing but this will add the link to the id. $item->addChild('link', $link . $row['id']); You'll want to make sure that $link is a valid url though: $link = "http://reecesayer.com/projects/template/testprofile.php?id="; Quote Link to comment https://forums.phpfreaks.com/topic/254560-creating-links-including-variables-simple-xml/#findComment-1305365 Share on other sites More sharing options...
ReeceSayer Posted January 8, 2012 Author Share Posted January 8, 2012 Thanks a lot. The links will be valid as they'll point to the users profile id. I'll give it a try tomorrow when i'm back doing work. Thanks, Reece Quote Link to comment https://forums.phpfreaks.com/topic/254560-creating-links-including-variables-simple-xml/#findComment-1305501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.