View Full Version : Resolved href not the same as echo
ggalan
11-24-2010, 05:52 PM
i am reading from a dB
$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
<?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
james438
11-24-2010, 06:06 PM
The following works for me:
<?php
$newid='3';
echo"<a href='product.php?id=";
echo $newid;
echo"&prod=123'>hi</a>";
?>
The following is better though:
<?php
$newid='3';
echo"<a href='product.php?id=$newid&prod=123'>hi</a>";
?>
ggalan
11-24-2010, 06:12 PM
yeah when its simplified it works here too,
wonder whats causing this delay reaction?
james438
11-24-2010, 06:23 PM
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.
ggalan
11-24-2010, 06:42 PM
ok. i have been testing on localhost but will try it on a live server and compare results
thanks for the help
ggalan
11-24-2010, 07:32 PM
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
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($prod, 0, 3);
?>
<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($str6, 0, 6)."_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($str6, 0, 6)."_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($str6, 0, 6)."_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($str6, 0, 6)."_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>
Schmoopy
11-24-2010, 08:01 PM
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
ggalan
11-24-2010, 08:05 PM
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
Schmoopy
11-24-2010, 08:16 PM
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...
ggalan
11-24-2010, 08:30 PM
the url seems to have a delay of 1 click - updating
ggalan
11-25-2010, 04:29 AM
spent the whole day, but fixed for anyone whos got a similar problem
<?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($prod, 0, 3);
?>
<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
$last = substr($str3, -2);
echo "\n<div id='colorwayDiv'>\n<ul>\n";
echo"<li><a href='product_demo.php?prod=";//<<<<< fixed
$swatch_1 = substr($str6, 0, 6)."_dc";
echo $swatch_1;
echo "&id=";
$query1 = "SELECT * FROM products WHERE productID='$swatch_1'";
$result1 = mysql_query($query1) or die (mysql_error());
$row1 = mysql_fetch_array($result1);
echo $row1['id'];
echo"'><img src='img/swatch/A_retreat.jpg' width='30' height='30' /></a></li>\n";
echo"<li><a href='product_demo.php?prod=";//<<<<< fixed
$swatch_2 = substr($str6, 0, 6)."_do";
echo $swatch_2;
echo "&id=";
$query2 = "SELECT * FROM products WHERE productID='$swatch_2'";
$result2 = mysql_query($query2) or die (mysql_error());
$row2 = mysql_fetch_array($result2);
echo $row2['id'];
echo"'><img src='img/swatch/B_retreat.jpg' width='30' height='30' /></a></li>\n";
echo"<li><a href='product_demo.php?prod=";//<<<<< fixed
$swatch_3 = substr($str6, 0, 6)."_pc";
echo $swatch_3;
echo "&id=";
$query3 = "SELECT * FROM products WHERE productID='$swatch_3'";
$result3 = mysql_query($query3) or die (mysql_error());
$row3 = mysql_fetch_array($result3);
echo $row1['id'];
echo"'><img src='img/swatch/C_retreat.jpg' width='30' height='30' /></a></li>\n";
echo"<li><a href='product_demo.php?prod=";//<<<<< fixed
$swatch_4 = substr($str6, 0, 6)."_po";
echo $swatch_4;
echo "&id=";
$query4 = "SELECT * FROM products WHERE productID='$swatch_4'";
$result4 = mysql_query($query4) or die (mysql_error());
$row4 = mysql_fetch_array($result4);
echo $row4['id'];
echo"'><img src='img/swatch/D_retreat.jpg' width='30' height='30' /></a></li>\n";
echo "</ul>\n</div>\n";
?>
</div>
</div>
</body>
</html>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.