Lennart Ericson
asked on
Too much is printed.
Given the code below
<?php
$dag = $dagen_1a;
//echo "<tr>";
$cols = 0;
$rows = 0;
while ($dag <= $sista_vakt_dagen)
{
$dag2 = ($dag - 75000);
//Print date (first print column)
echo "<tr><td valign=\"top\" height=\"20px\" class=\"vaktvisning\"><str ong>".date ('Y-m-d',$ dag)."</st rong></td> ";
//------------------------ ---------- -----
$SQL1 = " SELECT * FROM medlem_vakt_test LEFT JOIN bryggplatser ON medlem_vakt_test.medlemsnr = bryggplatser.medlemsnr WHERE (medlem_vakt_test.dagkod1 between '$dag2' AND '$dag') OR (medlem_vakt_test.dagkod2 between '$dag2' AND '$dag') ORDER BY medlem_vakt_test.dag_bev1 ASC ";
$ret1 = mysql_query($SQL1);
if (!$ret1) { echo( mysql_error()); }
else {
while ($row = mysql_fetch_array($ret1)) {
$id = $row['id'];
$fornamn = $row["fornamn"];
$efternamn = $row["efternamn"];
$medlemsnr = $row['medlemsnr'];
$telnr = $row['telnr'];
$mobilnr = $row['mobilnr'];
$bryggplats = $row['bryggplatser.bryggpl ats'];
//Print mooring nr (second print column)
echo "<td><span class=\"style36\">$bryggpl ats</span> </td>";
//Print yacht owners' first name (third print column)
echo "<td><span class=\"style36\">$fornamn </td>";
//Print yacht owners' last name (fourth print column)
echo "<td><span class=\"style36\">$efterna mn</span>< /td>";
//Print yacht owners' telephone number (fifth print column)
echo "<td><span class=\"style36\">$telnr</ span></td> ";
//Print yacht owners' cell phone number (sixth print column)
echo "<td><span class=\"style36\">$mobilnr </span></t d>";
echo "</tr>";
}}
$dag = $dag + 60*60*24;
}
?>
The expected printout:
2011-05-08 62 Peter Taylor 0752-745041 0708-148319
2011-05-09 90 Sergio Gonzales 0738-990711 0708-990711
2011-05-10 91 Sergio Gonzales 0738-990711 0708-990711
2011-05-11 254 John Fitzgerald 0719-123456
This is how it is printed:
2011-05-08 62 Peter Taylor 7450410 0708-148319
2011-05-09 90 Sergio Gonzales 0738-990711 0738-990711
91 Sergio Gonzales 0738-990711 0738-990711
2011-05-10 90 Sergio Gonzales 0738-990711 0738-990711
91 Sergio Gonzales 0738-990711 0738-990711
2011-05-11 254 John Fitzgerald 0719-123456
When a name appears twice; i. e. on two dates, it comes up as doubles. That's not wanted.
How can I get it to print out the way I want it?
<?php
$dag = $dagen_1a;
//echo "<tr>";
$cols = 0;
$rows = 0;
while ($dag <= $sista_vakt_dagen)
{
$dag2 = ($dag - 75000);
//Print date (first print column)
echo "<tr><td valign=\"top\" height=\"20px\" class=\"vaktvisning\"><str
//------------------------
$SQL1 = " SELECT * FROM medlem_vakt_test LEFT JOIN bryggplatser ON medlem_vakt_test.medlemsnr
$ret1 = mysql_query($SQL1);
if (!$ret1) { echo( mysql_error()); }
else {
while ($row = mysql_fetch_array($ret1)) {
$id = $row['id'];
$fornamn = $row["fornamn"];
$efternamn = $row["efternamn"];
$medlemsnr = $row['medlemsnr'];
$telnr = $row['telnr'];
$mobilnr = $row['mobilnr'];
$bryggplats = $row['bryggplatser.bryggpl
//Print mooring nr (second print column)
echo "<td><span class=\"style36\">$bryggpl
//Print yacht owners' first name (third print column)
echo "<td><span class=\"style36\">$fornamn
//Print yacht owners' last name (fourth print column)
echo "<td><span class=\"style36\">$efterna
//Print yacht owners' telephone number (fifth print column)
echo "<td><span class=\"style36\">$telnr</
//Print yacht owners' cell phone number (sixth print column)
echo "<td><span class=\"style36\">$mobilnr
echo "</tr>";
}}
$dag = $dag + 60*60*24;
}
?>
The expected printout:
2011-05-08 62 Peter Taylor 0752-745041 0708-148319
2011-05-09 90 Sergio Gonzales 0738-990711 0708-990711
2011-05-10 91 Sergio Gonzales 0738-990711 0708-990711
2011-05-11 254 John Fitzgerald 0719-123456
This is how it is printed:
2011-05-08 62 Peter Taylor 7450410 0708-148319
2011-05-09 90 Sergio Gonzales 0738-990711 0738-990711
91 Sergio Gonzales 0738-990711 0738-990711
2011-05-10 90 Sergio Gonzales 0738-990711 0738-990711
91 Sergio Gonzales 0738-990711 0738-990711
2011-05-11 254 John Fitzgerald 0719-123456
When a name appears twice; i. e. on two dates, it comes up as doubles. That's not wanted.
How can I get it to print out the way I want it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
angelIII,
Thanks for your reply.
With this SQL sentence:
$SQL1 = " SELECT * FROM medlem_vakt_test LEFT JOIN bryggplatser ON medlem_vakt_test.medlemsnr = bryggplatser.medlemsnr WHERE (medlem_vakt_test.dagkod1 between '$dag2' AND '$dag') OR (medlem_vakt_test.dagkod2 between '$dag2' AND '$dag') GROUP BY medlem_vakt_test.dag_bev1, medlem_vakt_test.dag_bev2 ";
I get
2011-05-08 62 Peter Taylor 7450410 0708-148319
2011-05-09 90 Sergio Gonzales 0738-990711 0738-990711
2011-05-10 90 Sergio Gonzales 0738-990711 0738-990711
which is not wrong in itself, but I'd like to have the last line above like
2011-05-10 91 Sergio Gonzales 0738-990711 0738-990711
I. e. second column 91 instead of 90.
How could I achieve that?
Thanks for your reply.
With this SQL sentence:
$SQL1 = " SELECT * FROM medlem_vakt_test LEFT JOIN bryggplatser ON medlem_vakt_test.medlemsnr
I get
2011-05-08 62 Peter Taylor 7450410 0708-148319
2011-05-09 90 Sergio Gonzales 0738-990711 0738-990711
2011-05-10 90 Sergio Gonzales 0738-990711 0738-990711
which is not wrong in itself, but I'd like to have the last line above like
2011-05-10 91 Sergio Gonzales 0738-990711 0738-990711
I. e. second column 91 instead of 90.
How could I achieve that?
then you are grouping by the wrong columns, or not enough.
what column is that 90/91 coming from? add that to the group by ...
what column is that 90/91 coming from? add that to the group by ...
ASKER
The column 90/91 is coming from is bryggpltser.bryggplats
If I group by bryggpltser.bryggplats, I get this outprint:
2011-05-08 62 Peter Taylor7450410 0708-148319
2011-05-09 90 Sergio Gonzales 0738-990711 0738-990711
91 Sergio Gonzales 0738-990711 0738-990711
2011-05-10 90 Sergio Gonzales 0738-990711 0738-990711
91 Sergio Gonzales 0738-990711 0738-990711
It is repeated twice. Please, give me an advice.
If I group by bryggpltser.bryggplats, I get this outprint:
2011-05-08 62 Peter Taylor7450410 0708-148319
2011-05-09 90 Sergio Gonzales 0738-990711 0738-990711
91 Sergio Gonzales 0738-990711 0738-990711
2011-05-10 90 Sergio Gonzales 0738-990711 0738-990711
91 Sergio Gonzales 0738-990711 0738-990711
It is repeated twice. Please, give me an advice.
>Please, give me an advice.
well, actually, I gave you some advice in giving the link to the article which describes the issue in general.
you need to find why it is "duplicated", aka which of the columns in the group by you need to remove to avoid what you consider a duplicate.
well, actually, I gave you some advice in giving the link to the article which describes the issue in general.
you need to find why it is "duplicated", aka which of the columns in the group by you need to remove to avoid what you consider a duplicate.
ASKER
Thanks! Excellent article.
SELECT DISTINCT(COLUMN) FROM TABLE