no duplicate codes
Moderator: General Moderators
no duplicate codes
Hello,
is there a way i can not have duplicate recordes shown on a page? I can't do the unique key, because i need them to be duplicate for another reason, but i dont want to show them (the duplicates)
thank you in advance
is there a way i can not have duplicate recordes shown on a page? I can't do the unique key, because i need them to be duplicate for another reason, but i dont want to show them (the duplicates)
thank you in advance
I blieve you can use "SELECT DISTINCT" in your query
Here is a page: http://www.mysql.com/doc/en/DISTINCT_optimisation.html
Example
Here is a page: http://www.mysql.com/doc/en/DISTINCT_optimisation.html
Example
Code: Select all
SELECT DISTINCT * FROM tablename- mrvanjohnson
- Forum Contributor
- Posts: 137
- Joined: Wed May 28, 2003 11:38 am
- Location: San Diego, CA
im sorry, but i tried that and it didnt work (or better yet, im not writing it correctly)
table name= forum
column = question_title
now thats what i don't want to duplicate, when question_title is repeated
here's my code:
$query_forum = "SELECT * FROM forum ORDER BY `date` DESC";
can you please help me out........im very new at php coding
table name= forum
column = question_title
now thats what i don't want to duplicate, when question_title is repeated
here's my code:
$query_forum = "SELECT * FROM forum ORDER BY `date` DESC";
can you please help me out........im very new at php coding
it doesnt........i think this is the part of the code that'll help (or u might want everything ?)
Code: Select all
mysql_select_db($database_cnpa, $cnpa);
$query_forum = "SELECT DISTINCT * FROM forum ORDER BY `date` DESC";
$query_limit_forum = sprintf("%s LIMIT %d, %d", $query_forum, $startRow_forum, $maxRows_forum);
$forum = mysql_query($query_limit_forum, $cnpa) or die(mysql_error());
$row_forum = mysql_fetch_assoc($forum);
Last edited by grudz on Thu Dec 04, 2003 2:54 pm, edited 2 times in total.
here it is
Code: Select all
// *** Logout the current user.
$FF_Logout = $HTTP_SERVER_VARSї'PHP_SELF'] . "?FF_Logoutnow=1";
if (isset($HTTP_GET_VARSї'FF_Logoutnow']) && $HTTP_GET_VARSї'FF_Logoutnow']=="1") {
session_start();
session_unregister("MM_Username");
session_unregister("MM_UserAuthorization");
$FF_logoutRedirectPage = "content_privee.php";
// redirect with URL parameters (remove the "FF_Logoutnow" query param).
if ($FF_logoutRedirectPage == "") $FF_logoutRedirectPage = $HTTP_SERVER_VARSї'PHP_SELF'];
if (!strpos($FF_logoutRedirectPage, "?") && $HTTP_SERVER_VARSї'QUERY_STRING'] != "") {
$FF_newQS = "?";
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
if($key != "FF_Logoutnow"){
if (strlen($FF_newQS) > 1) $FF_newQS .= "&";
$FF_newQS .= $key . "=" . urlencode($val);
}
}
if (strlen($FF_newQS) > 1) $FF_logoutRedirectPage .= $FF_newQS;
}
header("Location: $FF_logoutRedirectPage");
exit;
}
?>
<?php require_once('Connections/cnpa.php'); ?>
<?php
$currentPage = $HTTP_SERVER_VARSї"PHP_SELF"];
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}
$editFormAction = $HTTP_SERVER_VARSї'PHP_SELF'];
if (isset($HTTP_SERVER_VARSї'QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARSї'QUERY_STRING'];
}
if ((isset($HTTP_POST_VARSї"MM_insert"])) && ($HTTP_POST_VARSї"MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO forum (name, `date`, question_title, question) VALUES (%s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARSї'name'], "text"),
GetSQLValueString($HTTP_POST_VARSї'date'], "text"),
GetSQLValueString($HTTP_POST_VARSї'question_title'], "text"),
GetSQLValueString($HTTP_POST_VARSї'question'], "text"));
mysql_select_db($database_cnpa, $cnpa);
$Result1 = mysql_query($insertSQL, $cnpa) or die(mysql_error());
$insertGoTo = "content_forum.php";
if (isset($HTTP_SERVER_VARSї'QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARSї'QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$MM_Username=$FF_valUsername;
session_register("MM_Username");
$maxRows_forum = 5;
$pageNum_forum = 0;
if (isset($HTTP_GET_VARSї'pageNum_forum'])) {
$pageNum_forum = $HTTP_GET_VARSї'pageNum_forum'];
}
$startRow_forum = $pageNum_forum * $maxRows_forum;
mysql_select_db($database_cnpa, $cnpa);
$query_forum = "SELECT DISTINCT * FROM forum ORDER BY `date` DESC";
$query_limit_forum = sprintf("%s LIMIT %d, %d", $query_forum, $startRow_forum, $maxRows_forum);
$forum = mysql_query($query_limit_forum, $cnpa) or die(mysql_error());
$row_forum = mysql_fetch_assoc($forum);
if (isset($HTTP_GET_VARSї'totalRows_forum'])) {
$totalRows_forum = $HTTP_GET_VARSї'totalRows_forum'];
} else {
$all_forum = mysql_query($query_forum);
$totalRows_forum = mysql_num_rows($all_forum);
}
$totalPages_forum = ceil($totalRows_forum/$maxRows_forum)-1;
mysql_select_db($database_cnpa, $cnpa);
$query_privee = "SELECT * FROM privee WHERE name="" . $HTTP_SESSION_VARSї'MM_Username'] . """;
$privee = mysql_query($query_privee, $cnpa) or die(mysql_error());
$row_privee = mysql_fetch_assoc($privee);
$totalRows_privee = mysql_num_rows($privee);
$maxRows_forum = 5;
$pageNum_forum = 0;
if (isset($HTTP_GET_VARSї'pageNum_forum'])) {
$pageNum_forum = $HTTP_GET_VARSї'pageNum_forum'];
}
$startRow_forum = $pageNum_forum * $maxRows_forum;
mysql_select_db($database_cnpa, $cnpa);
$query_forum = "SELECT DISTINCT * FROM forum ORDER BY `date` DESC";
$query_limit_forum = sprintf("%s LIMIT %d, %d", $query_forum, $startRow_forum, $maxRows_forum);
$forum = mysql_query($query_limit_forum, $cnpa) or die(mysql_error());
$row_forum = mysql_fetch_assoc($forum);
if (isset($HTTP_GET_VARSї'totalRows_forum'])) {
$totalRows_forum = $HTTP_GET_VARSї'totalRows_forum'];
} else {
$all_forum = mysql_query($query_forum);
$totalRows_forum = mysql_num_rows($all_forum);
}
$totalPages_forum = ceil($totalRows_forum/$maxRows_forum)-1;
$queryString_forum = "";
if (!empty($HTTP_SERVER_VARSї'QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARSї'QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_forum") == false &&
stristr($param, "totalRows_forum") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_forum = "&" . implode("&", $newParams);
}
}
$queryString_forum = sprintf("&totalRows_forum=%d%s", $totalRows_forum, $queryString_forum);
$MM_paramName = "";
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
// create the list of parameters which should not be maintained
$MM_removeList = "&index=";
if ($MM_paramName != "") $MM_removeList .= "&".strtolower($MM_paramName)."=";
$MM_keepURL="";
$MM_keepForm="";
$MM_keepBoth="";
$MM_keepNone="";
// add the URL parameters to the MM_keepURL string
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepURL .= "&".$key."=".urlencode($val);
}
}
// add the URL parameters to the MM_keepURL string
if(isset($HTTP_POST_VARS)){
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
$nextItem = "&".strtolower($key)."=";
if (!stristr($MM_removeList, $nextItem)) {
$MM_keepForm .= "&".$key."=".urlencode($val);
}
}
}
// create the Form + URL string and remove the intial '&' from each of the strings
$MM_keepBoth = $MM_keepURL."&".$MM_keepForm;
if (strlen($MM_keepBoth) > 0) $MM_keepBoth = substr($MM_keepBoth, 1);
if (strlen($MM_keepURL) > 0) $MM_keepURL = substr($MM_keepURL, 1);
if (strlen($MM_keepForm) > 0) $MM_keepForm = substr($MM_keepForm, 1);
?>-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC