SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to initiate a query by clicking on a link ?

    Is it possible to initiate a query by clicking on a link ?

    If I say I have A - B - C - D - E -F - ........
    And when clicked on (B) letter we got something like this,

    PHP Code:
    <?php

        $query 
    "SELECT nom FROM FrCandidat WHERE nom LIKE '".$alpha."'";

        
    $result mysql_query($query);

        if (
    mysql_num_rows($result) == 0) {
            echo 
    "Aucune fiche est associ&eacute; \xE0 cette lettre !";
        
        exit;
        
        }
        
    ?>
    So (B) is been asign to $alpha and the query select only name startin by B ???

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Yes, use $_GET to retrieve the link data.

    The links
    Code:
    <a href="?do=B">B</a>
    <a href="?do=C">C</a>
    The code
    PHP Code:
    $alpha $_GET['do'];
    $query "SELECT nom FROM FrCandidat WHERE nom LIKE '".$alpha."'"

        
    $result mysql_query($query); 

        if (
    mysql_num_rows($result) == 0) { 
            echo 
    "Aucune fiche est associ&eacute; \xE0 cette lettre !"
         
        exit; 
         
        } 
    Also you might want to look into SQL REGEXP for the sort clause.

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The final result is a bit more complex but it's not working!
    PHP Code:
        <p>Rercherche par nom de famille</p>
                
                    <?php
                    
    echo "<a href='?do=C'>C</a> D E F G H I J K L M N O P Q R S T U V W X Y Z<br/>";
                        
    $alpha $_GET['do'];            
                         
                        
    $query "SELECT nom FROM FrCandidat WHERE nom LIKE '".$alpha."'";
                    
                        
    $result mysql_query($query); 
    //                        if (mysql_num_rows($result) == 0) { 
    //                            echo "Aucune fiche est associ&eacute; \xE0 cette lettre !";
                                
    //                            }
                             
                                 
    while ($row mysql_fetch_array($result)) {

                                    
    $email $row['email'];
                                    
    $prenom $row['prenom'];
                                    
    $nom $row['nom'];
                                    
    $pict $row['pict'];
                                    
    $fullname $prenom .'<br /> '$nom;
                                    
                                    echo (
    '<div class="float">
                        <img class="photo" src='
    .$pict.' width="120" height="120" alt="Photo" /><br />
                        <a href="fiche1d.php?email='
    .urlencode($email).'">'.$fullname.'</a></div>');
                        
                        }
                    
                                exit; 
                                
                
                                  
                    
    ?>

  4. #4
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm try this query:
    PHP Code:
    $query "SELECT nom FROM FrCandidat WHERE nom LIKE '%$alpha'"
    Silly

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this supposed to be proccess all in the same page or should I call another PHP file.

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Try this
    PHP Code:
    <p>Rercherche par nom de famille</p> 
       <a href="?do=C">C</a> D E F G H I J K L M N O P Q R S T U V W X Y Z<br/> ?>         
                    <?php 
                       $alpha 
    $_GET['do'];             
                         
                        
    $query "SELECT nom FROM FrCandidat WHERE nom REGEXP "^['. $alpha. ']"";
                     
                        
    $result mysql_query($query); 
    //                        if (mysql_num_rows($result) == 0) { 
    //                            echo "Aucune fiche est associ&eacute; \xE0 cette lettre !"; 
                                 
    //                            } 
                              
                                 
    while ($row mysql_fetch_array($result)) { 

                                    
    $email $row['email']; 
                                    
    $prenom $row['prenom']; 
                                    
    $nom $row['nom']; 
                                    
    $pict $row['pict']; 
                                    
    $fullname $prenom .'<br /> '$nom
                                     
                                    echo (
    '<div class="float"> 
                        <img class="photo" src='
    .$pict.' width="120" height="120" alt="Photo" /><br /> 
                        <a href="fiche1d.php?email='
    .urlencode($email).'">'.$fullname.'</a></div>'); 
                         
                        } 
                     
                                exit; 
                                
                 
                                   
                    
    ?>
    It might just work!

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, it doesn't !

  8. #8
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to make a quick note, any incoming request data which is going into a database query, you should always cleanse. If it's an integer use the intval function on it, if it's a string use the addslashes function. Better yet in this instance it appears you have some sort of dictionary going on, so just check that the strlen of the request variable is no greater than 1

  9. #9
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by patlap
    Sorry, it doesn't !
    You know I read it doesnt work. But I dont see info on exactly how it isnt working. So what is actually happening when you click on a letter? Does it give you errors? does it show same order and not change anything?

    Silly

  10. #10
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's clearing the data on the page.
    No entries shows

  11. #11
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well try echoing out the query. So when you click a letter show the actual query it is doing. Verify it is passing the correct value.

    Silly

  12. #12
    SitePoint Addict phpster's Avatar
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is the error? saying it doesn't work doesn't tell me much...
    phpster

    I wish my computer would do what I want it to.
    Not what I tell it to do...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •