Jump to content

adding a value with my link


elexion

Recommended Posts

hello everyone, I'm trying to add a value to my link. So far i've come up with

echo "<a href='detail.php?product={$query['productname']}\'>" . $row['productname'] . "</a>" . $row['console'];

note that i do have all the required tags etc this is just the part i'm concerned about.the idea is that once i arrive at the detail page i still have the productname value and am able to read it.this is where it gets quite nasty.

<body><?php$query['productname'];$result = mysql_query ("SELECT * FROM products WHERE productname= $query");echo $result;?></body>

i should probably be using a $_GET but how do i apply it to this? it's been a while since i programmed in php

Link to comment
Share on other sites

When you passed the value using the link.it will be sent using get and wahtever value is passed will be available to that page in $_GET associative array.

echo "<a href='detail.php?product={$query['productname']}\'>" . $row['productname'] . "</a>" . $row

if you click on that link name=value pairs will be availabe to $_GET array. name (eg. product) will be the index of the $_GET array and it will contain the value(eg value of $query['productname'] wahtever will be evaluated in the anhor)echo $_GET['product']; will show you the value of $query['productname']

Link to comment
Share on other sites

$_GET is a super global array. When you pass a variable through the URL it will be available in the $_GET array. Take a look at the example below. In this example we have a simple webpage with a link that says "Click Me!" in it. In the link we pass a variable called myvariable with the value of myvalue. When the link is clicked, the browser will go to index.php?myvariable=myvalue. It's the same page, but in the URL you will notice the variable has been added. To retrieve values from the URL we use the $_GET array.

<html><head><title>index.php</title></head><body><a href="index.php?myvariable=myvalue">Click Me!</a></body></html>

First you will have to test if the variable you are looking for has been set. To do this we use the isset(); function. If the variable has indeed been set it will return true, otherwise it will return false. That's great, because then we can use a conditional if statement to test if the variable has been set or not and act upon it. Look in the example below.

if(isset($_GET['myvariable'])){	//if the variable has been set, do stuff here!}

Now all we have to do is save the value to a variable and then we can do stuff with it! Look below. The value of $_GET['myvariable'] is being saved in the variable $storage. And there you have it!

<?phpif(isset($_GET['myvariable'])){	$storage = $_GET['myvariable'];}?>

Link to comment
Share on other sites

When you passed the value using the link.it will be sent using get and wahtever value is passed will be available to that page in $_GET associative array.
echo "<a href='detail.php?product={$query['productname']}\'>" . $row['productname'] . "</a>" . $row

if you click on that link name=value pairs will be availabe to $_GET array. name (eg. product) will be the index of the $_GET array and it will contain the value(eg value of $query['productname'] wahtever will be evaluated in the anhor)echo $_GET['product']; will show you the value of $query['productname']

Thank you that solved getting the value from A to B. But for some extremely odd reason when i try to echo the rows i get a error message that my argument in the mysql fetch array is not a valid result source at this point i'm not quite sure to why this is so.(actual error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in)
<?php$product = $_GET['product'];$result = mysql_query("SELECT * FROM producten WHERE productname=$product");while($row = mysql_fetch_array($result))  {  $row['description'] . " " . $row['console'];  }?>

note that i already echo'd the value of $product and it's exactly what i want it to be.

Link to comment
Share on other sites

Echo out the query to see whether that contains what you think it does. You probably need quotation marks around the string literal.

Link to comment
Share on other sites

Echo out the query to see whether that contains what you think it does. You probably need quotation marks around the string literal.
Your right. quotation marks did the trick also had to thow in a echo to see the results but it's working properly now thank you
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...