2017-10-12 7 views
-1

s'il vous plaît aidez-moi avec la liste suivante. Je ne sais pas où je fais une erreur.chaîne de requête dans l'URL et les conditions

Ma table:

year | distributor | item | nameautor 
1994 | Nike | Book | John 
1994 | Nike | Book | Peter 
1994 | Nike | DVD | Jessie 
1994 | Nike | DVD | Marc 
1995 | O2 | Book | Heck 
1995 | O2 | Book | Lars 
etc. 

Une liste complète de liens apparaît sur la page index.php

Exemple:

1994 Nike 
1995 O2 

Une fois que le lien (1994 Nike) est cliquée , il apparaît:

1994 Nike Book 
1994 Nike DVD 

Et la dernière étape est lorsque vous cliquez sur - 1994 Nike livre:

1994 Nike Book John 
1994 Nike Book Peter 

Je les codes suivants, et je ne sais pas comment les relier entre eux.

1. étape

<?php 
$query="(SELECT DISTINCT year, distributor FROM table)"; 
$back=mysql_query($query, $conn) or die(mysql_error()); 
while (list($year,$distributor) = mysql_fetch_row($back)){ 
    echo ("<a href=\"index.php?$year&$distributor\"><b></b>$year - $distributor</a></br>"); 
    } 
?> 

2. étape

<?php 
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { 
    $year = $_SERVER['QUERY_STRING']; 
    $distributor = $_SERVER['QUERY_STRING']; 
    $namechoose = str_replace(array('%20', '&'), ' ' , $_SERVER['QUERY_STRING']); 
    $query="(select distinct year, distributor, item FROM table WHERE CONCAT(year, ' ', distributor)='$namechoose')"; 
    $back=mysql_query($query, $conn) or die(mysql_error()); 
    echo ("<h3><center>you choose --- $namechoose ---</center></h3>"); 
    while (list($year,$distributor,$item) = mysql_fetch_row($back)){ 
     echo ("<a href=\"index.php?$year&$distributor&$item\"><b></b>$year - $distributor - $item</a></br>"); 
     } 
} 
?> 

La dernière étape

<?php 
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { 
    $year = $_SERVER['QUERY_STRING']; 
    $distributor = $_SERVER['QUERY_STRING']; 
    $item = $_SERVER['QUERY_STRING']; 
    $detailedtable = str_replace(array('%20', '&'), ' ' , $_SERVER['QUERY_STRING']); 
    $query="(select distinct year, distributor, item, nameautor FROM table WHERE CONCAT(year, ' ', distributor, ' ', item)='$detailedtable')"; 
     $back=mysql_query($query, $conn) or die(mysql_error()); 
    echo TABLE LISTING; 
} 
?> 

J'ai essayé cette structure, mais ça ne marche pas comme je le souhaite.

<?php 
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { 
    if (!isset($_GET['item'])) { 
      $year = $_SERVER['QUERY_STRING']; 
      $distributor = $_SERVER['QUERY_STRING']; 
      $namechoose = str_replace(array('%20', '&'), ' ' , $_SERVER['QUERY_STRING']); 
      $query="(select distinct year, distributor, item FROM table WHERE CONCAT(year, ' ', distributor)='$namechoose')"; 
      $back=mysql_query($query, $conn) or die(mysql_error()); 
      echo ("<h3><center>you choose --- $namechoose ---</center></h3>"); 
      while (list($year,$distributor,$item) = mysql_fetch_row($back)){ 
       echo ("<a href=\"index.php?$year&$distributor&$item\"><b></b>$year - $distributor - $item</a></br>"); 
       } 
    } else { 
      $year = $_SERVER['QUERY_STRING']; 
      $distributor = $_SERVER['QUERY_STRING']; 
      $item = $_SERVER['QUERY_STRING']; 
      $detailedtable = str_replace(array('%20', '&'), ' ' , $_SERVER['QUERY_STRING']); 
      $query="(select distinct year, distributor, item, nameautor FROM table WHERE CONCAT(year, ' ', distributor, ' ', item)='$detailedtable')"; 
       $back=mysql_query($query, $conn) or die(mysql_error()); 
      echo TABLE LISTING; 
     } 
    } 
else { 
    $query="(SELECT DISTINCT year, distributor FROM table)"; 
    $back=mysql_query($query, $conn) or die(mysql_error()); 
    while (list($year,$distributor) = mysql_fetch_row($back)){ 
     echo ("<a href=\"index.php?$year&$distributor\"><b></b>$year - $distributor</a></br>"); 
     } 
} 
?> 

Est-ce une mauvaise structure?

Merci pour vos commentaires.

+1

* "Est-ce une mauvaise structure?" * - Peut-être ou peut-être pas, mais l'API que vous utilisez est. –

+0

... ou peut-être que c'est vraiment la question? Votre URL doit être '' vous les accès via '$ _GET'. L'année étant dans '$ _GET ['année']'. – chris85

+0

où 'codeigniter' est utilisé ici? – Bira

Répondre

0

Nous vous remercions de l'aide.

J'ai modifié le code en utilisant

echo ("<a href=\"index.php?year=$year&distributor=$distributor&item=$item\"><b></b>$year - $distributor - $item</a></br>"); 

Et maintenant, il fonctionne comme il se doit.