PDA

View Full Version : Dynamic link


lux
04-12-2006, 07:48 PM
Hey,

At the moment i have created a dynamic table in which I have
created a link to another page which displays the full contents of a particular db record.

I would like to better control the links to the full descriptions
by only displaying a link for each of the db records where
all the columns have values (i.e. NOT NULL), or to put it the
other way; not show a link when the record contains null values.

If somebody could explain the logic behind how to do this and/or examples that would be really cool

Thanks

davidj
04-13-2006, 07:20 AM
is this asp or php

please say php

lux
04-13-2006, 09:45 AM
sorry, yeah its php, hehe

davidj
04-13-2006, 09:49 AM
please post your code from the dynamic table

lux
04-13-2006, 10:57 AM
$query_rs_reports = "SELECT * FROM tbl_reports ORDER BY `date` DESC";
$rs_reports = mysql_query($query_rs_reports, $conn_solentsuns) or die(mysql_error());
$row_rs_reports = mysql_fetch_assoc($rs_reports);
$totalRows_rs_reports = mysql_num_rows($rs_reports);
?>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Date</td>
<td>Opponent</td>
<td>H/A</td>
<td>Competition</td>
<td>W/L</td>
<td>Score</td>
<td>Report</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $readable_date=date("jS F Y", strtotime($row_rs_reports['date'])); ?></td>
<td><?php echo $row_rs_reports['opponent']; ?></td>
<td><?php echo $row_rs_reports['venue']; ?></td>
<td><?php echo $row_rs_reports['compName']; ?></td>
<td><?php echo $row_rs_reports['result']; ?></td>
<td><?php echo $row_rs_reports['score']; ?></td>
<td>go! (reportDetail.php?reportId=<?php echo $row_rs_reports['reportId']; ?>)</td>
</tr>
<?php } while ($row_rs_reports = mysql_fetch_assoc($rs_reports)); ?>
</table>

</p>


</p>


</p>


</p>


</p></td>
</tr>
</table>


thanks for your help

davidj
04-13-2006, 01:55 PM
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Date</td>
<td>Opponent</td>
<td>H/A</td>
<td>Competition</td>
<td>W/L</td>
<td>Score</td>
<td>Report</td>
</tr>
<?php do { ?>

<?php if ($row_rs_reports['date'] !='' && $row_rs_reports['opponent'] !='' && $row_rs_reports['venue'] !='' && $row_rs_reports['compName'] !='' && $row_rs_reports['result'] !='' && $row_rs_reports['score'] !='' && $row_rs_reports['reportId'] !='' ) {?>

<tr>
<td><?php echo $readable_date=date("jS F Y", strtotime($row_rs_reports['date'])); ?></td>
<td><?php echo $row_rs_reports['opponent']; ?></td>
<td><?php echo $row_rs_reports['venue']; ?></td>
<td><?php echo $row_rs_reports['compName']; ?></td>
<td><?php echo $row_rs_reports['result']; ?></td>
<td><?php echo $row_rs_reports['score']; ?></td>
<td>go! (reportDetail.php?reportId=<?php echo $row_rs_reports['reportId']; ?>)</td>
</tr>
<?php } ?>

<?php } while ($row_rs_reports = mysql_fetch_assoc($rs_reports)); ?>
</table>

lux
04-13-2006, 03:16 PM
Cool cool cool.
Thanks again for the help.

regards
lux8uk

joepages
04-17-2012, 03:16 PM
Hello! I'm trying to create a dynamic link that when users click at it the web site open a new window a show the corresponding text, the problem that I'm having is that I just did it but it only show me the las récord, and I want the récord corresponding to id selected.

I have one DB in mysql and two different tables, one that show titles (the link) and the other that shows cotent, I want that when user click in the title they see the content corresponding to another table in the same DB.

Here I post the entire code:

1st table (Title and content, the title should be the link to redirect to the corresponding article shown for its id_post)

<?php require_once('../Connections/check_mag.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}

mysql_select_db($database_check_mag, $check_mag);
$query_GetDisplay = "SELECT actualidad.title, actualidad.entry, actualidad.link, DATE_FORMAT(actualidad.updated, '%M %e, %Y') AS formatted, actualidad.post_id FROM actualidad ORDER BY actualidad.updated DESC LIMIT 4";
$GetDisplay = mysql_query($query_GetDisplay, $check_mag) or die(mysql_error());
$row_GetDisplay = mysql_fetch_assoc($GetDisplay);
$totalRows_GetDisplay = mysql_num_rows($GetDisplay);

mysql_select_db($database_check_mag, $check_mag);
$query_vinculo = "SELECT * FROM contenidoactualidad ORDER BY id_post ASC";
$vinculo = mysql_query($query_vinculo, $check_mag) or die(mysql_error());
$row_vinculo = mysql_fetch_assoc($vinculo);
$totalRows_vinculo = mysql_num_rows($vinculo);
?>
<!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="selector/menu/menu_style.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--


</style>
</head>

<body>
<div class="menu">
<ul>
<li><a id="current" href="actualidad.php" target="_self" >Actualidad</a>
</li>
<li><a href="recomendados.php" target="_self" >Recomendados</a>
</li>
</ul>
</div>
<div id="cuerpo_actualidad">
<?php do { ?>
<a href="../web/actualidad/actualidad.php?id_post=<?php echo $row_vinculo['id_post']; ?>" target="_blank"><?php echo $row_GetDisplay['title']; ?></a>
<p><?php echo $row_GetDisplay['formatted']; ?></p>
<h6><?php echo $row_GetDisplay['entry']; ?></h6>

<?php } while ($row_GetDisplay = mysql_fetch_assoc($GetDisplay)); ?>
</div>
</body>
</html>
<?php
mysql_free_result($GetDisplay);

mysql_free_result($vinculo);
?>


2nd Table. (where I want to show the content corresponding by ip_post from te last table)

<?php require_once('../../Connections/check_mag.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}

$colname_diplayingMain = "-1";
if (isset($_GET['id_post'])) {
$colname_diplayingMain = $_GET['id_post'];
}
mysql_select_db($database_check_mag, $check_mag);
$query_diplayingMain = sprintf("SELECT * FROM contenidoactualidad WHERE id_post = %s", GetSQLValueString($colname_diplayingMain, "int"));
$diplayingMain = mysql_query($query_diplayingMain, $check_mag) or die(mysql_error());
$row_diplayingMain = mysql_fetch_assoc($diplayingMain);
$totalRows_diplayingMain = mysql_num_rows($diplayingMain);
?>
<!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><?php echo $row_diplayingMain['titulox']; ?> .:. <?php echo $row_diplayingMain['fecha']; ?></title>
<link href="../../includes/styles/cuerpo.css" rel="stylesheet" type="text/css" />
<link href="../../includes/styles/registro1.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#foto1 {
position:absolute;
width:224px;
height:214px;
z-index:3;
left: -234px;
top: 0px;
text-align: center;
}
#foto2 {
position:absolute;
width:80px;
height:105px;
z-index:1;
left: 271px;
top: 0;
text-align: center;
}

#foto3 {
position:absolute;
width:80px;
height:105px;
z-index:3;
left: -90px;
top: 0px;
text-align: center;
}

#foto4 {
position:absolute;
width:80px;
height:105px;
z-index:1;
left: 271px;
top: 0;
text-align: center;
}

#foto5 {
position:absolute;
width:80px;
height:105px;
z-index:3;
left: -90px;
top: 0px;
}

#foto6 {
position:absolute;
width:80px;
height:105px;
z-index:1;
left: 271px;
top: 0;
}


-->
</style>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onload="MM_preloadImages('../../images/upla.gif','../../images/idu.gif')">
<div class="body">
<div class="cabecera">
<div class="cabecera_foto1">
</div>
<div class="cabecera_foto2">
</div>
<div class="cabecera_foto3">
</div>
<div class="logo">
<div id="PV"></div>
<div id="sol_cabecera"><img src="../../images/sol_candidato.gif" width="90" height="76" /></div>
</div>
</div>
<div class="menu">
<ul>
<li><a href="../../templates/inicio.html" target="_self" >Inicio</a></li>
<li><a href="" target="_self" >Proyecto Venezuela</a>
<ul>
<li><a href="../../templates/bienvenida.html" target="_self">Bienvenida</a></li>
<li><a href="../../descargas/estatutos.pdf" target="_blank">Estatutos</a></li>
<li><a href="../../templates/historia.html" target="_self">Historia</a></li>
<li><a href="../../templates/organizacion.html" target="_self">Organización y Estructura</a></li>
</ul>
</li>
<li><a href="" target="_self" >Cauce para una causa</a>
<ul>
<li><a href="../../templates/introduccion.html" target="_self">Introducción</a></li>
<li><a href="../../templates/vzlaposible.html" target="_self">La Venezuela Posible</a></li>
<li><a href="../sol.html" target="_self">El Sol de la Esperanza</a></li>
<li><a href="../musica.html" target="_self">Música de la Alegría</a></li>
</ul>
</li>
<li><a href="" target="_self" >Líderes</a>
<ul>
<li><a href="../../templates/autoridades.html" target="_self">Nuestras Autoridades</a></li>
<li><a href="../../templates/cargos.html" target="_self">Cargos de Representación</a></li>
<li><a href="../../templates/hsr.html" target="_self">Henrique Salas-Romer</a></li>
</ul>
</li>
<li><a href="" target="_self" >Noticias</a>
<ul>
<li><a href="../nacionales.html" target="_self">Nacionales</a></li>
<li><a href="../Internacionales.html" target="_self">Internacionales</a></li>
<li><a href="../prensaPV.html" target="_self">Prensa Proyecto Venezuela</a></li>
</ul>
</li>
<li><a href="" target="_self" >Voluntarios</a>
<ul>
<li><a href="../perfil.html" target="_self">Perfil del Voluntario</a></li>
<li><a href="" target="_self">Incribete</a></li>

</ul>
</li>
<li><a href="" target="_self" >Nuevas Generaciones</a></li>
<li><a href="" target="_self" >Venezuela Tricolor</a></li>
<li><a href="" target="_self" >Multimedia</a>
<ul>
<li><a href="" target="_self">Videos</a></li>
<li><a href="" target="_self">Fotos</a></li>
</ul>
</li>
</ul>
</div>
<div class="barra_derecha">
<div class="registro">
<form name="registro1" action="../../templates/insertar_datos.php" method="post">
<fieldset id="forma1">
<legend>Registro</legend>
<label>Nombre y Apellido: </label>
<input name="nombre" type="text" id="nombre" size="30" /><br>
<label>Correo Electrónico: </label>
<input type="text" name="correo" size="30" /><br>
</legend>
<p align="center"><input type="submit" name="enviar" class="btn" value="enviar" /></p>

</fieldset>
</form>
</div>
<div class="twitter">
<script charset="utf-8" src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 30,
interval: 30000,
width: 250,
height: 217,
theme: {
shell: {
background: '#3a77d1',
color: '#ffffff'
},
tweets: {
background: '#ffffff',
color: '#000000',
links: '#40a8f7'
}
},
features: {
scrollbar: false,
loop: true,
live: true,
behavior: 'default'
}
}).render().setUser('JoseRPages').start();
</script>
</div>
<div class="facebook">
<!-- Facebook Badge START -->
<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FH enriqueFSalasRomer&amp;width=250&amp;height=290&amp;colorschem e=light&amp;show_faces=true&amp;border_color=%23000000&amp;str eam=false&amp;header=true&amp;appId=190145251836" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:252px; height:290px;" allowTransparency="true"></iframe>
<!-- Facebook Badge END -->
</div>
<div class="nube">
<center>
<iframe src="../tagscloud/tagcloud.html" width="216" height="240" frameborder="0" align="left" scrolling="no">
</iframe>
</center>
</div>
</div>

<div id="contenido">
<h1>Noticias</h1>
<p> </p>
<div class="caja_chica_1_1">
<div id="apDiv1_1">
<a><?php echo $row_diplayingMain['titulox']; ?></a>
</div>
<div id="apDiv2_1">
<p><?php echo $row_diplayingMain['descripcion']; ?></p>
</div>
<div id="foto1"><img />
<!--<img src="../../images/fotos noticias/capriles.presidente1.gif" width="143" height="214" />--></div>
</div>
<div id="apDiv13">
<p><br /><?php echo $row_diplayingMain['entradax']; ?>
<br /><br /></p>
</div>
<!-- -->
<!---->
<!---->
</div>
<div class="inferior">
<div id="facebook_inferior"><a href="http://www.facebook.com" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('facebook','','../../images/redes_sociales/facebook/facebook2.gif',1)"><img src="../../images/redes_sociales/facebook/facebook1.gif" name="facebook" width="40" height="40" border="0" id="facebook" /></a></div>
<div id="twitter_inferior"><a href="http://www.twitter.com" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('twitter','','../../images/redes_sociales/twitter/twitter2.gif',1)"><img src="../../images/redes_sociales/twitter/twitter_1.gif" name="twitter" width="40" height="40" border="0" id="twitter" /></a></div>
<div id="flickr_inferior"><a href="http://www.flickr.com" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','../../images/redes_sociales/flickr/flickr-2.gif',1)"><img src="../../images/redes_sociales/flickr/flickr-1.gif" name="Image4" width="40" height="40" border="0" id="Image4" /></a></div>
<div id="youtube_inferior">
<a href="http://www.youtube.com" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('youtube','','../../images/redes_sociales/youtube/youtube2.gif',1)"><img src="../../images/redes_sociales/youtube/youtube.gif" name="youtube" width="40" height="40" border="0" id="youtube" /></a>
</div>
<div id="upla_inferior"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('upla','','../../images/upla.gif',1)"><img src="../../images/upla-g.gif" name="upla" width="86" height="28" border="0" id="upla" /></a></div>
<div id="idu_inferior"><a href="http://www.idu.org" target="_blank" onmouseover="MM_swapImage('idu','','../../images/idu.gif',1)" onmouseout="MM_swapImgRestore()"><img src="../../images/idu-g.gif" name="idu" width="93" height="39" border="0" id="idu" /></a></div>
<div class="derechos_web">
<div id="declaracion_derechos">
<p>Desarrollado por Proyecto Venezuela <br>Av. Bolívar Norte, Torre Straros, Piso 9. 02002. Valencia, Carabobo.<br>
Venezuela</p>
</div>
</div>

</div>
</div>
</body>
</html>
<?php
mysql_free_result($diplayingMain);
?>


Thanks for any help possible!