Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: href not the same as echo

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default href not the same as echo

    i am reading from a dB
    Code:
    $query0 = "SELECT * FROM products WHERE productID='$prod' ";
    $result0 = mysql_query($query0) or die (mysql_error());
    $row0 = mysql_fetch_array($result0);
    
    $newid = $row0['id'];
    and when i echo out the "$newid" for testing it seems to work, but when i place it inside a href it takes a refresh click to have that variable change

    Code:
    <?php
    echo $newid;// for test
    
    echo"<a href='product.php?id=";
    echo $newid;//doesnt work
    echo"&prod=123'>";
    }
    ?>
    
    *the code has been truncated for easy reading
    Last edited by ggalan; 11-25-2010 at 04:29 AM.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    The following works for me:
    PHP Code:
    <?php
    $newid
    ='3';
    echo
    "<a href='product.php?id=";
    echo 
    $newid;
    echo
    "&prod=123'>hi</a>";
    ?>
    The following is better though:
    PHP Code:
    <?php
    $newid
    ='3';
    echo
    "<a href='product.php?id=$newid&amp;prod=123'>hi</a>";
    ?>
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    yeah when its simplified it works here too,
    wonder whats causing this delay reaction?

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    try running it with a dummy sql. For example replace your sql with $newid='3'; and see if it still works. If regular debugging does not work or you are stumped try posting more of your code here and we'll see what we can find.

    update: maybe it is a problem with your database. You could try running on a different databse and see if the error persists.
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #5
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    ok. i have been testing on localhost but will try it on a live server and compare results
    thanks for the help

  6. #6
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    same result
    heres the code, trimmed down to the basic

    when i view source on the browser, im noticing the "$newid" is placed in the href when its supposed to be up on the url. not sure if that makes sense

    PHP Code:
    <?php

    include("dbconnect.php");

    $prod $_GET['prod'];
    //$view = $_GET['view'];
    if ($view==null){$view='A';};

    $query0 "SELECT * FROM products WHERE productID='$prod'";
    $result0 mysql_query($query0) or die (mysql_error());
    $row0 mysql_fetch_array($result0);

    $item $row0['itemName'];
    $newid $row0['id'];
    $fabricName $row0['fabricName'];
    $str3 = ($row0['productID']);
    $str6 = ($row0['productID']);
    $three substr($prod03);
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="css/koza_main.css" rel="stylesheet" type="text/css" />
    <link href="css/koza_product.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="container">
    <?php
     
    if ($three == "RET") {
        echo 
    "<div id='productImgRetreat'><img src='assets/main_img/";
     } else {
        echo 
    "<div id='productImg'><img src='assets/main_img/";
     }
    echo 
    $view."_";
    echo 
    $row0['productID'];
    echo 
    ".jpg'/></div>";
    ?>
    <div id="productDescriptDiv">
    <?php
    echo $newid;// <<<<<<<<<<<<<for testing,  this number works

    $last substr($str3, -2);
    echo 
    "\n<div id='colorwayDiv'>\n<ul>\n";

    echo
    "<li><a href='product.php?id=$newid&prod=";//<<<<< need to press this 2x to get the href / url  to switch 

    echo substr($str606)."_dc";
    echo
    "'><img src='img/swatch/A_retreat.jpg' width='30' height='30' /></a></li>\n";

    echo
    "<li><a href='product.php?id=$newid&prod=";//<<<<< need to press this 2x to get the href / url  to switch 

    echo substr($str606)."_do";
    echo
    "'><img src='img/swatch/B_retreat.jpg' width='30' height='30' /></a></li>\n";

    echo
    "<li><a href='product.php?id=$newid&prod=";//<<<<< need to press this 2x to get the href / url  to switch 

    echo substr($str606)."_pc";
    echo
    "'><img src='img/swatch/C_retreat.jpg' width='30' height='30' /></a></li>\n";

    echo
    "<li><a href='product.php?id=$newid&prod=";//<<<<< need to press this 2x to get the href / url  to switch 

    echo substr($str606)."_po";
    echo
    "'><img src='img/swatch/D_retreat.jpg' width='30' height='30' /></a></li>\n";
    echo 
    "</ul>\n</div>\n";

    ?>
    </div>
    </div>
    </body>
    </html>
    Last edited by ggalan; 11-25-2010 at 04:07 AM.

  7. #7
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    I can't see what the problem is, when I go on that page I get "58" being output and then in the links, they've all got "58" in them as well. Unless I'm missing something?

    I get : product_demo.php?id=58&prod=RET004_dc

  8. #8
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    when you click on one of the thumbnails, the number above updates.
    this number should also update in the urls "id="
    but it takes a second click

  9. #9
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    product_demo.php?id=58&prod=RET004_do

    Outputs 58

    product_demo.php?id=58&prod=RET004_dc

    Outputs 57

    Haven't really looked at the code in depth, but that seems strange...

  10. #10
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    the url seems to have a delay of 1 click - updating

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
  •