Jump to content

[SOLVED] this script is spilling into the next script


zhangy

Recommended Posts

Hello, the following code is giving me a bit of trouble. It is supposed to output tags associated with blog entries from a mysql database table. However it only seems to grab one of the tags out of the several that are in the table row. Not only that, but the text on the blog site immediately following this code's output is somehow turned into a link with the value of one of the tags that didn't get outputted.  :P

 

 

<?php
require_once('load_data.php');

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

$id = (int) $_GET['id']; 

$sql = "SELECT * FROM $table WHERE id=$id";
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
if(mysql_num_rows($result) == 1){
$row = mysql_fetch_array($result);

	echo 'Tags: ';
	$tags = $row['tags'];
	$tags_array = explode(",", $tags);

	foreach($tags_array as $value) {
	   $value = trim($value);
	   echo '<a href="mysite.com/tag.php?tag='.$value.'>'.$value ."</a><br />";
	}
}
?>

 

 

 

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.