vinnie19 Posted March 26, 2009 Share Posted March 26, 2009 index.php <html> <head> <title>Just a title</title> <link rel="stylesheet" type="text/css" href="css\style.css"> <?php include("include\inc_posts.php"); $info = new posts; ?> </head> <body> <div id="header"> <?php include("include\inc_header.php")?> </div> <div id="menu"> <?php include("include\inc_menu.php")?> </div> <div id="database"> <p class="titel">Video</p> <?php $info->show_video_posts() ?> <br> <p class="titel">Games</p> <?php $info->show_games_posts() ?> </div> </body> </html> post.php <html> <head> <title>Just a title</title> <link rel="stylesheet" type="text/css" href="css\style.css"> </head> <body> <div id="header"> <?php include("include\inc_header.php")?> </div> <div id="menu"> <?php include("include\inc_menu.php")?> </div> <div id="database"> <p class="titel"><?php echo $rij['titel']; ?></p> <p> U heeft geselecteerd id <?php echo $rij['id']; ?></p> <p> Dit is <?php echo $rij['titel']; ?></p> </div> </body> </html> inc_posts.php <?php class posts { function show_video_posts(){ $db= sqlite_open ("database\dvddb.sdb"); $sql= "SELECT * FROM allposts WHERE category = 'video' ORDER BY id DESC LIMIT 10;"; $result= sqlite_query($db, $sql); while ($rij = sqlite_fetch_array($result)){ echo ("<a href=\"post.php?id=". $rij['id'] ."\">".$rij['id']."|". $rij['titel']."</a>". "<br>\n"); } return $info; }//einde functie show_video_posts function show_games_posts(){ $db= sqlite_open ("database\dvddb.sdb"); $sql= "SELECT * FROM allposts WHERE category = 'games' ORDER BY id DESC LIMIT 10;"; $result= sqlite_query($db, $sql); while ($rij = sqlite_fetch_array($result)){ echo ($rij['id']."|". $rij['titel']."". "<br>\n"); } return $info; }//einde functie show_games_posts function show_video(){ $db= sqlite_open ("database\dvddb.sdb"); $sql= "SELECT * FROM allposts WHERE category = 'video' ORDER BY id;"; $result= sqlite_query($db, $sql); while ($rij = sqlite_fetch_array($result)){ echo ($rij['id']."|". $rij['titel']."". "<br>\n"); } return $info; }//einde functie show_video function show_games(){ $db= sqlite_open ("database\dvddb.sdb"); $sql= "SELECT * FROM allposts WHERE category = 'games' ORDER BY id;"; $result= sqlite_query($db, $sql); while ($rij = sqlite_fetch_array($result)){ echo ($rij['id']."|". $rij['titel']."". "<br>\n"); } return $info; }//einde functie show_games }//einde class ?> The header and the menu contains nothing interesting This is what i have now: On the index you see this: 1|record 1 2|record 2 Now i want to click on the 1|record 1 and then go to post.php and get there the info about record 1 And if i click on 2|record 2 then go to post.php but then with info about record 2 How can i do this? Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/ Share on other sites More sharing options...
ober Posted March 26, 2009 Share Posted March 26, 2009 Instead of: <div id="database"> <p class="titel"><?php echo $rij['titel']; ?></p> <p> U heeft geselecteerd id <?php echo $rij['id']; ?></p> <p> Dit is <?php echo $rij['titel']; ?></p> </div> You'll need to run a query before that that pulls the data out of the database again based on the ID: $id = mysql_real_escape_string($_GET['id]); $query = "SELECT * FROM allposts WHERE id = $id"; Does that help? So instead of $rij, your array would be the row you pull from the database based on the ID. Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794439 Share on other sites More sharing options...
JonnoTheDev Posted March 26, 2009 Share Posted March 26, 2009 Using a url parameter i.e. post.php?id=1 On post.php the value is stored in $_GET['id']; Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794440 Share on other sites More sharing options...
redarrow Posted March 26, 2009 Share Posted March 26, 2009 just tighten the code a little. make sure the $_GET['id'] is numeric <?php $id = mysql_real_escape_string(is_numeric($_GET['id'])); $query = "SELECT * FROM allposts WHERE id = $id"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794452 Share on other sites More sharing options...
vinnie19 Posted March 26, 2009 Author Share Posted March 26, 2009 But is the function in inc_posts.php then correct? (the url?) Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794466 Share on other sites More sharing options...
vinnie19 Posted March 26, 2009 Author Share Posted March 26, 2009 I just was looking to the code you gave me but im not using mysql. Im using SQLite Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794515 Share on other sites More sharing options...
redarrow Posted March 26, 2009 Share Posted March 26, 2009 trim() the same in sql lite does not do the same theo lol <?php $id = trim(is_numeric($_GET['id']); $query = "SELECT * FROM allposts WHERE id = $id"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794522 Share on other sites More sharing options...
corbin Posted March 26, 2009 Share Posted March 26, 2009 Errr redarrow, that code doesn't make sense at all since is_numeric returns a boolean. Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794526 Share on other sites More sharing options...
scottybwoy Posted March 26, 2009 Share Posted March 26, 2009 Look up SQL injection using your favourite search. as far as I know SQLite doesn't have the same feature as mySQL in php. As you are getting the id from a link it shouldn't be a problem, but that won't stop people from editing the URL manually to jeopodise your database. You may want to create a function (or find one on the net) with a preg_match(REGEX) in it. Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794527 Share on other sites More sharing options...
vinnie19 Posted March 26, 2009 Author Share Posted March 26, 2009 Now im very lost. Im still a beginner in php. So i need some help someone who can help me step by step helping with this. So not to difficult. Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794575 Share on other sites More sharing options...
vinnie19 Posted March 26, 2009 Author Share Posted March 26, 2009 fixed it myself it was only this code on post.php <?php $db= sqlite_open ("database\dvddb.sdb"); $query= "SELECT * from allposts WHERE id=" . $_GET["id"]; $result= sqlite_query($db, $query) or die ("FOUT: " . sqlite_error()); ?> Wasnt that hard Quote Link to comment https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/#findComment-794693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.