PDA

View Full Version : Links via database


neonfluxx
11-18-2007, 06:57 PM
On the last post my question was about line spacing. This one is about links. How do i get links to show up fro the dB when it is displayed.

Thanks

domedia
11-18-2007, 07:50 PM
Do you have a separate field where you store the link?

neonfluxx
11-18-2007, 09:15 PM
No separate field. Simalar to here in the forum. If someone types a lin as part of their it shows up fine. thats what i want to accomplish.

davidj
11-19-2007, 07:44 AM
are you wanting to output a link / text wrapped in an <a> tag

neonfluxx
11-19-2007, 11:05 PM
I think so.

I will give you a explanation. When you type a post here in the forum and add a link this ----> www.google.com or and email like mike@google.com it shows up as a link you can click on. thats what i'm trying to accomplish.

davidj
11-20-2007, 08:21 AM
just add the tags to the database entry or keep the <a> tags on the page and populate the link text from the db

example 1...

in the table you can have the full link...

<a href="page.php">link text</a>

example 2

or have in the db...

page.php | text link

and then in the web page have this...

<a href="<?php echo $row['db_page_value']; ?>"><?php echo $row['db_link_text']; ?></a>

neonfluxx
11-20-2007, 04:41 PM
DJ i am posting the code as i am a little lost can you show me how that would work in here please


<?php require_once('../Connections/dbconfig.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_RSupdate = 10;
$pageNum_RSupdate = 0;
if (isset($_GET['pageNum_RSupdate'])) {
$pageNum_RSupdate = $_GET['pageNum_RSupdate'];
}
$startRow_RSupdate = $pageNum_RSupdate * $maxRows_RSupdate;

mysql_select_db($database_dbconfig, $dbconfig);
$query_RSupdate = "SELECT * FROM updates ORDER BY id DESC";
$query_limit_RSupdate = sprintf("%s LIMIT %d, %d", $query_RSupdate, $startRow_RSupdate, $maxRows_RSupdate);
$RSupdate = mysql_query($query_limit_RSupdate, $dbconfig) or die(mysql_error());
$row_RSupdate = mysql_fetch_assoc($RSupdate);

if (isset($_GET['totalRows_RSupdate'])) {
$totalRows_RSupdate = $_GET['totalRows_RSupdate'];
} else {
$all_RSupdate = mysql_query($query_RSupdate);
$totalRows_RSupdate = mysql_num_rows($all_RSupdate);
}
$totalPages_RSupdate = ceil($totalRows_RSupdate/$maxRows_RSupdate)-1;

$queryString_RSupdate = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_RSupdate") == false &&
stristr($param, "totalRows_RSupdate") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_RSupdate = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_RSupdate = sprintf("&totalRows_RSupdate=%d%s", $totalRows_RSupdate, $queryString_RSupdate);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="../css/frame.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php do { ?>
<table width="470" border="0" cellpadding="0" cellspacing="0" class="update-text" id="display">
<tr>
<td>&nbsp;</td>
<td width="35"><div align="center"><a href="add.php?recordID=<?php echo $row_RSupdate['id']; ?>"><img src="images/add.png" width="15" height="15" border="0" /></a></div></td>
<td width="35"><div align="center"><a href="edit.php?recordID=<?php echo $row_RSupdate['id']; ?>"><img src="images/check.png" width="15" height="15" border="0" /></a></div></td>
<td width="35"><div align="center"><a href="delete.php?recordID=<?php echo $row_RSupdate['id']; ?>"><img src="images/delete.png" width="15" height="15" border="0" /></a></div></td>
</tr>
<tr>
<td colspan="4"><?php echo $row_RSupdate['date']; ?> </td>
</tr>
<tr>
<td colspan="4">&nbsp;</td>
</tr>
<tr>
<td colspan="4"><?php echo $row_RSupdate['title']; ?></td>
</tr>
<tr>
<td colspan="4">&nbsp;</td>
</tr>
<tr>
<td colspan="4"><?php echo nl2br($row_RSupdate['update']); <------this is the infor i want to have the links ?></td>
</tr>
<tr>
<td colspan="4" class="line">&nbsp;</td>
</tr>
<tr>
<td colspan="4">&nbsp;</td>
</tr>
</table>
<?php } while ($row_RSupdate = mysql_fetch_assoc($RSupdate)); ?>
<p>&nbsp;</p>
<p>
<table width="470" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="400" border="0" align="center">
<tr>
<td><?php if ($pageNum_RSupdate > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_RSupdate=%d%s", $currentPage, 0, $queryString_RSupdate); ?>"><img src="../images/First.gif" border="0" /></a>
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_RSupdate > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_RSupdate=%d%s", $currentPage, max(0, $pageNum_RSupdate - 1), $queryString_RSupdate); ?>"><img src="../images/Previous.gif" border="0" /></a>
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_RSupdate < $totalPages_RSupdate) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_RSupdate=%d%s", $currentPage, min($totalPages_RSupdate, $pageNum_RSupdate + 1), $queryString_RSupdate); ?>"><img src="../images/Next.gif" border="0" /></a>
<?php } // Show if not last page ?>
</td>
<td><?php if ($pageNum_RSupdate < $totalPages_RSupdate) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_RSupdate=%d%s", $currentPage, $totalPages_RSupdate, $queryString_RSupdate); ?>"><img src="../images/Last.gif" border="0" /></a>
<?php } // Show if not last page ?>
</td>
</tr>
</table></td>
</tr>
</table>
<br />
Records <?php echo ($startRow_RSupdate + 1) ?> to <?php echo min($startRow_RSupdate + $maxRows_RSupdate, $totalRows_RSupdate) ?> of <?php echo $totalRows_RSupdate ?>
</p>
</body>
</html>
<?php
mysql_free_result($RSupdate);
?>

davidj
11-21-2007, 05:51 AM
<td colspan="4"><?php echo nl2br("<a href=\"page.php\">".$row_RSupdate['update'])."</a>"; ?></td>


drop DW code

neonfluxx
11-21-2007, 04:09 PM
DJ, is it better to hand code php. Is the DW code good or do you think DW code stinks. I am asking because I am training myself on this stuff and want to know what experienced coders think. Thanks for your answer to DJ. If you ever nee video help or 3D help let me know.

davidj
11-22-2007, 08:17 AM
you cant call your self a developer unless you can understand the language your developing in. If you rely on DW then you will get stuck

people have this "Oooo that looks way too hard" attitude. They are actually intimidated by the complexity of code. Remember what HTML looked like when you first fired up View Source from your browser... Scary stuff.

give my tuts a try and you will see how easy it is

neonfluxx
11-22-2007, 04:20 PM
DJ you are 100% correct. When i first looked at html code I was really nervous. But I went after it by learning code first. I never touched dreamweaver til many years later. I have been going about this all wrong. I have been relying on dreamweaver for my PHP when i should have done it the way I did HTML. So i will start watching those tuts tonight. I need to do this he right way. I totally see what you mean. I tried to find a way in dreamweaver to insert data into 2 tables at the same time and there is no way in dreamweaver. You have no choice but to hand code this. I'm beginning to se you are very limited bu what you can do with dreamweaver php. It is really for simple apps and nothing more unless you hand code there. Thanks for the in site and i will begin tonight. I did with HTML and CSS I will now do it with PHP. Thanks for your help DJ.