Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Zmienna w tworzeniu linku
rankor
post 1.05.2024, 11:24:06
Post #1





Grupa: Zarejestrowani
Postów: 15
Pomógł: 0
Dołączył: 15.09.2010

Ostrzeżenie: (0%)
-----


Chcę zrobić tak, że przychodząca zmienna ma wpływ na konstrukcję linku na stronie.

Najprościej tłumacząc wysyłam 3 osobom link

Osoba nr 1: https://www.stronka.pl/index.php?id=1
Osoba nr 2: https://www.stronka.pl/index.php?id=2
Osoba nr 3: https://www.stronka.pl/index.php?id=3

I osoby odwiedzające stronę przez ten link widzą stronę z buttonem o różnej konstrukcji linku.

Próbowałem tak:

<a href="https://www.stronka.pl/index.php?id=$id"><img src="https://www.stronka.pl/button.png"></a>

Jednak zmienna nie jest wstawiana do linku. W linku jest po prostu $id a nie wartość id
Oczywiście wcześniej wywołuję zmienną $id = $_REQUEST['id'];

Jak zrobić, żeby było dobrze ?
Go to the top of the page
+Quote Post
Salvation
post 1.05.2024, 13:34:06
Post #2





Grupa: Zarejestrowani
Postów: 357
Pomógł: 70
Dołączył: 15.07.2014

Ostrzeżenie: (0%)
-----


  1. $options = [
  2. 'default' => 0,
  3. 'min_range' => 0,
  4. 'max_range' => 999,
  5. ];
  6. $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT, ['options' => $options]);
  7. $link = sprintf('https://www.stronka.pl/index.php?id=%d', $id);
  8.  
  9. echo '<a href="'. $link .'"><img src="https://www.stronka.pl/button.png"></a>';

Demo: https://3v4l.org/D88TE
Go to the top of the page
+Quote Post
trueblue
post 1.05.2024, 18:44:44
Post #3





Grupa: Zarejestrowani
Postów: 6 762
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. echo "<a href=\"https://www.stronka.pl/index.php?id=$id\"><img src=\"https://www.stronka.pl/button.png\"></a>";
  2.  
  3. echo '<a href="https://www.stronka.pl/index.php?id='.$id.'"><img src="https://www.stronka.pl/button.png"></a>';



--------------------
Go to the top of the page
+Quote Post
Malinaa
post 3.05.2024, 09:29:28
Post #4





Grupa: Zarejestrowani
Postów: 528
Pomógł: 6
Dołączył: 21.07.2008

Ostrzeżenie: (0%)
-----


Cytat(rankor @ 1.05.2024, 12:24:06 ) *
Najprościej tłumacząc wysyłam 3 osobom link

Osoba nr 1: https://www.stronka.pl/index.php?id=1
Osoba nr 2: https://www.stronka.pl/index.php?id=2
Osoba nr 3: https://www.stronka.pl/index.php?id=3


Linki wysyłasz względnie poprawnie, więc może zostaw je bez zmian:
https://www.stronka.pl/index.php?id=1 itd.
natomiast po stronie PHP
$id = $_GET['id'];
i np. ifem, switchem, itp.
$html = '<button value="Button 1">';
if ($id == 2) $html = '<button value="Button 2">';
else if ($id == 3) $html = '<button value="Button 3">';
echo $html;

I osoby odwiedzające stronę przez wysłany link widzą stronę z różnym buttonem.


--------------------
I welcome you on the Internet >>> Design by Malina
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 15.05.2024 - 20:58