How to choose a ID!?!

Discussion in 'PHP' started by jmansa, Dec 15, 2005.

  1. #1
    Can somebody please help me with this... I cant figure out how to make the ID stick with the $Link line...

    
    <?
    $queryPro = "select ID, Name from tabel where CID=".$rowCat["CID"];
    $resultPro = mysql_db_query($dbname, $queryPro);
    $numrowsPro = mysql_num_rows($resultPro);
    
    for ($j = 0; $j<$numrowsPro; $j++)
    {
    $rowPro = mysql_fetch_array($resultPro);
    $ProName = $rowPro["Name"];
    [B][COLOR="Red"]$Link = "index.php?ID=" ;[/COLOR][/B]
    ?>
    
    Code (markup):

     
    jmansa, Dec 15, 2005 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you mean add the ID to the link???

    $Link = "index.php?ID=$ProName" ;
    PHP:
     
    dave487, Dec 15, 2005 IP
  3. kniveswood

    kniveswood Well-Known Member

    Messages:
    764
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Or even:
    $Link = "index.php?ID=".$ProName;
    PHP:
     
    kniveswood, Dec 15, 2005 IP
  4. jmansa

    jmansa Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That allmost did the job, but... The outcome looks like this...

    index.php?ID=Peter Hill

    But on my page I got it to call for a ID.

    if (($_GET['ID']) && (is_numeric($_GET['ID']))) {
    $userid = $_GET['ID'];
    
    Code (markup):
    How do I fix that... Either ways are good...
     
    jmansa, Dec 15, 2005 IP
  5. Djohn

    Djohn Peon

    Messages:
    75
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    As I see it, you're looking to transfer the numerical ID (you're using 'is_numeric') and not the name of the user.

    Change the first part into
    
    $ProID = $rowPro["ID"];
    $Link = "index.php?ID=".$ProID;
    
    Code (markup):
    That should do the trick, if I understand your intentions correctly.
     
    Djohn, Dec 15, 2005 IP
  6. jmansa

    jmansa Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    See... I allready tryid that solution, but it doesn't seem to get the ID??? The link only gets "index.php?ID=". Any other sugestions?!?

    It's driving me crazy...
     
    jmansa, Dec 15, 2005 IP
  7. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Not sure what j represents but try this
    $Link = "index.php?ID=$j" ;
    PHP:
     
    dave487, Dec 15, 2005 IP
  8. jmansa

    jmansa Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How can I change it from being numeric to get the name instead?

     
    jmansa, Dec 15, 2005 IP
  9. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #9
    
    if ($_GET['ID']) {
    $userid = $_GET['ID'];
    }
    
    PHP:
     
    dave487, Dec 15, 2005 IP
  10. Djohn

    Djohn Peon

    Messages:
    75
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You'd have to take care of the space in the name first, if you want to transfer the name.

    Example
    In the first part
    
    $ProName = str_replace(" ", "%20", $rowPro["Name"]);
    
    PHP:
    Of course, you'd have to revert that if you want to use for comparison or echo'ing
    
    $userid = str_replace("%20", " ", $_GET['ID']);
    
    PHP:
    (You can obviously use any character you'd like in stead of %20)


    My first thought would be to check and see if the ID actually exists in the database, as I don't see any reason why it wouldn't be attached to the url...
     
    Djohn, Dec 15, 2005 IP
  11. jmansa

    jmansa Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    When I tryid the solution I only get "No user specified"? Any ideas...
     
    jmansa, Dec 16, 2005 IP
  12. Djohn

    Djohn Peon

    Messages:
    75
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Are you sure the code that is supposed to use '$userid' is set up to have the name and not the numerical ID?
    Is the name correctly placed in the url?
     
    Djohn, Dec 16, 2005 IP