Hi,

Basically I am quite new to php but am currently connecting to a database and am trying to send data from one web page to another using the information selected in a hyperlink.

The first web page contains a table populated will all options within the database e.g. if it was computer software it would show all the brands and products. But i want to select one of these products using a hyperlink under that option in the table and use the product details selected to populate the table on the next page e.g. then showing the price and extra details for the product selected.

I don't think this requires the use of a form but am quite stuck with how to do this....i can get the hyperlink to move to the next page but the second page still displays all products rather than the one chosen!

any ideas would be greatly appreciated!

Recommended Answers

All 25 Replies

have your link end in .php?brand=dell

You can add this to the end of a url and it bassicaly stores the variable (dell) in the variable name (brand) which PHP can access.

Than on the next page you can use the
$brand = $_GET;

now the brand variable equals the brand value of the link that was clicked.

Hi,

Basically I am quite new to php but am currently connecting to a database and am trying to send data from one web page to another using the information selected in a hyperlink.

The first web page contains a table populated will all options within the database e.g. if it was computer software it would show all the brands and products. But i want to select one of these products using a hyperlink under that option in the table and use the product details selected to populate the table on the next page e.g. then showing the price and extra details for the product selected.

I don't think this requires the use of a form but am quite stuck with how to do this....i can get the hyperlink to move to the next page but the second page still displays all products rather than the one chosen!

any ideas would be greatly appreciated!

Say for example you have a link like:

<a href="page.php?category=1">Shoes</a>

Then if a user clicks on that link, they will be taken to page.php.

When page.php is loaded, PHP will create a global Array $_GET with the parameters sent via the HTTP Request.

This Array will look like this:

<?php

// page.php

// request was: page.php?category=1

// array will look like

$_GET; // array('category'=>'1');

$_GET['category']; // 1

?>

As you can see you can get the parameter: category via the $_GET array.

So you can use this in your database query.

Edit: lol.. Guilderpilot, looks like you got to it first...

Hi - thanks a lot for your help i've got it working now :)

hello,
im a new user :S

and i need help !!

i need to use the hyperlink value as variable

<a href="Details.php"><?php echo "$first" . " " . "$last<br>";?></a>
i need to get $first and $fast
to use them later in the code
so how could i?

plz reply fast

best regards
zanzo

hello,
im a new user :S

and i need help !!

i need to use the hyperlink value as variable

<a href="Details.php"><?php echo "$first" . " " . "$last<br>";?></a>
i need to get $first and $fast
to use them later in the code
so how could i?

plz reply fast

best regards
zanzo

Can you post your code ?

<?php
    include 'config.php';
    include 'opendb.php';

  $rowsPerPage = 5;
  $pageNum = 1;

  if(isset($_GET['page']))
  {
    $pageNum = $_GET['page'];
  }

  $offset = ($pageNum - 1) * $rowsPerPage;

  $query = " SELECT FName, LName FROM user " .
         " LIMIT $offset, $rowsPerPage";
  $result = mysql_query($query) or die('Error, query failed');

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{   
    $first=$row['FName'];
    $last=$row['LName'];

    ?>  
   <a href="Details.php"><?php echo "$first" . " " . "$last<br>";?></a>   
   <?php 

    if(mysql_num_rows($result)<1){
    echo "No Results!";
     }
 }
include 'closedb.php';
?>
<?php
include 'config.php';
include 'opendb.php';

$rowsPerPage = 5;
$pageNum = 1;

if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}

$offset = ($pageNum - 1) * $rowsPerPage;

$query = " SELECT FName, LName FROM user " .
" LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$first=$row['FName'];
$last=$row['LName'];
echo "a href=\"Details.php?first=$first&last=$last\">";
if(mysql_num_rows($result)<1){
echo "No Results!";
}
}
include 'closedb.php';
?>

in this code, i do post registered users
and when u click a First name and last name
you got all the information about a user
this is done in the second page "Details.php"

but i need the 2 variables $first and $last
in order to get the data from db

it will not work like this
coz u set $first to first and $last to last

look here what i got
a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">

it will not work like this
coz u set $first to first and $last to last

look here what i got
a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">a href="Details.php?first=&last=">

it looops the number of users entered in db :S

Thats because theres no value in $first and $last.

the code is working and i got a list of hyperlinks
each line contain a First and LAst name

the problem is how to set this value when somebody click on a name in order to get all details ?????

i do really dunno :(

When somebody clicks on a name, get the name using $_GET. Then use it in the query. But, I don't recommend using firstname to get the details, because there can be more than 1 people with the same first name.

$_GET : i know that i should use this method but i dont know how to right "variablename" inside? with $? or how?

then this method is applied in the Details.php page

As for firstname, its not the only field, it is with last name, and this is not my choice ;)

thx a lot

for example, If you have a hyperlink, <a href="page1.php?firstname=test&lastname=user">Click here</a>. When you click it, in page1.php, you need to write,

$firstname = $_GET['firstname'];
$lastname = $_GET['lastname'];

for example, If you have a hyperlink, <a href="page1.php?firstname=test&lastname=user">Click here</a>. When you click it, in page1.php, you need to write,

$firstname = $_GET;
$lastname = $_GET;


ok but what is the value of test and user ???

what ? test and user ARE the values for firstname and lastname.

$first=$row;
$last=$row;

?>
<a href="Details.php"><?php echo "$first" . " " . "$last<br>";?></a>
<?php

fine so it will look like this:

<a href="Details.php?firstname=$first&lastname=$last"><?php echo "$first". ""."$last<br>";?></a>

??????

Yep. But you don't need a br. AND you need to keep it like this. echo <a href=\"details.php?firstname=$first&lastname=$last\">$first." ".$last</a>";

this cod in the registered.php
<a href="Details.php?firstname=$first&lastname=$last"><?php echo "$first" . " " . "$last<br>";?></a>

i tried the following code in Details.php:
$fname = $_GET;
$lname = $_GET;
echo ($fname);
echo ($lname);

look what is the result:

$first$last

so what to do???

You need to put <a href tag inside php echo statement. OR, use this.

<a href="Details.php?firstname=<?php echo $first; ?>&lastname=<?php echo $last; ?>"><?php echo "$first" . " " . "$last<br>";?></a>

That it :D
thanks a lot

You are welcome :)

:D
i have displayed a user data in Details.php
so now i have to let him "update" or "Delete"

But i don't know yet how to handle that within the same page
by using hidden variable??! and redirect page!

so could you help
best regards,
zanzo

:D
i have displayed a user data in Details.php
so now i have to let him "update" or "Delete"

But i don't know yet how to handle that within the same page
by using hidden variable??! and redirect page!

so could you help
best regards,
zanzo

You can use a link just like you did on the page, or an HTML Form. Essentially they achieve the same thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.