craig1978 Posted April 27, 2007 Share Posted April 27, 2007 Hi Guys, Last time I posted you were awesome, Thanks!! Here's my question: I don't have any code to post as I actually don't know where to even start. With your help I have built a MySQL database and created a search page to display results. I now want to make each result a link to a page displaying more details about each result. I would prefer not to create a different HTML page about each result, and would prefer to create some sort of PHP script to get the data (including photos) from the database. I just think this would make it easier to manage, only 1 template page vs 100's. Any help or ideas would be greatly appreciated. Thanks Craig Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/ Share on other sites More sharing options...
nikkieijpen Posted April 27, 2007 Share Posted April 27, 2007 Use the GET method Link your search result to your details page by passing the ID in de URL. The details page extracts the id from the URL and executes a mysql_query which gets the row which had that particular id. Search results page: <a href="details.php?id=<?= $row_seach_result['id'] ?>"><?= $row_seach_result['title'] ?></a> And your details page: if(isset($_GET['id'])) { $id = $_GET['id']; $result=mysql_query("SELECT * FROM table WHERE id='$id'"); $row_result=mysql_fetch_assoc($result); } Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/#findComment-239713 Share on other sites More sharing options...
craig1978 Posted April 27, 2007 Author Share Posted April 27, 2007 Just a few questions: Sorry I am pretty new to any coding let alone PHP. 1.Do I need to post anything else in the details.php page?? 2.Where exactly do I put the code on the results.php page?? 3.Does it matter that I used the POST method to display the results page from the search form?? I will post the code I used below: This is the details.php <? include 'Config.php' include 'OpenDB.php' if(isset($_GET['Thumbnail'])) { $id = $_GET['Thumbnail']; $result=mysql_query("SELECT * FROM PersonalTrainers WHERE Thumbnail='$Thumbnail'"); $row_result=mysql_fetch_assoc($result); } include 'CloseDB.php' ?> This is the results.php <body> <? include 'Config.php'; include 'OpenDB.php'; $query = "SELECT * FROM PersonalTrainers WHERE Postcode = '".$_POST['Postcode']."' AND Age = '".$_POST['Age']."' AND Sex = '".$_POST['Sex']."'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Personal Trainers</center></b><br><br>"; $i=0; while ($i < $num) { $Thumbnail=mysql_result($result,$i,"Thumbnail"); $First_Name=mysql_result($result,$i,"First_Name"); $Last_Name=mysql_result($result,$i,"Last_Name"); $Email=mysql_result($result,$i,"Email"); $Suburb=mysql_result($result,$i,"Suburb"); $Postcode=mysql_result($result,$i,"Postcode"); $Age=mysql_result($result,$i,"Age"); echo "<center>$Thumbnail<br><b>$First_Name $Last_Name</b><br>Email: $Email<br>Suburb: $Suburb<br>Postcode: $Postcode<br>Age: $Age<br><hr><br></center>"; $i++; } ?> <a href="details.php?id=<?= $Thumbnail['Thumbnail'] ?>"><?= $Email['Email'] ?></a> </body> Thanks in advance Craig Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/#findComment-239741 Share on other sites More sharing options...
bubblegum.anarchy Posted April 27, 2007 Share Posted April 27, 2007 Have you tried the php forum? Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/#findComment-239756 Share on other sites More sharing options...
craig1978 Posted April 27, 2007 Author Share Posted April 27, 2007 No I haven't, that's a good idea. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/#findComment-239758 Share on other sites More sharing options...
nikkieijpen Posted April 27, 2007 Share Posted April 27, 2007 1. No, only showing the details 2. You put the <a href=..... in the while loop 3. No, The difference between GET and POST is in the way of sending data to the page, while the GET method sends data using URL, the POST method sends them through the standard entrance STDIO. Does every 'Personal Trainer' have an unique number (ID)? Or is Thumbnail unique? You need something unique to pass to the details page so the details page knows which trainer's details to show... Try this code in your results page: $query = "SELECT * FROM PersonalTrainers WHERE Postcode = '".$_POST['Postcode']."' AND Age = '".$_POST['Age']."' AND Sex = '".$_POST['Sex']."'"; $result=mysql_query($query); $row_result = mysql_fetch_assoc($result); mysql_close(); echo "<center>Personal Trainers</center>"; while ($row_result = mysql_fetch_assoc($result)) { echo '<center><a href="details.php?id='.$row_result['Thumbnail'].'">'.$row_result['Thumbnail'].'</a></center>'; } Change in the details page: $id = $_GET['Thumbnail']; into: $Thumbnail = $_GET['Thumbnail']; Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/#findComment-239768 Share on other sites More sharing options...
craig1978 Posted April 27, 2007 Author Share Posted April 27, 2007 Hey Thanks, Got the Thumbnail to be a link to the Details.php page, but it only displays the message: "No input file specified" Any ideas?? Do I need to do more on the Detail page apart from what I posted?? Any echos or anything?? Thanks Craig Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/#findComment-239778 Share on other sites More sharing options...
craig1978 Posted April 27, 2007 Author Share Posted April 27, 2007 One other thing, I haven't changed other parts of the code but my results page no longer outputs First and Last names. Did i ruin something when I entered the href stuff: echo "<b><center>Personal Trainers</center></b><br><br>"; $i=0; while ($row_result = mysql_fetch_assoc($result)) { echo '<center><a href="details.php?id='.$row_result['Thumbnail'].'">'.$row_result['Thumbnail'].'</a></center>'; $Thumbnail=mysql_result($result,$i,"Thumbnail"); $First_Name=mysql_result($result,$i,"First_Name"); $Last_Name=mysql_result($result,$i,"Last_Name"); $Email=mysql_result($result,$i,"Email"); $Suburb=mysql_result($result,$i,"Suburb"); $Postcode=mysql_result($result,$i,"Postcode"); $Age=mysql_result($result,$i,"Age"); echo "<center><br><$First_Name $Last_Name<br>Email: $Email<br>Suburb: $Suburb<br>Postcode: $Postcode<br>Age: $Age<br><hr><br></center>"; $i++; } Sorry guys, it's probably really easy. Here's the code for Details.php <? include 'Config.php'; include 'OpenDB.php'; if(isset($_GET['Thumbnail'])) { $Thumbnail = $_GET['Thumbnail']; $result=mysql_query("SELECT * FROM PersonalTrainers WHERE Thumbnail='$Thumbnail'"); $row_result=mysql_fetch_assoc($result); } include 'CloseDB.php'; ?> Thanks Craig Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/#findComment-239805 Share on other sites More sharing options...
craig1978 Posted April 27, 2007 Author Share Posted April 27, 2007 Figured out the name thing an extra '<' before the variable Quote Link to comment https://forums.phpfreaks.com/topic/48917-mysqlphp-query/#findComment-239810 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.