mitman Posted July 28, 2009 Share Posted July 28, 2009 I have created a page where data is displayed based on what is in the url/id. For example, if a link is clicked for www.example.com/resultspage.php?uniqueid=2, the resultspage.php shows the unique id, in this case 2. What I am trying to do is display the information from the mysql table that has that specific uniqueid, 2. Here is the code for the data page, where the links are located: <?php include 'testphpconnect.php'; $result = mysql_query( "SELECT * FROM `data` ORDER BY `data` . `pets` ASC LIMIT 0, 30" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<center><table width=800 border=1><tr><td><font face=arial size=2/>Full List</td></tr></table></center>"; print "<center><table width=800 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "<td><font face=arial size=2/>$field</font></td>\n"; print "</tr>\n"; } print "</table></center>\n"; $query = mysql_query("SELECT * FROM data ORDER BY pets DESC"); while ($row=mysql_fetch_array($query)) { echo "<a href='http://localhost/forms/resultspage.php?uniqueid=$row[uniqueid]'>$row[name] $row[pets]</a> <Br>"; } ?> As you can see, there is a table that displays all the information in the database, and then links, which are created using the unique ids are displayed as "Name Pet". Here is the code for the results page: <?php include 'testphpconnect.php'; if ( isset($_GET['uniqueid']) ) { $uniqueid = $_GET['uniqueid']; // use the value in $uniqueid to pull from the db } else { // no tutorial was specified, do some error handling } echo "$uniqueid <Br>"; echo"<a href='http://localhost/forms/datapage.php'>Back</a> <Br>"; $sql = 'SELECT comments FROM data WHERE uniqueid = $uniqueid'; $result = mysql_query($sql, $link); if (!$result) { echo "DB Error, could not query the database\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_assoc($result)) { echo $row['comments']; } mysql_free_result($result); ?> It echoes the uniqueid fine, even with the variable. However, when I use the same variable in the 'where' clause, it doesn't work and results in an error. If I put a static id in, like 1 or 2, it displays the entry corresponding to that id. But I want the data displayed to change based on the id requested. Basically, I am trying to generate a permalink to an archives page for an entry in the MYSQL database. I feel like the solution is very simple but I just started learning php and can't seem to figure it out. I've looked everywhere to no avail, so any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/167743-solved-displaying-info-from-mysql-table-based-on-urluniqueid/ Share on other sites More sharing options...
mmarif4u Posted July 28, 2009 Share Posted July 28, 2009 $sql = "SELECT comments FROM data WHERE uniqueid = '$uniqueid'"; $result = mysql_query($sql, $link) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/167743-solved-displaying-info-from-mysql-table-based-on-urluniqueid/#findComment-884572 Share on other sites More sharing options...
mitman Posted July 28, 2009 Author Share Posted July 28, 2009 I cannot believe I didn't see that. I'm such a noob. I was looking all over for a solution when it was right under my nose. Thanks so much!!! Quote Link to comment https://forums.phpfreaks.com/topic/167743-solved-displaying-info-from-mysql-table-based-on-urluniqueid/#findComment-884578 Share on other sites More sharing options...
mmarif4u Posted July 28, 2009 Share Posted July 28, 2009 Glad you get the solution. Mark the thread as solved. Quote Link to comment https://forums.phpfreaks.com/topic/167743-solved-displaying-info-from-mysql-table-based-on-urluniqueid/#findComment-884581 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.