Top
Phpuniverset logo
 
930 banner

INDHOLD

Forside

Script libary

Job annoncer

Tips og Tricks

Konkurrence

Downloads

Dokumenter

Forum

Online udviklere


ARTIKLER

CSS

Diverse

E-handel / annoncer

Grafik

Html

Internet

Javascript

Linux

PHP/MySQL

Programmer

Flash

Søgemaskiner

Windows

C / C++


INFO

Information

Annoncering

Kontakt

Forside Forum PHP, mysql Ændring af script til query string

Ændring af script til query string


 

Ændring af script til query string

Senunits  

Hvis nu jeg gerne vil have lavet således at i stedet for at for-definere parent_id=131 er
det let at ændre til query string eks listen.php?parent_id=1&p=1, altså det jeg mener er
at jeg gerne vil have den dynamisk så jeg kan vælge parent_id ud fra frontenden. Se
koden forneden.

<?php 

//connection 

    
$username="xxxxxr";  

    
$password="xxxxx";  

    
$database="xxxxxxx";   

 

 

                             @
mysql_connect("localhost",$username,$password); 

                             @
mysql_select_db($database) or die("Unable to select
database"
); 

 

                             

                                                          function 
DB_Inhalt($table,
$Säule$end false

                                                                                       

                                                                                       {

                              

                                                                                      
$return_array null

                             

                                                          
//Brother         ink: 4, Laser:
101

                                                          
//Canon            ink: 249,
Laser654

                                                          
//Epson             ink: 878,
Laser2537

                                                          
//HP                            
                  
ink1139Laser2051

                                                          
//Lexmark        ink: 2234,
Laser2468

                                                          
//Xerox             ink: 2529,
Laser2530

                                                          
//Dell                          
                  
ink4184Laser4185

                                                          
//Samsung       ink: 4187,
Laser4188

                             

                             

 

                                                                                          
                         $sql 
"SELECT * FROM $table WHERE parent_id=131  ORDER BY
LENGTH(name), name asc 
$end"

                                                                                          
                         
$result mysql_query($sql); 

     

                                                                                       

                                                                                          
                         while(
$rows mysql_fetch_array($result))

                                                                                          
                         

                                                                                          
                                                      { 

                                                                                          
                         
$return_array[] = $rows[$Säule]; 

         

                                                                                          
                         }  

     

         

                                                                                      
return 
$return_array

                                                                                       } 

 

 

                                                                                      
$tableBAL "catalog_category_flat"

                                                                                      
$columnBAL =  "url_key"

     

                                                                                      
$tableTEL "catalog_category_flat"

                                                                                      
$columnTEL =  "name"

     

                                                          
//if ?p= is not set  

                                                          

                                                          
if($req $_REQUEST['p']);   

                                                          else 
$req 1;   

    

     

                                                                                      
$limitBAL $req 400 400;    

                                                                                      
$limit $limitBAL "," 400

   

                                                                                      
$inhaltBAL DB_Inhalt($tableBAL$columnBAL"LIMIT $limit");     

                                                                                      
$inhaltTEL DB_Inhalt($tableTEL$columnTEL"LIMIT $limit");

                                                                                       

                                                                                       

     

                                                          if(
count($inhaltBAL) > 1)    

                                                          

                                                          { 

                             print(
"<table border='0'>"); 

        

                                                                                      
for(
$i 0$i 50$i++)    

                                                          {

     

                                                          
printf("<tr>\n<td style='width:
200px'><a
href=/index.php/component/magebridge/webshop/udstodning/mtc/suzuki/%s>%s</a></td>"
,
$inhaltBAL[$i], $inhaltTEL[$i]); 

                                                          
printf("<td style='width:
200px'><a
href=/index.php/component/magebridge/webshop/udstodning/mtc/suzuki/%s>%s</a></td>"
,
$inhaltBAL[$i 50], $inhaltTEL[$i 50]);

                                                                                      
printf("<td style='width: 200px'><a
href=/index.php/component/magebridge/webshop/udstodning/mtc/suzuki/%s>%s</a></td>"
,
$inhaltBAL[$i 150], $inhaltTEL[$i 150]);                                              
                           

                                                                                      
printf("<td style='width: 200px'><a
href=/index.php/component/magebridge/webshop/udstodning/mtc/suzuki/%s>%s</a></td>\n</tr>"
,
$inhaltBAL[$i 200], $inhaltTEL[$i 250]); 

 

        } 

            

                                                          print(
"</table>"); 

                                                          

                                                                                      
echo
" Vælg en af siderne";

                                                          

                                                                                      
echo 
" <a href='$_SERVER[PHP_SELF]?p=1'>Første side</a>";

                                                                                      
echo 
" <a href='$_SERVER[PHP_SELF]?p=1'>1</a>";

                                                                                      
echo 
" <a href='$_SERVER[PHP_SELF]?p=2'>2</a>";

                                                                                      
echo 
" <a href='$_SERVER[PHP_SELF]?p=3'>3</a>";

                                                                                      
echo 
" <a href='$_SERVER[PHP_SELF]?p=4'>4</a>";

                                                                                          
                                                      

 

     

 

                             } 

     

                                                          else    

                             { 

        

                             echo 
"No rows found!"

                             echo 
" <a href='$_SERVER[PHP_SELF]?p=1'>Til forsiden</a>";

    }  

?>




Dato : 22.10.2010, 12:48

Visninger : 3384

Points : 150

 

Hej Senunits.

Jeg synes det er lidt svært at forstå, hvad det er du prøver på og vil. Både pga.
dårlig formulering og at koden stort set er ulæselig. Prøv at formulere dig bedre og
fremstille din kode ordentligt
til en anden gang, men nok om det. Så vidt jeg kan forstå vil du gerne have at dit
script er i stand til at modtage data igennem adresselinjen og det er ikke så svært
endda. :)

Alt du skal gøre er at benytte dig af GET-metoden. Via POST-metoden modtager scripts data
fra en HTTP-request hvorimod via GET-metoden modtager scripts data som du gerne vil have
det.
Lad mig vise dig et eksempel:

<?php
    
echo "<a href=\"" $_SERVER['PHP_SELF'] . "?parent_id=23\">Gå til</a>";
?>

<?php
    $pid 
$_GET['parent_id'];
    
$sql "SELECT * FROM " $table " WHERE parent_id=" $pid " ORDER BY LENGTH(name),
name asc " 
$end;
    
$result mysql_query($sql);
?>

Hvis dette ikke er hvad du søger efter så prøv, som sagt, at formulere dit problem lidt
bedre. ;)


Dato : 25.10.2010, 01:30

Svar af : Nicklas Smed  




Login for at skrive et indlg :



   Brugernavn

Password
 

+ Opret en ny Bruger, Klik her

+ Glemt brugernavn/password

 

Send Artikel/anmeldelse til: phpuni@phpuniverset.dk

Tilbage til oversigt

Phpuniverset's politik om personlige oplysninger, artikler & Koder Phpuniverset er optimeret til Mozilla 1024 * 768 Phpuniverset version: 3.0 beta
Webhost : Ignesco.dk

Bund