Jump to content

[SOLVED] Php links


RCS

Recommended Posts

Try this out:

 

<?php

echo '<a href="'. $_SERVER['SCRIPT_NAME'] .'?page=info">Info</a><br />';
echo '<a href="'. $_SERVER['SCRIPT_NAME'] .'?page=about">About</a><br />';
echo '<a href="'. $_SERVER['SCRIPT_NAME'] .'?page=contact">Contact</a><br />';
echo '<br /><br />';

if ($_GET['page'] == 'info') {
   echo 'This is the info page';
} elseif ($_GET['page'] == 'about') {
   echo 'This is the about page';
} elseif ($_GET['page'] == 'contact') {
   echo 'This is the contact page';
} else {
   echo 'No page has been picked yet';
}

?>

 

Should get you on the right track

Link to comment
https://forums.phpfreaks.com/topic/101144-solved-php-links/#findComment-517312
Share on other sites

Say you have these links on your site home, about, sales catalog, gallery

but you don't want to display your link pages like home.php, about.php, sales_catalog.php, gallery.php

 

or e.g http:www.yoursite.com/home.php

 

but oyu want to display it like

 

http:www.yoursite.com/index.php?home or http:www.yoursite.com/index.php?1

Link to comment
https://forums.phpfreaks.com/topic/101144-solved-php-links/#findComment-517313
Share on other sites

You create those links yourself just as you would an ordinary HTML link.

 

I found the idea a little confusing at first also. But its really quite simple.

 

Say for example you have a list of users on your site. You want to display the user names, age,  and a link to their profile.

 

You'd do this. You'd have a page that displays the list.Perhaps you'd retrieve records only of users who are 24 years old.

Your table structure has  the columns, userid,name,age

$query="SELECT * FROM table WHERE age=24";<!--Select all the records where the age=24-->
$result=mysql_query($query);<!--Execute the query-->
$number=mysql_num_rows($result)<!--Check how many results are returned-->
if($number>0)<!--Make sure more than 0 results are returned before the next line is executed-->

{
while($list=mysql_fetch_array($result)<!--Place the result into an array and run a loop through the results-->
        
        {
           print "<h1>$list[username]</h1}"   <!--Print the user name-->
           print "<h2>$list[age]</h2}"   <!--Print the user age-->
           print "<a href='viewprofile.php?userid=$list[userid]'>View user profile</a><!--Print the profile link-->

 

So basically what you have done is selected all the data from the table where the age =24, placed it into an array and printed the array.

The important part is that you have printed a link with ?userid=xyz attached to the end of it. All this does is carry a GET value.

 

You can then test for this value on the link page. So <a href='viewprofile.php?userid=594'> Links to a page called viewprofile.php

 

On the viewprofile.php page you can start with some code to retireve the value that has been passed.

 

$userid=$_GET['userid]

 

This will store the value 594 in the variable $userid. You can use this value to perfomr queries to display the user profile

 

e.g SELECT profile_picture FROM table WHERE userid=$userid

 

etc.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/101144-solved-php-links/#findComment-517335
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.