Jump to content

is it possible? if then how?


abeer

Recommended Posts

Hi there.. i am new in this forum as well as new in php..  i need help regarding below issue. please help me

 

 

I use below code to display data from mysql  row from specific id. here is id=1

 

<?php 
mysql_connect("localhost", "dhaka", "dhaka") or die("Connection Failed"); 
mysql_select_db("dhaka")or die("Connection Failed"); 
$result = mysql_query("SELECT *FROM page WHERE id='1'")
or die(mysql_error());
$row = mysql_fetch_array( $result );
echo "content: ".$row['dtl'];

?>

 

now i included this code by using php include function in one page called " johns page.php"

 

so when i click the "john page" the page come with the pulling from id=1.

 

but if i have 30 page like " kate page" ," roberts page", "michale page"......

 

then i have to include the above code 30 time by editing it manusally have to change the id number.

 

for "kate page" i have to change  manually the line

$result = mysql_query("SELECT *FROM page WHERE id='1'")

 

to

 

$result = mysql_query("SELECT *FROM page WHERE id='2'")

and include the code to " kate page.php"

 

which is horrible expreince for multiple  page...

 

is it possible that  the id number will automatically change when i click on different page?

 

please help me

Link to comment
Share on other sites

Well if you want to change the value of a variable by clicking on a link you need to append a $_GET variable to that link.

 

Just as a demonstration the following will result in a different value when you click the links. Try that out as is so you see what is going on.

 

<?php 
//some standard error reporting, remove on a live server
error_reporting(E_ALL);
ini_set("display_errors", 1);


$id = 1; // giving a default value, could be anything

if(isset($_GET['id'])){ // isset checks to see if the $_GET variable id is set
    $id = $_GET['id'];

}

?>
<a href="?id=1">kate</a>
<a href="?id=2">pete</a>
<a href="?id=3">steve</a>
<a href="?id=4">kate4</a>
<a href="?id=5">pete5</a>
<a href="?id=6">steve6</a>
<br /><br />

<?php echo 'the value is now: '.$id; ?>

 

So if you want you can just put $id in the database query. There is only one catch: the value can not be trusted since the end user can change it. So before you apply this, read the security tutorial http://www.phpfreaks.com/tutorial/php-security

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.