Jump to content

Creating Links & Including Variables Simple XML


ReeceSayer

Recommended Posts

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=8)

 

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

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=";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.