Jump to content

Adding mysql value to url


LegionSmith

Recommended Posts

Hi everyone,

 

I have what is probably a very simple question. I have written a php script that creates an rss feed from mysql database values. I have everything working now but I need to setup the link for each "posting". What I'm trying to do is take the user id (which is what the profile url is, i.e. www.mysite.com/123) and append it to the url.

 

Currently I have the base url (http://www.mysite.com) set as a variable and am trying to add $row['ID'] to it. $userid = $row['ID'];

 

But, so far everything I've tried to do hasn't worked. There is no form being submitted so I'm assuming I can't use _GET. This is just a feed script that pulls all the needed info from peoples profiles in the database. Any help would be appreciated.

 

Thanks,

Michael

Link to comment
https://forums.phpfreaks.com/topic/153693-adding-mysql-value-to-url/
Share on other sites

yeah, I had tried that. just tried it again. that doesn't work at all. here's a bigger snippet of my code. it's actually the entire function for the items portion of the xml file.

 

private function getItems()
{
	$itemsTable = "Profiles";
	$this->dbConnect($itemsTable);
	$query = "SELECT * FROM ". $itemsTable;
	$result = mysql_db_query (DB_NAME, $query, LINK);
	$items = '';

	while($row = mysql_fetch_array($result))
	{
		$text = $row['ListingDescription'];
		$title = $row['ListingTitle'];
	    $title2 = preg_replace(array('/</', '/>/', '/"/', '/&/'), array('<', '>', '"', '&'), $title);
		$text2 = preg_replace(array('/</', '/>/', '/"/', '/&/'), array('<', '>', '"', '&'), $text);
		$rsurl = 'http://www.mysite.com/';
                        $userid = $row['ID'];
		$link = rsurl ."". $userid;	
	               $items .= '<item>
					 <title>'. $title2 .'</title>
					 <link>'. $link .'</link>
					 <description>'. $text2 .'</description>
				 </item>';
	}
	$items .= '</channel>
			 </rss>';
	return $items;

 

Now, the variables $rsurl and $link are what I'm playing with at the moment. If I were to put $rsurl inside of the xml <link> tags then it works with the base url. But what I need is the base url plus the user id from the database for that particular person. We have a rewite rule script changing the url of the users profile from a long complex query to baseurl/user id. as in http://www.mysite.com/123.

 

I hope that makes more sense, I would have thought this would have been simple, and I've tried several things, but it seems that something with the xml standards prevent alot of the normal php operations. for example, you can't seem to "echo $var" inside an xml tag as you'll just get the word echo.

 

Thanks!

Michael

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.