Results 1 to 6 of 6

Thread: whats wrong with this code?

  1. #1
    Join Date
    Nov 2004
    Posts
    1,822

    Default whats wrong with this code?

    Some of my listigns dont have websites. If they dont I have the default address : http://www.mysite.com/nosite.php added in the DB. This link will go to a page saying the site has no webpage etc. I want to display graphics depending on if the site has a webpage, if the do it will come up with a button saying "Visit Site" if not a button saying "No Website Available"

    I have the following code, but it ALWAYS comes out displaying the "yessite.jpg"

    I cannot see whats wrong with the logic. no site url is identical to what is stored in the database so it should work

    Code:
    $links_obj->url = $url;
    
    if ($url==("http://www.mysite.com/nosite.php")){ 
      $displaysite=("http://www.mysite.com/images/nosite.jpg");
    } else {
    $displaysite=("http://www.mysite.com/images/yessite.jpg");
    }

    the plan is to use
    <a href=<%url%>> <img src=<%displaysite%>border=0></a> to display if a site exists, and make a clickable button.

    Im sure this is a simple problem, im new to php. I try for an hour and then i post. thats my rule!!!

  2. #2
    Join Date
    Nov 2004
    Posts
    1,822

    Default

    ok if i declare $url = www.mysite.com/nosite.php it works. SO, the problem must be the way im getting the url fromt he database into the variable $url ... its obviously not working.

    Im actually using : $url = $links_obj->url

    not what i used in the first post... so how would i do it?

  3. #3
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    the following should work:

    Code:
    $url = $links_obj->url;
    
    if ($url=="http://www.mysite.com/nosite.php"){ 
      $displaysite=("http://www.mysite.com/images/nosite.jpg");
    } else {
    $displaysite=("http://www.mysite.com/images/yessite.jpg");
    }
    I'm not to sure about the value of
    Code:
    $url = $links_obj->url;
    whether its works depends on where you are at in the code.



    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  4. #4
    Join Date
    Nov 2004
    Posts
    1,822

    Default

    I did a few tests and the problem is that i cannot get the url fromt he database to do any comparing. Im using your hits mod I found in the forums (counts hits to the details page rather than external site) and adapted the way you did it, this works but im not sure if its the best way :

    Code:
    $query = "select url from $links_obj->table_name where link_id=$id";
    $result = $conn->Execute($query);
    $url = $result->Fields("url");
    
    if ($url=="http://www.mysite.com/nosite.php"){ 
      $displaysite=("http://www.mysite.com/nosite.jpg");
    } else {
    $displaysite=("http://www.mysite.com/yessite.jpg");
    }
    I dont really understand why it is necessary to query the database again once a query to :
    Code:
    select * from idx_link where id=$id
    has already happened, surely the url field is available... anyway it works now so im happy!!

  5. #5
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    Quote Originally Posted by inspireme
    ...anyway it works now so im happy!!
    I'm not sure which code it is that is working for you but if it works...

    depending on where you are at in the code, any one of these three could work:


    Code:
    $query = "select url from $links_obj->table_name where link_id=$id";
    Code:
    $query = "select url from $this->table_name where link_id=$id";
    Code:
    $query = "select url from idx_link where link_id=$id";
    I don't think the following will ever work since id is not a valid field name in the SQL table idx_link
    Quote Originally Posted by inspireme
    select * from idx_link where id=$id

    .
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  6. #6
    Join Date
    Nov 2004
    Posts
    1,822

    Default

    the database query was my short hand im using link_id really. I was just wondering why I needed to query the database again, because the indexu (unchanged code!) already selects everything from idx_link, therfore I should be able to get the url from the returned array...

    But as you said, its working so lets not worry about it !!

Similar Threads

  1. What is wrong with this ???
    By lanzabiz in forum v5.x
    Replies: 3
    Last Post: 05-27-2004, 01:17 AM
  2. <%hot_links%> code
    By persut in forum v5.x
    Replies: 4
    Last Post: 02-01-2004, 03:31 PM
  3. Inserting a PHP Code In the INDEX page !!!
    By althahabi in forum v5.x
    Replies: 1
    Last Post: 09-26-2003, 03:21 PM
  4. Adding code before and after a link
    By shanet in forum v5.x
    Replies: 7
    Last Post: 06-07-2003, 05:15 AM
  5. Wrong focus
    By ReeToric in forum v5.x
    Replies: 1
    Last Post: 09-26-2001, 07:45 AM

Posting Permissions

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