LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-28-2008, 03:14 PM   #1
htamayo
Member
 
Registered: Jan 2005
Location: san salvador, el salvador
Distribution: Debian Stable, UbuntuStudio Karmic Koala
Posts: 190

Rep: Reputation: 30
populate a php query into a html table with <a href>


Hi, I have several hours dealing with the next problem:
I want to populate a query into a html table, but the problem is that I want to put in the "name" field a url, for example: <a href="viewprofile.php>, So, the user may clic in a specific record and then the user can view the entire profile but I don't know how to controle the value for each record in the table, I'm looking something like it can help me to controle each value, something like <td value>and then send this value via the POST event.

So, may you help me with this?


Thanks a lot
 
Old 04-28-2008, 04:19 PM   #2
rubadub
Member
 
Registered: Jun 2004
Posts: 236

Rep: Reputation: 33
Code:
print "<table width='100%'>";
while ($a = mysql_fetch_array($res))
{
	print "<tr><td>".$a['id']."</td><td><a href='user_".$a['name'].".html'>Link</a></td></tr>";
}
print "</table>";
Something like that?
 
Old 04-28-2008, 04:25 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
It's a little hard to figure out what you're asking. It seems like you want to have a page full of links, each link will essentially send form data to the server so that it can pull info from a database, is that right?

Does it have to be a POST variable? It would be much easier with GET variables. With get, you simply make a link that looks something like:

Code:
<a href="some_page.php?profile_name=some_user_name>some_user_name profile</a>
and then the PHP would look something like:

PHP Code:
function get_profile($uname) {
  
$query "SELECT whatever FROM profile WHERE profile_name='$uname';";
  ...
  return 
$profile;
}

if isset(
$_GET['profile_name']) {
  echo 
get_profile($_GET['profile_name']);

if you *must* do it with post vars, then I would say use javascript to populate then send a form. That's a little more complex of an example. I can post it here, but won't unless you ask for it.
 
Old 04-28-2008, 04:43 PM   #4
htamayo
Member
 
Registered: Jan 2005
Location: san salvador, el salvador
Distribution: Debian Stable, UbuntuStudio Karmic Koala
Posts: 190

Original Poster
Rep: Reputation: 30
Something like this:
Code:
<TABLE border='2'>
<tr><td>Nombres</td><td>Apellidos</td><td>Nivel Academico</td><td>NIT</td><td>NUP</td></tr>
<?php
	while($xrsa = mysqli_fetch_assoc($resa)) 	{
		echo "<tr><td><a href='viewprofile.php'" . $xrsa['nombres']. ">" .$xrsa['nombres'] . "</a></td><td>" . $xrsa['apellidos'] . "</td><td>" . $xrsa['nivacad'] . "</td><td>" . $xrsa['nit'] . "</td><td>" . $xrsa['nup']. "</td></tr>";		
		}
?>
the main problems that I have are:
1. this line <td><a href='viewprofile.php'" . $xrsa['nombres']. ">" , is the one that gives me a headache, because I don't know how to catach the value of some rows, because the name could be: Saquile, Larry, Patrick, Michael, etc.

2. how viewprofile.php will catch this value? because the value will not be passed trough the POST event, because is via the <a href>

Thanks a lot
 
Old 04-28-2008, 04:48 PM   #5
rubadub
Member
 
Registered: Jun 2004
Posts: 236

Rep: Reputation: 33
Code:
echo "<tr><td><a href='viewprofile.php?name='" . $xrsa['nombres']. "'>" .$xrsa['nombres'] . "</a></td><td>" . $xrsa['apellidos'] . "</td><td>" . $xrsa['nivacad'] . "</td><td>" . $xrsa['nit'] . "</td><td>" . $xrsa['nup']. "</td></tr>";
then

Code:
$name = $_GET['name'];
 
Old 04-28-2008, 05:13 PM   #6
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by htamayo View Post
2. how viewprofile.php will catch this value? because the value will not be passed trough the POST event, because is via the <a href>
Just to clarify what both rubadub and I are saying, POST is not the best way to accomplish what you're after. GET is a better choice & the way both of our examples work.

FYI, GET variables are sent through the URL, i.e. http://some_site.com?variable1=value1&variable2=value2

POST values are sent via the html header & require the page to submit the data through, for example, a form.

The nice thing about GET is that you can construct the URL however you'd like through a href, i.e.

Code:
echo "<a href='http://some_side.com/page.php?variable1=$val1&variable2=$val2'>link</a><br />\n";
... and then access that data using php's $_GET array. This is the same thing as creating a GET method form & submitting it.

POST become more difficult because you actually have to submit form data - you can't just put it in the URL.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Populate Validate and Query XML Content LXer Syndicated Linux News 0 05-26-2007 11:46 PM
LXer: <a href="http://blogs.zdnet.com/threatchaos/index.php?p=311">Why is Linux more secure than Windows?</a> LXer Syndicated Linux News 0 04-18-2006 02:03 PM
HTML + href absolute path does not work blizunt7 Programming 3 11-21-2005 04:59 PM
Routing table query mickboda Linux - Networking 3 11-05-2005 11:11 AM
PHP rewrite href in a page newuser455 Programming 5 09-11-2005 07:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration