aznjay Posted September 13, 2008 Share Posted September 13, 2008 Can anyone create me a script that shows the data from MYSQL as links, and then if i click it it'll show specific data from the specified row. Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/ Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 There is not that much to to it really. Example if(isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; $sql = "SELECT * FROM table WHERE id='$id'"; $result = mysql_query($sql); if(mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); echo '<pre>' . print_r($row, true) . '</pre>'; } } else { $sql = 'SELECT id, title FROM table'; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { echo '<a href="?id='.$row['id'].'">'.$row['title'].'</a><br />'; } } As I don't know what you're table structure is, you will need to modify the queries and the $row variables. Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640418 Share on other sites More sharing options...
aznjay Posted September 13, 2008 Author Share Posted September 13, 2008 Thank you I understand...will this script show the data?? if the link is clicked? Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640561 Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 That is correct. Have you tested it yet. Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640566 Share on other sites More sharing options...
aznjay Posted September 13, 2008 Author Share Posted September 13, 2008 I have the website alltraxx.uni.cc is under construction On the context box of this page I have the code: <?php $file = $_GET['page'].'.php'; if (file_exists($file)) { include $file; } elseif ($_GET['page'] == '') { include ("newsinc.php"); } else { echo ' ERROR'; } ?> Whenever I click on the http://alltraxx.uni.cc/index.php?id=5 ...... it redirects me back to the news page...it does not load up the data from mysql. Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640572 Share on other sites More sharing options...
aznjay Posted September 13, 2008 Author Share Posted September 13, 2008 Yes..It's very helpful, but i got another problem...=( Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640574 Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 whats in newsinc.php Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640597 Share on other sites More sharing options...
aznjay Posted September 13, 2008 Author Share Posted September 13, 2008 that is where the news feed another page that shows is there is no link click from side bar Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640613 Share on other sites More sharing options...
aznjay Posted September 13, 2008 Author Share Posted September 13, 2008 whats in newsinc.php news..that is not significant to the problem Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640652 Share on other sites More sharing options...
wildteen88 Posted September 13, 2008 Share Posted September 13, 2008 What! You're confusing the hell of me! When the user goes to http://alltraxx.uni.cc/index.php?id=X -- X being a number. Whats supposed to happen? Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640653 Share on other sites More sharing options...
aznjay Posted September 14, 2008 Author Share Posted September 14, 2008 it's suppose to show the data from click the link on my website click on my website and click the link PHP this will show the page phptuts.php and then phptuts.php?id="1" and then it'll show specific data from that row...but when ever i click that it show the news... coz' i have the if and then script...that's the main problem... Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640964 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 You just need to add the relevant code in the included file then. If you post phptuts.php here I'll be able to incorporate the code I posted earlier for you. Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-640995 Share on other sites More sharing options...
aznjay Posted September 14, 2008 Author Share Posted September 14, 2008 Here you go: phptuts.php file: <div id="tutorial2"> <? include 'database.php'; if(isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; $sql = "SELECT * FROM phptut WHERE id='$id'"; $result = mysql_query($sql); if(mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); echo '<pre>' . print_r($row, true) . '</pre>'; } } else { $sql = 'SELECT * FROM phptut'; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { echo '<a href="?id='.$row['id'].'">'.$row['title'].'</a><br />'; } } ?> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-641221 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 OK now I understand your problem. Change echo '<a href="?id='.$row['id'].'">'.$row['title'].'</a><br />'; to echo '<a href="'.$_SERVER['REQUEST_URI'].'&id='.$row['id'].'">'.$row['title'].'</a><br />'; Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-641323 Share on other sites More sharing options...
aznjay Posted September 14, 2008 Author Share Posted September 14, 2008 YOU ARE OFFICIALLY THE BEST!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/124039-mysql-data-as-links/#findComment-641366 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.