abeer Posted June 12, 2011 Share Posted June 12, 2011 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 https://forums.phpfreaks.com/topic/239141-is-it-possible-if-then-how/ Share on other sites More sharing options...
cssfreakie Posted June 12, 2011 Share Posted June 12, 2011 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 https://forums.phpfreaks.com/topic/239141-is-it-possible-if-then-how/#findComment-1228711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.