Jump to content

Recommended Posts

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!  ;D

Link to comment
https://forums.phpfreaks.com/topic/119379-solved-id-not-passed-to-if-statment/
Share on other sites

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...

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.