PHP - sending data via hyperlink

Reply

Join Date: Apr 2007
Posts: 6
Reputation: pink_zippy_123 is an unknown quantity at this point 
Solved Threads: 0
pink_zippy_123 pink_zippy_123 is offline Offline
Newbie Poster

PHP - sending data via hyperlink

 
0
  #1
Apr 18th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 57
Reputation: GliderPilot is an unknown quantity at this point 
Solved Threads: 2
GliderPilot's Avatar
GliderPilot GliderPilot is offline Offline
Junior Poster in Training

Re: PHP - sending data via hyperlink

 
0
  #2
Apr 18th, 2007
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['brand'];

now the brand variable equals the brand value of the link that was clicked.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: PHP - sending data via hyperlink

 
0
  #3
Apr 18th, 2007
Originally Posted by pink_zippy_123 View Post
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:

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

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]
<?php

// page.php

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

// array will look like

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

$_GET['category']; // 1

?>
[/php]

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...
Last edited by digital-ether; Apr 18th, 2007 at 10:03 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 6
Reputation: pink_zippy_123 is an unknown quantity at this point 
Solved Threads: 0
pink_zippy_123 pink_zippy_123 is offline Offline
Newbie Poster

Re: PHP - sending data via hyperlink

 
0
  #4
Apr 20th, 2007
Hi - thanks a lot for your help i've got it working now
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: zanzo is an unknown quantity at this point 
Solved Threads: 0
zanzo's Avatar
zanzo zanzo is offline Offline
Junior Poster in Training

Re: PHP - sending data via hyperlink

 
0
  #5
Feb 27th, 2008
hello,
im a new user

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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: PHP - sending data via hyperlink

 
0
  #6
Feb 27th, 2008
Originally Posted by zanzo View Post
hello,
im a new user

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 ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: zanzo is an unknown quantity at this point 
Solved Threads: 0
zanzo's Avatar
zanzo zanzo is offline Offline
Junior Poster in Training

Re: PHP - sending data via hyperlink

 
0
  #7
Feb 27th, 2008
<?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';
?>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: PHP - sending data via hyperlink

 
0
  #8
Feb 27th, 2008
  1. <?php
  2. include 'config.php';
  3. include 'opendb.php';
  4.  
  5. $rowsPerPage = 5;
  6. $pageNum = 1;
  7.  
  8. if(isset($_GET['page']))
  9. {
  10. $pageNum = $_GET['page'];
  11. }
  12.  
  13. $offset = ($pageNum - 1) * $rowsPerPage;
  14.  
  15. $query = " SELECT FName, LName FROM user " .
  16. " LIMIT $offset, $rowsPerPage";
  17. $result = mysql_query($query) or die('Error, query failed');
  18.  
  19. while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  20. {
  21. $first=$row['FName'];
  22. $last=$row['LName'];
  23. echo "a href=\"Details.php?first=$first&last=$last\">";
  24. if(mysql_num_rows($result)<1){
  25. echo "No Results!";
  26. }
  27. }
  28. include 'closedb.php';
  29. ?>
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: zanzo is an unknown quantity at this point 
Solved Threads: 0
zanzo's Avatar
zanzo zanzo is offline Offline
Junior Poster in Training

Re: PHP - sending data via hyperlink

 
0
  #9
Feb 27th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: zanzo is an unknown quantity at this point 
Solved Threads: 0
zanzo's Avatar
zanzo zanzo is offline Offline
Junior Poster in Training

Re: PHP - sending data via hyperlink

 
0
  #10
Feb 27th, 2008
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=">
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC