Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Tech > [PHP] aiuto su uno script menu
Pages (2): [1] 2 »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
publi
.grande:maestro.

User info:
Registered: Jun 2002
Posts: 885 (0.10 al dì)
Location:
Corso:
Anno:
Time Online: 8 Days, 6:51:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
[PHP] aiuto su uno script menu

Ho un menu e mi serve che la voce del menu selezionata resti attiva.
Sto utilizzando PHP+CSS.
Il css è ok.
Per php sto usando questo script che funziona solo se nell'array come valore di $link metto nome.php, se invece ho un url del tipo nome.php?id=nomeid il link lo legge perchè mi apre la pagina, ma non mi attiva il css che resta su home (index.php), come mai?

PHP:

<?php 
// definisce l'array di pagine
$pagine = array ('Home' => 'index.php','Servizi' => 'index.php?id=servizi');
    
// per ogni elemento dell'array di pagine
foreach ($pagine as $text => $link) {

// se sono nella pagina linkata
echo '<font';
if  (
substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['
SCRIPT_NAME'
],'/')+1) == $link) {
// aggiunge la classe css
echo ' class="attivo">';
}

 
// inserisce link e testo
echo '<a href="' $link '">' $text '</a></font>';
}
?>

Last edited by publi on 14-01-2007 at 00:49

14-01-2007 00:46
Click Here to See the Profile for publi Click Here to See the Blog of publi Click here to Send publi a Private Message Visit publi's homepage! Find more posts by publi Add publi to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged


code:
if (substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER[' SCRIPT_NAME'],'/')+1) == $link)


Perché confronti il nome del file con l'url, che in $link contiene anche la stringa di query (quella dal "?" in poi).

Una soluzione potrebbe essere:
code:
if (basename($_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']) == $link)


Se ben ricordo QUERY_STRING comprende anche il "?", quindi dovrebbe funzionare :)

__________________
?

Last edited by yeah on 14-01-2007 at 17:42

14-01-2007 10:13
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
publi
.grande:maestro.

User info:
Registered: Jun 2002
Posts: 885 (0.10 al dì)
Location:
Corso:
Anno:
Time Online: 8 Days, 6:51:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

spe, nel tuo mancava una parentesi )

ma mi fa la stessa cosa della mia riga...:?

Last edited by publi on 14-01-2007 at 13:18

14-01-2007 13:05
Click Here to See the Profile for publi Click Here to See the Blog of publi Click here to Send publi a Private Message Visit publi's homepage! Find more posts by publi Add publi to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Hai ragione, l'ho corretto, grazie.

Allora stampa

code:
basename($_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']) $link substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER[' SCRIPT_NAME'],'/')+1)

E vediamo i risultati :)

__________________
?

14-01-2007 17:44
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
publi
.grande:maestro.

User info:
Registered: Jun 2002
Posts: 885 (0.10 al dì)
Location:
Corso:
Anno:
Time Online: 8 Days, 6:51:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Me la riscrivi correttamente?
Non ci capisco nulla li e l'ho riscritta cosi, ma non va.

PHP:

if (basename($_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'])
 substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['S
CRIPT_NAME'],'/')+1) == $link)

14-01-2007 18:31
Click Here to See the Profile for publi Click Here to See the Blog of publi Click here to Send publi a Private Message Visit publi's homepage! Find more posts by publi Add publi to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Aehm... no :) io ti ho riscritto l'if.
Sostituisci il mio codice al tuo.

__________________
?

14-01-2007 18:51
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
publi
.grande:maestro.

User info:
Registered: Jun 2002
Posts: 885 (0.10 al dì)
Location:
Corso:
Anno:
Time Online: 8 Days, 6:51:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

non funziona.

15-01-2007 09:33
Click Here to See the Profile for publi Click Here to See the Blog of publi Click here to Send publi a Private Message Visit publi's homepage! Find more posts by publi Add publi to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Fai così:

code:
echo basename($_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']).'<br />'; echo $link.'<br />'; echo substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['S CRIPT_NAME'],'/')+1).'<br />';

inseriscilo nel foreach e posta il risultato :)

Ma se la condizione non viene soddisfatta, non entrando quindi nell'if, "<font" non resta senza la ">"?

__________________
?

15-01-2007 11:12
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
publi
.grande:maestro.

User info:
Registered: Jun 2002
Posts: 885 (0.10 al dì)
Location:
Corso:
Anno:
Time Online: 8 Days, 6:51:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ora stampa questo

PHP:

index.php
florida/index.php
class="attivo">Home
index.php?id=servizi
florida/index.php
class="attivo">Servizi

15-01-2007 13:56
Click Here to See the Profile for publi Click Here to See the Blog of publi Click here to Send publi a Private Message Visit publi's homepage! Find more posts by publi Add publi to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Potresti ripostare tutto il codice insieme agli echo che ti ho fatto aggiungere? Giusto per avere la visione d'insieme :)

Comunque quel "florida/index.php" da dove spunta?

__________________
?

15-01-2007 14:06
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
publi
.grande:maestro.

User info:
Registered: Jun 2002
Posts: 885 (0.10 al dì)
Location:
Corso:
Anno:
Time Online: 8 Days, 6:51:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Florida è la cartella dove sta index.php

PHP:


<?php 
// definisce l'array di pagine
$pagine = array ('Home' => 'index.php','Servizi' => 'index.php?id=servizi');
        
// per ogni elemento dell'array di pagine
foreach ($pagine as $text => $link) {

// se sono nella pagina linkata
echo '<font';
echo 
basename($_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']).'<br />';
echo 
$link.'<br />';
echo   
substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['S

CRIPT_NAME'
],'/')+1).'<br />';

// if  (substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['
SCRIPT_NAME'],'/')+1) == $link) 
{
        
// aggiunge la classe appropriata
echo ' 
class="attivo">';
}
   
// inserisce link e testo
echo '
<a href="' . $link . '">' . $text . '</a></font>';
}

?>

15-01-2007 14:23
Click Here to See the Profile for publi Click Here to See the Blog of publi Click here to Send publi a Private Message Visit publi's homepage! Find more posts by publi Add publi to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Questa cosa ti stampa

code:
<?php $pagine = array ('Home' => 'index.php','Servizi' => 'index.php?id=servizi'); foreach ($pagine as $text => $link) { echo "basename(): "; echo basename($_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']).'<br />'; echo "link: "; echo $link.'<br />'; echo "substr(): "; echo substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['S CRIPT_NAME'],'/')+1).'<br />'; }

?

__________________
?

Last edited by yeah on 15-01-2007 at 14:41

15-01-2007 14:39
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
publi
.grande:maestro.

User info:
Registered: Jun 2002
Posts: 885 (0.10 al dì)
Location:
Corso:
Anno:
Time Online: 8 Days, 6:51:22 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

basename(): index.php
link: index.php
_SERVER: florida/index.php
class="attivo">Homebasename(): index.php
link: index.php?id=servizi
_SERVER: florida/index.php
class="attivo">Servizi

15-01-2007 14:42
Click Here to See the Profile for publi Click Here to See the Blog of publi Click here to Send publi a Private Message Visit publi's homepage! Find more posts by publi Add publi to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

C'è qualcosa che non va perché "class="attivo">Home" non dovrebbe comparire :-/

Strano che QUERY_STRING non produca nulla... ma per passare da una pagina all'altra usi link, suppongo? e "id" l'hai messo nei link? O meglio, la navigazione da una pagina all'altra funziona correttamente?

Dovrebbe, visto che, come hai scritto nel primo post, la pagina te la apre...

__________________
?

15-01-2007 14:48
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ok, ora dovrebbe funzionare, l'ho provato in locale

code:
<?php // definisce l'array di pagine $pagine = array ('Home' => 'index.php','Servizi' => 'index.php?id=servizi'); // per ogni elemento dell'array di pagine foreach ($pagine as $text => $link) { $thispage = basename($_SERVER['PHP_SELF']); if(!empty($_SERVER['QUERY_STRING'])) $thispage .= '?'.$_SERVER['QUERY_STRING']; echo $thispage; // se sono nella pagina linkata echo '<font'; if ($thispage == $link) { // aggiunge la classe css echo ' class="attivo">'; echo "(y)"; } else echo '>'; // inserisce link e testo echo '<a href="' . $link . '">' . $text . '</a></font><br />'; } ?>

Ho lasciato le righe di verifica ;)

__________________
?

Last edited by yeah on 15-01-2007 at 15:02

15-01-2007 15:00
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 17:15.    Post New Thread    Post A Reply
Pages (2): [1] 2 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.454 seconds (45.30% PHP - 54.70% MySQL) con 24 query.