Jump to content

[SOLVED] SELECT DISTINCT


djdellux

Recommended Posts

SELECT DISTINCT has absolutely nothing to do with PHP, and everything to do with a SQL database. I suggest you ask in a database forum.

 

I have never used this option and i need to implement it into my new code to make sure that all categories are updated from the database..

 

any suggestions

I'd also ask you what you're trying to do, because nothing in your description suggests a need for using SELECT DISTINCT. For one, you're talking about updating.


sry mark.. let me be more descriptive for ya...i have 3 feilds that consist of employee tags. i need a way to continusly have my php code topopulate the feilds from the sqlite db. if a new employee is hired there code will not be in the search field. i need that to update when the prgm is opened..

is this a lil better  ;D

if you need any more info plz ask and here is the existing code for ya

 

 

 

<html>
<head>
<title>Loggin DB</title> 
</head>
<body>
<h1 align=left>Please enter search feilds:</h1>
<body bgcolor="#82CAFA">
<form method="get" action="loggin1.php">
Page: 
<select name="Page">
<option value="approve.php" >Approve</option> 
<option value="custquery" >CustQuery</option> 
<option value="slpnlogin">SlpnLogin</option>
</select>
User Code:
<select name="UserCode">
<option >T3</option>
<option >J9</option>
<option>BL</option>
<option >SC</option>
<option >MN</option>
<option >CA</option>
<option>MW</option>
<option >TJ</option>
<option >E2</option>
<option >D6</option>
<option >SS</option>
<option >R9</option>
<option >GL</option>
<option >MP</option>
<option >RW</option>
</select>
Start Date: 
<input type="text" name="time">
End Date:
<input type="text" name="time1">
<p><input name="submitted" type="submit" value="send"/></p></form>
<?php
$db = $_SERVER['DOCUMENT_ROOT']."/../data/log.db"; //connect to sql
$handle = sqlite_open($db);
$query = "SELECT DISTINCT * FROM log WHERE";
if(isset($_GET['submitted']) && $_GET["submitted"] == "send")// line check
{
if ($_GET["Page"] !="")
{	
	$query.=" page=\"" .$_GET["Page"]."\"";
}
if ($_GET["UserCode"] !="")
{
	$query.=" and userCode=\"" .$_GET["UserCode"]."\"";
}
if(isset($_GET["time"]))
{
		$stime = strtotime($_GET["time"]);
	$query.=" and time >='" .$stime."'";
}
if(isset($_GET["time1"]))
{
		$etime = strtotime($_GET["time1"]);
	$query.=" and time <='" .$etime."'";
}
}
echo $query;// show the result of the search
$result = sqlite_query($handle, $query);
$row = sqlite_fetch_array( $result );
echo "<style type='text/css'>
table {
border-width: 1px;
border-spacing:0px ;
border-style: double;
border-color: black;
border-collapse: separate;
background-color: #82CAFA;
}
table th {
border-width: 1px;
padding: 0px;
border-style: solid;
border-color: black;
background-color: #82CAFA;
}
table td {
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: black;
background-color: #82CAFA;
}
</style>
<table class='db'; cellspacing=\"0px\">";
while($row = sqlite_fetch_array($result)){
echo "  <tr>\n";
echo "    <td> $row[id]</td><td> $row

</td> <td>  $row[desc]   </td><td>  $row[userCode]  </td><td>  $row[codeType]  </td><td>". date( "Y-m-d", $row['time'])."</td><td>  $row[ipaddr]</td>\n";
echo "  </tr>\n";
}
echo "</table>";
?>
</html>

Well

SELECT DISTINCT UserCode 
  FROM log

Should return a list of all the user codes that have any entry in the log table.

 

 

<select name="UserCode">
<?php
$usercodeQuery = "SELECT DISTINCT usercode FROM log";
$usercodeResult = sqlite_query($handle, $usercodeQuery);
while($usercodeRow = sqlite_fetch_array($usercodeResult)){
   echo '<option >'.$usercodeRow['usercode'].'</option>';
}
?>
</select>

Mark I inserted the code at the top because i want the dropdown list to populate before anything else and i recieved some errors

 

Notice: Undefined variable: handle1 in c:\program files\Apache\htdocs\loggin1.php on line 3

 

Warning: sqlite_query() expects parameter 1 to be resource, string given in c:\program files\Apache\htdocs\loggin1.php on line 3

 

Warning: sqlite_fetch_array() expects parameter 1 to be resource, null given in c:\program files\Apache\htdocs\loggin1.php on line 4

...

dont know what to make of it...

 

 

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.