I'm not sure how easy it's going to be to explain this. I have a simple MySQL db - 1 table, 4 fields: id, co_name, fulltext and date_added. I've got a page which displays the contents of this table with the company name, and the first two sentences of the fulltext, sorted by date_added descending, so the newest shows first. So far so good. What I want to do is have a second page which will link from the first (with a "read more" sort of link after the two sentence intro) and will have the company name again, and the whole of the fulltext content. I've set up a page but can't work out how to code it so that when you click the link it shows the correct entry - I'm assuming that a variable of some sort which looks for the item's id is needed, but I'm a complete novice with PHP and can't see what I need to do be doing. For what it's worth, my test "results" page (the read more page) pulls the same entry from the table, regardless of which links you click.
The code for the first page is:
<?php require_once('Connections/offers.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;
}
}
mysql_select_db($database_offers, $offers);
$query_rsOffers = "SELECT * FROM show_off ORDER BY date_added DESC";
$rsOffers = mysql_query($query_rsOffers, $offers) or die(mysql_error());
$row_rsOffers = mysql_fetch_assoc($rsOffers);
$totalRows_rsOffers = mysql_num_rows($rsOffers);
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style6 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.style9 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #66cc33;
}
.style10 {color: #000000}
.style12 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #666666;
font-style: italic;
}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="get" action="">
<?php do { ?>
<table width="500" cellpadding="3">
<tr>
<td bgcolor="#66cc33" class="style9 style10"><?php echo $row_rsOffers['co_name']; ?></td>
</tr>
<tr>
<td><span class="style12"><?php echo $row_rsOffers['date_added']; ?></span></td>
</tr>
<tr>
<td class="style6"><?php echo extractFirst($row_rsOffers['fulltext']); ?> <a href="offers_full.php?id=<?php echo $row_rsOffersFullText['id']; ?>">more</a> </td>
</tr>
</table>
<?php } while ($row_rsOffers = mysql_fetch_assoc($rsOffers)); ?></form>
</body>
</html>
<?php
mysql_free_result($rsOffers);
function extractFirst($text,$num=1) {
// Create array of sentences using period as the divider
$sentences = explode('.',$text);
$extract = '';
if (count($sentences) > 1) {
// Rebuild, using number defined by $num, and adding period back in.
for ($i=0;$i<$num;$i++) {
$extract .= $sentences[$i].'.';
}
}
else {
$extract = $sentences[0].'.';
}
return $extract;
}?>
and the code for the second page is:
<?php require_once('Connections/offers.php'); ?>
<?php
$colname_rsoffersFullText = "-1";
if (isset($_GET['id'])) {
$colname_rsoffersFullText = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_offers, $offers);
$query_rsoffersFullText = sprintf("SELECT show_off.co_name, show_off.fulltext FROM show_off", $colname_rsoffersFullText);
$rsoffersFullText = mysql_query($query_rsoffersFullText, $offers) or die(mysql_error());
$row_rsoffersFullText = mysql_fetch_assoc($rsoffersFullText);
$totalRows_rsoffersFullText = mysql_num_rows($rsoffersFullText);
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style4 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #66cc33;
}
.style5 {color: #000000}
-->
</style>
</head>
<body>
<table width="500" cellpadding="3">
<tr>
<td bgcolor="#66cc33" class="style4 style5"><?php echo $row_rsoffersFullText['co_name']; ?></td>
</tr>
<tr>
<td class="style1"><?php echo nl2br($row_rsoffersFullText['fulltext']); ?></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class="style4"><a href="offers.php"><<Back</a></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsoffersFullText);
?>
I'd really appreciate any kind of help with this that you can offer, thanks in advance.
JMG