June 11, 200818 yr I’m trying to make this link work. The first page makes a list of bands. Each has a hyperlink to a page based on their band_id (key value of band_members table). The first page displays correctly and the link looks correct in the new page: http://localhost/bandinfo.php?id=31 where id=31 changes correctly depending on the artist clicked on. My code in the bandinfo.php page is not picking up the id value. The page will display correctly if I force the code to be id=31. How do I include the id from the previous page in this code? Thanks for any help... Page 1: artists.php $page_title = 'Artists'; require_once ('../mysqli_connect.php'); // Connect to the db. $q = "SELECT band_id, genera, band_name, music_description FROM band_members ORDER BY genera , band_name"; $r = mysqli_query($dbc, $q); $currentGenre = ''; while ($messages = mysqli_fetch_array($r, MYSQLI_ASSOC)) { if ($currentGenre != $messages['genera']) { echo "<h2>{$messages['genera']}</h2>\n"; $currentGenre = $messages['genera']; } echo "<a href=bandinfo.php?id={$messages['band_id']}><h5> {$messages['band_name']}</h5></a><br /> {$messages['music_description']}<br /><br />\n"; } mysqli_free_result ($r); mysqli_close($dbc); // Close the database connection. Page 2: bandinfo.php: session_start(); $page_title = 'Band Details'; require_once ('../mysqli_connect.php'); $q = "SELECT band_name AS bn, genera AS g, music_description AS md, biog AS b, gig_history AS gh, gig_future AS gf, reviews AS re FROM band_members WHERE band_id='$id'"; $r = @mysqli_query ($dbc, $q); if ($r) { // If it ran OK, display the records. // Fetch and print all the records: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo stripslashes(nl2br($row['bn'])); echo stripslashes(nl2br($row['g'])); echo '<h1>News</h1>'; echo stripslashes(nl2br($row['md'])); } mysqli_free_result ($r); } else { error messages …
June 12, 200818 yr Depending on your version of PHP, you may need to tell it specifically to get the ID from the URL and place it into a variable. In Page 2, stick this in before your SQL query. $id = ($_GET['id']); I find it's a good habit to do this whatever version/setup you're running. Just in case.
Create an account or sign in to comment