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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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