View Full Version : PHP Links
jc_gmk
06-13-2007, 02:51 PM
Probably a simple answer for those of you that know, but i'm trying to display a page of data from a MySQL database using PHP.
Can i send information from anything other than a form
e.g.
In a form I would do the following:
<form action="mypage.php" method="post">
<input type="text" name="myvalue" />
<input type="Submit" />
</form>
can I submit a single value using a link
e.g.
<a href="mypage.php" name="myvalue">
boogyman
06-13-2007, 04:44 PM
yes you can, but you would need to be more specific in naming the file. when you submit to a form there is extra data that is sent with it depending on what method you use (eg post / get), if you wish to just use a link, then you really need to be alot more specific in the url.
Take this for example
<form action="process.php" method="get">
Name: <input type="text" name="user" value="CLIENT_NAME" />
<input type="submit" value="submit" />
</form>
you would then grab that info in your php process.php file by using this
$name = $_GET['user'];
...
...
to accomplish that with just a link you would need to hard code the "user" in this case, which would look something like
[code]
<a href="process.php?user=CLIENTNAME">link title</a>
you would then grab that info in your php process.php file by using this
$name = $_GET['user'];
...
...
so if what you are attempting to do is just submit a constant value then yes you can use just a link, however if you are trying to obtain some type of resource / content from a client/user then I would suggest that you use the form method.
either way you would still need to handle the mysql inside the php file.
jc_gmk
06-14-2007, 08:50 AM
Works a treat!!
Thanks! :D
jc_gmk
06-14-2007, 08:59 AM
Following on from that question, I have now created a page that calls different data depending on what link you click.
Is there anyway that if one of these links are clicked
it is then highlighted to let the user know what the are looking at
kiwibrit
06-14-2007, 09:29 AM
If you mean the something like the link, and maybe its background colour changing, see here (http://www.w3.org/TR/REC-CSS2/selector.html#dynamic-pseudo-classes).
jc_gmk
06-14-2007, 09:54 AM
I am able to currently using those methods anyway,
what I need to know is; can I get the link to stay highlighted the whole time they are veiwing a dynamic page
e.g.
page1 | page2 | page3 | page 4
This content was produced by clicking page2
page1 | page2 | page3 | page 4
This content was produced by clicking page3
kiwibrit
06-14-2007, 12:35 PM
Hmm. Pretty much what you get on a good tabbed menu system, which I am digging about for at the moment. Here's one example (http://nontroppo.org/test/tab1.html). As for generation of the tabs through php, here's something I thought I might look at (http://www.phpclasses.org/browse/package/3059.html) when I get a round tuit (in short supply at the moment). May help you?
This should produce the effect . . .
//list of variables
$list_of_variables = array("var1" => "page one",
"var2" => "page two",
"var3" => "page three",
"var4" => "page four");
$tmp = array();
foreach ($list_of_variables as $var => $page_name) {
if ($_GET['my_var'] == $var) {
$tmp[] = "<font color='red'>$page_name</font>";
} else {
$tmp[] = "<a href='mypage.php?my_var=$var'>$page_name</a>";
}
}
echo(implode(" | ", $tmp);
echo("<br/>You've reached this page by clicking on ".$_GET['my_var']);
so then if the person clicks on
<a href='mypage.php?my_var=var3'>page three</a> they'll get this:
page one | page two | page three | page four
You've reached this page by clicking on var3
Where, of course, pages one two and four are links but page three is not.
boogyman
06-14-2007, 05:28 PM
<font> tags have been depreciated by the W3C Standards Committe. Use a <div > or <p> or <span> tag then use a CSS style to mark it up
kiwibrit
06-14-2007, 06:55 PM
Kosi, nice. I have bookmarked this thread.
You're welcome. And thanks, boogy, I didn't know that.
boogyman
06-19-2007, 12:42 PM
This should produce the effect . . .
//list of variables
$list_of_variables = array("var1" => "page one",
"var2" => "page two",
"var3" => "page three",
"var4" => "page four");
$tmp = array();
foreach ($list_of_variables as $var => $page_name) {
if ($_GET['my_var'] == $var) {
$tmp[] = "<font color='red'>$page_name</font>";
} else {
$tmp[] = "<a href='mypage.php?my_var=$var'>$page_name</a>";
}
}
echo(implode(" | ", $tmp);
echo("<br/>You've reached this page by clicking on ".$_GET['my_var']);
so then if the person clicks on
<a href='mypage.php?my_var=var3'>page three</a> they'll get this:
page one | page two | page three | page four
You've reached this page by clicking on var3
Where, of course, pages one two and four are links but page three is not.
thats a very nice idea koshi although I would take it 1 step further, and use a list.
//list of variables
<?php
$list_of_variables = array("var1" => "page one",
"var2" => "page two",
"var3" => "page three",
"var4" => "page four");
$tmp = array();
foreach ($list_of_variables as $var => $page_name) {
if ($_GET['my_var'] == $var) {
$tmp[] = "<li>$page_name</li>";
} else {
$tmp[] = "[b]<li>[b]<a href='mypage.php?my_var=$var'>$page_name</a></li>";
}
}
?>
<ul>
<?php echo(implode(" | ", $tmp); ?>
</ul>
echo("<p>You've reached this page by clicking on ".$_GET['my_var']."</p>");
then you can use some CSS to mark it up and make it look how you want.
<style type="text/css">
ul {
list-style: none; //Gets rid of the bullets
}
ul li {
display: inline; //Displays list horizontally
}
li a:link, li a:visited {
color: #ff0000; //Links = red when first visiting / after you come back
text-decoration: underline; //Displays link underline
}
li a:hover, li a:active {
color: #0000ff; //Links = blue when in hover / click state
text-decoration: none; //Deletes link underline in hover/click state
}
</style>
changes are in bold. By doing it this way rather than the way koshi described, you are staying W3C compliant (Standards), and giving yourself more control over what you are doing with the navigation
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.