Retrieving data from link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ali_Essa
Forum Newbie
Posts: 4
Joined: Fri Jan 13, 2012 4:54 am

Retrieving data from link

Post by Ali_Essa »

I have table designed in HTML that has many attributes using PHP.
One of them I want it to be a link to another page.

When the user go to the second page, I want to receive specific attribute and fetch from the database depending on this attribute.
I don't know how to use GET or POST methods with tables? Can we? Because it is not usual form!

This is the line that I want to add to it the $proj_num so in the other page I can fetch the information related to this specific $proj_num?
<td><a href="project_details.php" class="action"><?php echo ($proj_num);?></a></td>

So, My question is: How to send this specific attribute and how to receive it in the other page and fetch depending on it?

Hope my question is clear?

For your information of you need them, these are the tables I created in the database:


CREATE TABLE IF NOT EXISTS `projects` (
`id` int(150) NOT NULL AUTO_INCREMENT,
`proj_num` varchar(11) DEFAULT NULL,
`proj_desc` varchar(150) NOT NULL,
`customer` varchar(150) NOT NULL,
`plan_revenue` int(150) NOT NULL,
`plan_cost` int(150) NOT NULL,
`available_budget` int(150) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `proj_num` (`proj_num`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

CREATE TABLE IF NOT EXISTS `purchase_orders` (
`id` int(50) NOT NULL AUTO_INCREMENT,
`proj_num` varchar(100) NOT NULL,
`po_desc` varchar(100) NOT NULL,
`amount` int(50) NOT NULL,
`po_num` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `po_num` (`po_num`),
KEY `proj_num` (`proj_num`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;


CREATE TABLE IF NOT EXISTS `items` (
`id` int(50) NOT NULL AUTO_INCREMENT,
`po_num` varchar(100) NOT NULL,
`item_num` varchar(50) NOT NULL,
`item_desc` varchar(100) NOT NULL,
`item_quant` int(50) NOT NULL,
`item_price` int(50) NOT NULL,
PRIMARY KEY (`id`),
KEY `item_num` (`item_num`),
KEY `po_num` (`po_num`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Retrieving data from link

Post by Celauran »

Why not use GET? project_details.php?proj_num=foo
Ali_Essa
Forum Newbie
Posts: 4
Joined: Fri Jan 13, 2012 4:54 am

Re: Retrieving data from link

Post by Ali_Essa »

I tried using this:
<a href="project_details.php?proj_num=$proj_num" class="action"><?php echo ($proj_num);?></a>
But it doesn't work!
What show in the address bar is this:
project_details.php?proj_num=$proj_num
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Retrieving data from link

Post by Celauran »

Ali_Essa wrote:I tried using this:
<a href="project_details.php?proj_num=$proj_num" class="action"><?php echo ($proj_num);?></a>
But it doesn't work!
What show in the address bar is this:
project_details.php?proj_num=$proj_num

Code: Select all

<a href="project_details.php?proj_num=<?php echo $proj_num; ?>" class="action"><?php echo ($proj_num);?></a>
Ali_Essa
Forum Newbie
Posts: 4
Joined: Fri Jan 13, 2012 4:54 am

Re: Retrieving data from link

Post by Ali_Essa »

Thanks :)

It is solved by using echo. Now I will try using GET[] in the other page.

Thanks a lot Celauran,,,
Ali_Essa
Forum Newbie
Posts: 4
Joined: Fri Jan 13, 2012 4:54 am

Re: Retrieving data from link

Post by Ali_Essa »

I found difficulty in retrieving the data :(
What I used to fetch the projects is this:

$query_projects = select("SELECT * FROM projects");
$query_purchase_orders = select("SELECT * FROM purchase_orders ");

Then I used these two if statements to fetch from the database:

if(!$query_projects)
{
$row = mysql_fetch_array($query_projects);
}
if(!$query_purchase_orders)
{
$row2 = mysql_fetch_array($query_purchase_orders);

}

It works fine with me.
But WHen I want to do this:
$query_purchase_orders1 = select("SELECT * FROM purchase_orders WHERE proj_num = $proj_num");
if(!$query_purchase_orders1)
{
$row3 = mysql_fetch_array($query_purchase_orders1);
}
it gives me this error message: :(

mysql_fetch_array() expects parameter 1 to be resource, array given in ......
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Retrieving data from link

Post by Celauran »

What is this select() function you're using? Also, please enclose code in [ syntax] tags.
aadesh
Forum Newbie
Posts: 1
Joined: Fri Jan 13, 2012 3:31 pm

Re: Retrieving data from link

Post by aadesh »

the first step is to fetch information from table and than store in variables. 2nd pass or send these variable on calling page with link.
Post Reply