budimir Posted August 12, 2008 Share Posted August 12, 2008 Hey guys I'm having a small problem, An ID is not working in the first query, but in second is working. Anyone see where the problem is, because I can't find it? <?php $id = $_GET["id"]; if (isset($year) && isset($month)){ $upit = "SELECT * FROM obilasci WHERE YEAR(datum) = '$year' AND MONTH(datum) = '$month' AND id='$id'"; $rezultat = mysql_query($upit) or die (mysql_error()); $num = mysql_num_rows($rezultat); $i = 0; while ($i < $num){ $id = mysql_result($rezultat,$i,"id"); $datum = mysql_result($rezultat,$i,"datum"); $upisao = mysql_result($rezultat,$i,"upisao"); $napomena = mysql_result($rezultat,$i,"napomena"); $napomena_id = mysql_result($rezultat,$i,"napomena_id"); $datum1 = date("d.m.Y",strtotime($datum)); $datum2 = date("Y",strtotime($datum)); echo " <tr> <form name= 'form1' action='pregled_obilazaka_obrisi.php' method='post'> <input type='hidden' name='id' value='$napomena_id'> <td height='20'><div align='left'><em></em>$datum1</div></td> <td width='122'><div align='left'>$napomena</td> <td width='85'>$upisao</td> <td width='43'><a href='pregled_obilazaka_obrisi.php?id=".$napomena_id."'>Obriši</a></td> </tr>"; ++$i; } } else { $upit = "SELECT * FROM obilasci WHERE id='$id' ORDER BY datum DESC"; $rezultat = mysql_query($upit); $num = mysql_num_rows($rezultat); $i = 0; while ($i < $num){ $id = mysql_result($rezultat,$i,"id"); $datum = mysql_result($rezultat,$i,"datum"); $upisao = mysql_result($rezultat,$i,"upisao"); $napomena = mysql_result($rezultat,$i,"napomena"); $napomena_id = mysql_result($rezultat,$i,"napomena_id"); $datum1 = date("d.m.Y",strtotime($datum)); $datum2 = date("Y",strtotime($datum)); echo " <tr> <form name= 'form1' action='pregled_obilazaka_obrisi.php' method='post'> <input type='hidden' name='id' value='$napomena_id'> <td height='20'><div align='left'><em></em>$datum1</div></td> <td width='122'><div align='left'>$napomena</td> <td width='85'>$upisao</td> <td width='43'><a href='pregled_obilazaka_obrisi.php?id=".$napomena_id."'>Obriši</a></td> </tr>"; ++$i; } } ?> P.S. Please don't comment the code, it's form the begining, when I started learning! Quote Link to comment https://forums.phpfreaks.com/topic/119379-solved-id-not-passed-to-if-statment/ Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 Where do you set $year and $month? And mysql_result is much, much slower than mysql_fetch_array()...why not just take the two minutes and fix it? Quote Link to comment https://forums.phpfreaks.com/topic/119379-solved-id-not-passed-to-if-statment/#findComment-614983 Share on other sites More sharing options...
budimir Posted August 12, 2008 Author Share Posted August 12, 2008 Here is where I'm getting $year and $month.. <?PHP $year = $_GET['year']; $month = $_GET['month']; ?> <table width="938" border = "0"> <tr> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2008<?PHP if ($month) echo "&month=$month" ?> ">2008</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2009<?PHP if ($month) echo "&month=$month" ?> ">2009</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2010<?PHP if ($month) echo "&month=$month" ?> ">2010</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2011<?PHP if ($month) echo "&month=$month" ?> ">2011</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2012<?PHP if ($month) echo "&month=$month" ?> ">2012</a></td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=01">Siječanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=02">Veljača</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=03">Ožujak</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=04">Travanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=05">Svibanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=06">Lipanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=07">Srpanj</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=08">Kolovoz</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=09">Rujan</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=10">Listopad</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=11">Studeni</a></td> <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?<?PHP if ($year) echo "year=$year" ?>&month=12">Prosinac</a></td> </tr> You are right, I will fix that code, but right now this is really bothering me... Quote Link to comment https://forums.phpfreaks.com/topic/119379-solved-id-not-passed-to-if-statment/#findComment-614984 Share on other sites More sharing options...
akitchin Posted August 12, 2008 Share Posted August 12, 2008 it's because you're echoing the year or month into the URL if it exists, but not the ID. thus, if ID is set in the URL, it gets obliterated the second you click a link to refine either by month or by year: <td bgcolor="#fafafa"><a href="pregled_obilazaka.php?year=2008<?PHP if ($month) echo "&month=$month"; if ($id) echo "&id=$id"; ?> ">2008</a></td> i would suggest you use a select box for these instead. Quote Link to comment https://forums.phpfreaks.com/topic/119379-solved-id-not-passed-to-if-statment/#findComment-615055 Share on other sites More sharing options...
budimir Posted August 13, 2008 Author Share Posted August 13, 2008 Thanks, I have an idea now. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/119379-solved-id-not-passed-to-if-statment/#findComment-615358 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.