-1

I have a problem with my code. if I use select * from $table it's all good but now with select distinct it shows me

Notice: Undefined index: L_code in /home/lab_users/web_tue25/web_pages/2014-12-09/stats03-04e.php on line 70

and it show the same for all the variables A/A etc.

Can anyone help me find my mistake(s)???

Thank you

<?php 


include_once "dbconnect.php";

$sql = "SELECT DISTINCT akexam = '2003-04.e' FROM $table ";
$result = $dblink->query($sql);

if ($result->num_rows !== 0)
    {
        echo '<table border="1" style="width:100%; border: 1px solid black; border-collapse:collapse; text-align: center;">
        <tr bgcolor= #787878>

        <th>A/A</th>
        <th>ak.εξαμ.</th>
        <th>L_code</th>
        <th>τ.ε</th>
        <th>ck</th>
        <th>rb</th>
        <th>L_descr</th>
        <th>ΔΗΛ</th>
        <th>ΣΥΜ</th>
        <th>a</th>
        <th>b</th>
        <th>c</th>
        <th>d</th>
        <th>e</th>
        <th>f</th>
        <th>ΣΥΝ</th>
        <th>ok</th>
        <th>ok%</th>

    </tr>';

while($row = $result->fetch_assoc()) 
{
echo '<tr bgcolor= purple>';
    if(strstr($row["L_code"],"241"))
    {           
        echo "<td style= text-align:left>".$row["A/A"]."</td>";
        echo "<td style= text-align:left>".$row["akexam"]."</td>";
        echo "<td style= text-align:left>".$row["L_code"]."</td>";
        echo "<td>".$row["te"]."</td>";
        echo "<td> <input type='checkbox' name= 'ch' value='1'></td>";
        echo "<td> <input type='radio' name='labs' value='1'></td>";
        echo "<td>".$row["L_descr"]."</td>";
        echo "<td style= text-align:right>".$row["dhl"]."</td>";
        echo "<td style= text-align:right>".$row["sym"]."</td>";
        echo "<td style= text-align:right>".$row["a"]."</td>";
        echo "<td style= text-align:right>".$row["b"]."</td>";
        echo "<td style= color:blue>".$row["c"]."</td>";
        echo "<td style= color:blue>".$row["d"]."</td>";
        echo "<td style= color:blue>".$row["e"]."</td>";
        echo "<td style= color:blue>".$row["f"]."</td>";
        echo "<td style= text-align:right>".$row["syn"]."</td>";
        echo "<td style= text-align:right>".$row["ok"]."</td>";
        echo "<td style= text-align:right>".$row["ok%"].'%';"</td>";
    }
    else
    {   
        echo '<tr bgcolor= baby blue>';

        echo "<td style= text-align:left>".$row["A/A"]."</td>";
        echo "<td style= text-align:left>".$row["akexam"]."</td>";
        echo "<td style= text-align:left>".$row["L_code"]."</td>";
        echo "<td>".$row["te"]."</td>";
        echo "<td> <input type='checkbox' name= 'ch' value='1'></td>";
        echo "<td> <input type='radio' name='theories' value='1'></td>";
        echo "<td>".$row["L_descr"]."</td>";
        echo "<td style= text-align:right>".$row["dhl"]."</td>";
        echo "<td style= text-align:right>".$row["sym"]."</td>";
        echo "<td style= text-align:right>".$row["a"]."</td>";
        echo "<td style= text-align:right>".$row["b"]."</td>";
        echo "<td style= color:blue>".$row["c"]."</td>";
        echo "<td style= color:blue>".$row["d"]."</td>";
        echo "<td style= color:blue>".$row["e"]."</td>";
        echo "<td style= color:blue>".$row["f"]."</td>";
        echo "<td style= text-align:right>".$row["syn"]."</td>";
        echo "<td style= text-align:right>".$row["ok"]."</td>";
        echo "<td style= text-align:right>".$row["ok%"].'%';"</td>";
    }


echo '</tr>';
}

echo '</table>';

} 
else 
{
echo "0 results";
}
Alex Szabo
  • 3,274
  • 2
  • 18
  • 30
N_Gorg
  • 1
  • Uhm... maybe because you don't select 'L_code' from database? Use `SELECT DISTINCT * FROM...` – Forien Dec 11 '14 at 12:06
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Matt Burrow Dec 11 '14 at 12:24

2 Answers2

0

Yuo have to change the query. if you select distinct akexam, you will found a list of different akexam values in the table. Your rows will be just $row["akexam"]

If you select distinct * you will select all the different rows in the table. It will look like a normal select but it will discard the rows that are identical (if you have a primary key in the table all the rows are different, i warn you).

So please provide an explanation of why you want to select distinct and i can give you more precise solution.

AndreaBogazzi
  • 14,323
  • 3
  • 38
  • 63
0

You have to select each column individually.

SELECT DISTINCT `akexam`, `L_code`, .... /*Fetch other columns*/
FROM   `table`
WHERE akexam = '2003-04.e'
MontrealDevOne
  • 1,034
  • 3
  • 17
  • 30