Re: If statement duplicating mysql records?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Jun 20, 2007, at 10:56 AM, Daniel Brown wrote:

On 6/20/07, Jim Lucas <lists@xxxxxxxxx> wrote:
I would look at your result set and see if you had multiple lines
returned.  One person mentioned that you might be using a JOIN in you
SQL call.  This could lead to multiple lines.

Start investigating your SQL statement I would suggest.

   Actually, it looks like this is the system I started writing out
for him a week or two ago, and unless he changed the SQL queries,
there were no JOINs in there.

   Jason, just to be sure, can you include the SQL query being sent,
first with the PHP variables (if any), then with the actual translated
SQL?


Hey Jim,

You're right it is the system you helped me get started with, Just wanted to add a little color coding for the different levels :)

Here is the sql query:

$sql  = "SELECT * FROM tasks WHERE completed='0' order by id";
$sql .= " AND (day_of_week BETWEEN '0' AND '".$dow."')";

And if I understand what you are looking for:

$sql = "SELECT ALL from tasks where completed="NO" order by id and (Day_of_week between the start of the week and today)";

The code I had worked out, originally was something along the lines of:

if($row[5] =="Level1") (
echo "<TR><TD bgcolor=".$Level1.">$row[0] </td>";
	echo "<td bgcolor=".$Level1.">$row[1]  </td>";
	echo "<td bgcolor=".$Level1."><A href='$row[2]'>Instructions</A></td>";
echo "<TD bgcolor=".$Level1."><A href='update.php?taskid=$row [0]'>Click here!</A>";
}

if($row[5] =="Level2"){
	echo "<TR><TD bgcolor=".$Level2.">$row[0] </td>";
	echo "<td bgcolor=".$Level2.">$row[1]  </td>";
	echo "<td bgcolor=".$Level2."><A href='$row[2]'>Instructions</A></td>";
echo "<TD bgcolor=".$Level2."><A href='update.php?taskid=$row [0]'>Click here!</A>";

{
else
{
echo "<TR><TD bgcolor=".$unclassified.">$row[0] </td>";
	echo "<td bgcolor=".$unclassified.">$row[1]  </td>";
echo "<td bgcolor=".$unclassified."><A href='$row[2]'>Instructions</ A></td>"; echo "<TD bgcolor=".$unclassified."><A href='update.php?taskid=$row [0]'>Click here!</A>";

}

and what would happen is if $row[5] =="Level1" it would change the color to yellow, but then it would also display another line of the same info that would have the $unclassified color assigned to it.

What I have now though which Jim suggested is:

if ($row[5] =="Level1"){
	$rowColor = $Level1;
}

etc
 etc

echo "<TR><TD bgcolor=".$rowColor.">$row[0] </td>";
	echo "<td bgcolor=".$rowColor.">$row[1]  </td>";
echo "<td bgcolor=".$rowColor."><A href='$row[2]'>Instructions</A></ td>"; echo "<TD bgcolor=".$rowColor."><A href='update.php?taskid=$row [0]'>Click here!</A>";

	
which works great, I was just curious as to what was killing the original if statement and making it process the "else" statement when the "IF" matched...

	


   For example:

       $sql = "SELECT task_id FROM tasks WHERE
task_id='".$_POST['taskid']."' LIMIT 0,30;";

       "SELECT task_id FROM tasks WHERE task_id='24' LIMIT 0,30;"

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux