Page 1 of 1

Retrieving data from link

Posted: Fri Jan 13, 2012 5:05 am
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 ;

Re: Retrieving data from link

Posted: Fri Jan 13, 2012 5:34 am
by Celauran
Why not use GET? project_details.php?proj_num=foo

Re: Retrieving data from link

Posted: Fri Jan 13, 2012 6:05 am
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

Re: Retrieving data from link

Posted: Fri Jan 13, 2012 9:30 am
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>

Re: Retrieving data from link

Posted: Fri Jan 13, 2012 10:27 am
by Ali_Essa
Thanks :)

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

Thanks a lot Celauran,,,

Re: Retrieving data from link

Posted: Fri Jan 13, 2012 2:27 pm
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 ......

Re: Retrieving data from link

Posted: Sat Jan 14, 2012 6:50 am
by Celauran
What is this select() function you're using? Also, please enclose code in [ syntax] tags.

Re: Retrieving data from link

Posted: Sat Jan 14, 2012 6:07 pm
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.