Jump to content

Search the Community

Showing results for tags 'distinct'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 4 results

  1. Hello, Is there any Distinct function for php? an employee can have more than 1 form an employee have one and only one position in a form 1 form have only one and only one Evaluator 1 form include more than 1 questions (in this topic have 4 questions for each form) in this case, the forms, position,score and evaluator repeat 4 times due to there is 4 questions is a form. How to Distinct in to show only one time for forms, position,score and evaluator? Output: $sql = "SELECT EmpID,EmpName,FormName,Scoring,Position,addedBy FROM [Advisory_BoardDB].[dbo].[masterView] WHERE submissionStatus <> 'Draft' ORDER BY EmpName ASC,FormName ASC"; $stmt = sqlsrv_query($conn, $sql); $data = array(); while (list($eid, $ename, $fname,$score,$pos,$ab) = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) { if (!isset($data[$eid])) { // initialize array for employee $data[$eid] = array('emp' => $ename, 'total' => 0, 'items' => array()); } // accumulate item data $data[$eid]['items'][] = array('form' => $fname,'score' => $score,'position'=>$pos,'addby'=>$ab); $data[$eid]['total'] += $score; } $pcent20 = ceil(count($data)*20/100); //$pcent20 = ceil(count($data)*$finalPercentage); //uasort($data, function($a,$b){return $b['total']-$a['total'];}); uasort($data, function($a, $b) { $emp = $b['total'] - $a['total']; if($emp === 0) { return strcmp($a['emp'], $b['emp']); } return $emp; }); $data = array_slice($data, 0, $pcent20, true); //echo '<pre>',print_r($data, true),'</pre>'; // // Now output the array // echo <<<TABLE <table border="1" id="example"> <thead> <tr> <th>Employee ID</th> <th>Employee Name</th> <th>Grand Total</th> <th>Form</th> <th>Score</th> <th>Position</th> <th>Evaluator</th> </tr> <thead> TABLE; echo "<tbody>"; foreach ($data as $eid => $edata) { // how many items $numItems = count($edata['items']); echo "<tr> <td rowspan='$numItems'>$eid</td> <td rowspan='$numItems'>{$edata['emp']}</td> <td rowspan='$numItems'>{$edata['total']}</td>"; foreach ($edata['items'] as $k => $idata) { if ($k > 0) { echo "<tr class='hover-row'>"; } echo "<td>{$idata['form']}</td><td>{$idata['score']}</td><td>{$idata['position']}</td><td>{$idata['addby']}</td></tr>"; } } echo"</tbody>"; echo "</table>"; ?>
  2. Hi, I am trying to display week number in a drop down menu. I managed to display the numbers but not distinct. I´ve tried using array_unique but i´m not sure how to implement it. (below code shows how I tried to use array_unique. $sql="SELECT Date FROM maildata ORDER BY Date ASC"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $date_string = date($row['Date']); $week = array_unique($date_string); $options .="<option>". date("W", strtotime($week))."</option>"; ?> <SELECT name="week"> <OPTION VALUE="">Choose week <?=$options?> </SELECT>
  3. Hi there, I am trying to get images uploaded from a gallery to be organized under the author's id (displaying their name from the users table). I don't know if there are supposed to be different results (result1 result2 result3) either.... Thank you! Here is what the requirements are: $result1 = mysql_query("SELECT DISTINCT author_id FROM mugallery"); while ($row = mysql_fetch_array($result1)){ // nested query 1 { } // nested query 2 { } } // end outside query Inside this outside query, we will have 2 nested queries: 1. User data: One that uses the author_id from the mugallery table, and matches it to the user_id field of the users table. We can then retrieve first and last name of the author. • While we have the author name, create a <div> to contain them and echo out the name as a heading of sorts. 2. Gallery data: Another that retrieves all thumbnails from the gallery, but only WHERE the author_id matches the particular author in the current iteration of the loop from the outside query. Here is my code thus far: $result1 = mysql_query("SELECT DISTINCT author_id FROM mugallery"); while ($row = mysql_fetch_array($result1)){ $result2 = mysql_query("SELECT * FROM mugallery JOIN users ON mubdata.author_id = users.user_id "); while ($row = mysql_fetch_array($result2)){ $title = $row['title'] ; $description = $row['description']; $filename = $row['filename']; $imageid = $row['imageid']; $author_id = $row['author_id']; //echo $title . " | " .$description . " | " .$filename . " | " .$imageid; echo $author_id; }// end nested query 1 $result3 = mysql_query("SELECT * FROM mugallery WHERE author_id = !!!!! What to put here??!!!!!!!! "); while ($row = mysql_fetch_array($result3)){ $thisThumbHeader = " \n<div class=\"thumb\">"; $thisTitleToDisplay = "\n<div class=\"title\">$title</div>"; $titledescription = $title . ": " . $description; $thisImageCodePre = "<a href=\"display.php?imageid=$imageid\">"; $thisImageCode ="<img src=\"uploads/thumbs120/$filename\" /></a>"; $thisImageToDisplay = "\n<div class=\"image\">$thisImageCodePre$thisImageCode</div>"; $thisThumbFooter = " \n</div>"; $thisThumbToDisplay = $thisThumbHeader . $thisTitleToDisplay .$thisImageToDisplay.$thisDescriptionToDisplay .$thisThumbFooter ; echo $thisThumbToDisplay ; }// end nested query 2 } // end outside query
  4. Hi everyone, I've been wrapping my head around this problem and I was wondering if you could help me. I have the following three tables with example data: results_patterns =========================== name | medal -------- | ------------ James | Gold James | Silver James | Silver Paul | Gold Sam | Bronze Sarah | Silver results_sparring =========================== name | medal -------- | ------------ James | Bronze James | Bronze James | Bronze Paul | Silver Sam | Gold Sarah | Silver results_patterns =========================== name | medal -------- | ------------ James | Silver James | Silver James | Gold Paul | Gold Sam | Bronze Sarah | Silver There are other columns in the tables such as date, age, category etc but these are not necessary. The idea being that there can be duplicate medals and names in each table (due to different competition dates) I'm trying to get a medal count for each individual person, and produce an sql statement to get a result like this: results =========================== name | gold | silver | bronze ---------|----------|-----------|----------- James | 2 | 4 | 3 Paul | 2 | 1 | 0 Sam | 1 | 0 | 2 Sarah | 0 | 3 | 0 I hope it's clear what I'm after; I'll happily explain more if required. I've tried UNION ALL three tables for WHERE 'Gold' medals. I wanted to count how many gold medals per person but I failed at this stage. I was then going to perhaps JOINT LEFT this results with the same for each Silver and Bronze. But I have no idea how to go about it. Any help would be greatly appreciated as I'm a noob with MySQL. Thanks very much
×
×
  • 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.