-
Month events
I have registers in a mysql DB and I want to show them for months. I think I have a var like this:
PHP Code:
$id = "month(now())";
$sql = "select * from agenda_geral where agenda='desporto' and month = ".$id." and area_ID = 1 order by day" ;
But what I have to do for show the next or the previous month events in the same page without create a new??
-
Tried:
Code:
$sql = "select * from agenda_geral where agenda='desporto' and month = ".$id+1." and area_ID = 1 order by day" ;
?
-
But how can I change the month with links?
Example:
Code:
<p><a href="agend_desporto.php??????"> Previous </a> | <a href="agend_desporto.php??????"> Next </a></p>
-
Ah, I see.
Code:
$modifier = isset($_GET['modifier']) ? mysql_real_escape_string($_GET['modifier'], $conn) : 0;
$sql = "select * from agenda_geral where agenda='desporto' and month = ".$id+$modifier." and area_ID = 1 order by day";
... where $conn is the resource handler for the connection to the database (the return value of mysql_connect or _pconnect).
-
Sorry!! I don't understand!!!
What about the links?? What should I put for pass for the previous or for the next month like a calendar??
-
For a previous month:
Code:
agend_desporto.php?modifier=-1
For the next month:
Code:
agend_desporto.php?modifier=1
For a year ago:
Code:
agend_desporto.php?modifier=-12
For seven months from now:
Code:
agend_desporto.php?modifier=7
-
PHP Code:
$conn = mysql_connect(SERVER,DBUSER,DBPWD) or die ("Problemas na ligação MySQL");
$id = "month(now())";
$modifier = isset($_GET['modifier']) ? mysql_real_escape_string($_GET['modifier'], $conn) : 0;
$sql = "select * from agenda_geral where agenda='desporto' and month = ".($id+$modifier)." and area_ID = 1 order by day" ;
$queryl = query($sql) or die ("Query failed: " . mysql_error() . " Actual query: " . $sql);
echo ($id + $modifier);
The test echo below gives 1 when I click <a href="agend_desporto.php?modifier=1"> Previous </a> and -1 when I click <a href="agend_desporto.php?modifier=-1"> Previous </a>
Why doesn't gives the actual month minus or plus the modifier??
-
It´s fix.
But I have another question...how can I increment or decrement the var modifier for pass to others months like a calendar, when I click several times on a link?
-
That's impossible (or very difficult, at least). You'd have to modify the link.
-
At this moment I have:
Code:
<p>
<a href="agend_desporto.php?modifier=-1"> Anterior </a> |
<a href="agend_desporto.php?modifier=0"> Actual </a> |
<a href="agend_desporto.php?modifier=1"> Seguinte </a>
</p>
And I tried to do with months:
Code:
<p>
<a href="agend_desporto.php?modifier=-3"> <? //echo trata_month($arrl["month"]-3) ?> </a><br />
<a href="agend_desporto.php?modifier=-2"> <? //echo trata_month($arrl["month"]-2) ?> </a><br />
<a href="agend_desporto.php?modifier=-1"> <? //echo trata_month($arrl["month"]-1) ?> </a><br />
<a href="agend_desporto.php?modifier=0"> <? //echo trata_month($arrl["month"]) ?> </a><br />
<a href="agend_desporto.php?modifier=1"> <? //echo trata_month($arrl["month"]+1) ?> </a>
</p>
Code:
function trata_month($data)
{
switch ($data){
case 1:
$data = "Janeiro";
break;
case 2:
$data= "Fevereiro";
break;
case 3:
$data = "Março";
break;
case 4:
$data = "Abril";
break;
case 5:
$data = "Maio";
break;
case 6:
$data = "Junho";
break;
case 7:
$data = "Julho";
break;
case 8:
$data = "Agosto";
break;
case 9:
$data = "Setembro";
break;
case 10:
$data = "Outubro";
break;
case 11:
$data = "Novembro";
break;
case 12:
$data = "Dezembro";
break;
}
return $data;
}
When I do that some months modify or doesn't appear. Why?? What can I do correct this code?
-
Easier:
Code:
function trata_month($mes) {
$months = array("", "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");
return $months[$mes];
}
And:
Code:
<p>
<?php for($i=-3;$i<2;$i++) { ?>
<a href="agend_desporto.php?modifier=<?php echo($i); ?>"><?php echo(trata_month($arrl["month"]+$i)); ?></a><br />
<?php } ?>
</p>
-
I continue to have the same problems:
Example:
Load Page shows
Fevereiro
Março
Abril
Maio
Junho
When I press Maio shows:
Fevereiro
Março
Abril
Maio
Junho
When I press Junho :
Janeiro
Sometimes when I click a month, it not corresponds
-
Could you link to the page? And its source?
-
-
Then will you please do so? :)
-
Sorry but it's local and can´t link. Can I send the script to you??
-
Post it here, as an attachment.
-
1 Attachment(s)
Attachment 332
change extension to php to see better!!
-
Since I'm missing dados.php, functions.php and your database, that's a bit tricky.
How about those two files? And perhaps a mysqldump of that database?
-
2 Attachment(s)
Attachment 333
Attachment 334
I can´t give you dados.php but it only have DEFINES of mysql_connect
-
You never call mysql_select_db().
-
I put mysql_select_db() in agend_desporto.php and the result is the same one!!!! Any more idea??
-
Resume output:
http://10.0.0.9/cm-lousa.pt/2.0/agen...php?modifier=0
Fevereiro
Março
Abril
Maio
Junho
http://10.0.0.9/cm-lousa.pt/2.0/agen...hp?modifier=-1
Janeiro
Fevereiro
Março
Abril
Maio
In this case, if I click in Abril, it goes to Maio
If i click in Fevereiro, it goes to Março and shows:
Janeiro
Fevereiro
Março
Abril
and so on.
You understand the problem?!!
-
I see the problem, but I'm pretty much stumped. Maybe someone else can spot the problem -- I'm sure it's something simple.
-
I'd take a look, but the pages are timing out for me, sadly.
-
Yeah, me too. I had to reconstruct it on my desktop.
-
Ah. Fun, heh.
I've looked at this, and I'm confused. If you can't figure it out, I most likely can't, anyway.