SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    St. Louis, MO
    Posts
    212
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing argument woes

    Hi,
    I am having a problem that I have been wrestling with for 2 solid days and it is driving me mad. I need another set of eyes to look at it.
    I simply have two functions. One that retrieves data from a database, and one that displays it. A link is clicked that passes a 'catid' in the querystring to another page with the following code.
    PHP Code:
    $links getLinks($_REQUEST['catid']);
    displayLinks($links); 
    Here is the code for the 2 functions
    PHP Code:
    function getLinks($catid)

      if(!
    $catid || $catid=="")
        return 
    false;
      
    $query "select * from links where catid='$catid'";
      
    $result = @mysql_query($query);
      if(!
    $result)
        return 
    false;
      
    $num_links = @mysql_num_rows($result);
      if(
    $num_links == 0)
         return 
    false;
      
    $result db_result_to_array($result);
      return 
    $result;

    and
    PHP Code:
    function displayLinks($links)
    {
      if(!
    is_array($links))
      {
        echo 
    '<br>No links currently available in this category<br>';
      }
      else
      {
        foreach(
    $links as $row)
        {
          
    $url 'show_links.php?linkid=' .($row['linkid']). ' target=content';
          
    $title $row["catname"];
          
    do_html_url($url$title);
        }
      }

    For whatever reason, I always get 'No links currently available in this category' when this is not the case. From what I can deduct, getLinks does not recognize 'catid'. You can clearly see the catid passed in the address bar and I can echo it out on the page.
    I use two almost identical functions to display the different categories of links (the links that pass the catid) and it works fine. The difference is that getLinks accepts the catid parameter.
    There is definitely not a problem with the query or the data either.
    I'd appreciate any input

  2. #2
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This I'm sure is obvious but have you checked for case sensitivity? Also what does your db_result_to_array() function look like?

  3. #3
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    St. Louis, MO
    Posts
    212
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Thanks for answering and no, case sensitivity is definitely not an issue. Here is the code for db_result_to_array. It converts an identifier into an array of results.
    PHP Code:
    function db_result_to_array($result)
    {
       
    $res_array = array();
       for(
    $count=0$row = @mysql_fetch_array($result); $count++)
       {
         
    $res_array[$count] = $row;
       }
       return 
    $res_array;

    BTW...I even tried to pass a number as a string directly
    PHP Code:
    [font=Courier][color=#0000cc]$links [/color][color=#006600]= [/color][color=#0000cc]getLinks[/color][color=#006600]([/color][color=#cc0000]'1'[/color][/font][font=Courier][color=#006600]);
    [/color][color=#0000cc]displayLinks[/color][color=#006600]([/color][color=#0000cc]$links[/color][color=#006600]);[/color][/font] 
    and still no dice.

  4. #4
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    St. Louis, MO
    Posts
    212
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why all that html shows up in my post. It can be ignored.

  5. #5
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can I have the do_html_url function?

  6. #6
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind I think I've got it. I think your code works so its probably a little problem like a mysql field not matching one of your queries or something like that. I added my own little corny error checking just to figure out where the break might be happening but it produced no errors.

    Here is the straight code with a "catid" assigned within this document just for brevity:
    PHP Code:
     <?php 
    function getLinks($catid)

    if(!
    $catid || $catid=="" ){
    echo 
    "CatID does not exist";
    return 
    false;
    }
    $query "select * from links where catid='$catid'";
    $result = @mysql_query($query);
    if(!
    $result){
    echo 
    "First Result check failed";
    return 
    false;
    }
    $num_links = @mysql_num_rows($result);
    if(
    $num_links == 0){
    echo 
    "There are no links";
    return 
    false;
    }
    $result db_result_to_array($result);
    return 
    $result;

    function 
    do_html_url ($url$title) {
    ?>
    <a href="<?=$url?>"><?=$title?></a> 
    <?
    }

    function 
    db_result_to_array($result)
    {
    $res_array = array();
    for(
    $count=0$row = @mysql_fetch_array($result); $count++)
    {
    $res_array[$count] = $row;
    }
    return 
    $res_array;


    function 
    displayLinks($links)
    {
    if(!
    is_array($links))
    {
    echo 
    '<br>No links currently available in this category<br>';
    }
    else
    {
    foreach(
    $links as $row)
    {
    $url 'show_links.php?linkid=' .($row['linkid']). ' target=content';
    $title $row["catname"];
    do_html_url($url$title);
    }
    }

    $catid '1';
    $links getLinks($catid);
    displayLinks($links);
    Here is the table structure I used:
    Code:
     #
    # Table structure for table `links`
    #
    CREATE TABLE links (
    linkid int(11) NOT NULL auto_increment,
    catid int(11) NOT NULL default '0',
    catname varchar(20) NOT NULL default '',
    PRIMARY KEY (linkid)
    ) TYPE=MyISAM;
    
    And here is a link just to show you it works

    http://www.heliocreative.com/index2.php

  7. #7
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    St. Louis, MO
    Posts
    212
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE='seanmayhew']I think your code works so its probably a little problem like a mysql field not matching one of your queries or something like that.[/QUOTE]

    Thats whats freaking me out. I get no errors. I have troubleshot this thing to death.

    Maybe I should sleep on it, even though I've done that already...hehe.

    I really appreciate your help.

  8. #8
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    St. Louis, MO
    Posts
    212
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've attached the files involved including the .sql file. Maybe the problem is buried there. The functions are so straightforward and very easy to understand.

    Thanks
    Attached Files Attached Files

  9. #9
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where are they attached?


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
  •