newb Posted June 12, 2006 Share Posted June 12, 2006 [code]<?php$query = "SELECT * FROM `thumbnails` ORDER BY title ASC";$result = mysql_query( $query ); if ( !$result ) {die($query.'<br />'.mysql_error());while( $row = mysql_fetch_assoc( $result ) ) {echo '<a href="' . $row['link'] . '">' .$row['thumb'].'<br /></a>;$id = $row['id'];?>[/code]i want it to generate [a href=\"http://mysite.com/view.php?id=1\" target=\"_blank\"]http://mysite.com/view.php?id=1[/a] for example but instead it generates [a href=\"http://mysite.com/view.php?id=$id\" target=\"_blank\"]http://mysite.com/view.php?id=$id[/a]btw, data in the row link is "view.php?id=$id" Quote Link to comment https://forums.phpfreaks.com/topic/11766-id-wont-generate-in-the-url/ Share on other sites More sharing options...
.josh Posted June 12, 2006 Share Posted June 12, 2006 uh.. well first off, you don't have $row['id'] anywhere in your link. 2nd, are you saying that if you do this:echo $row['link'];it spits out this?"view.php?id=$id"??i'm gonna go on a hunch and tell you to put the $id = $row['id'] before the echo instead of after it. but that's just a hunch, cuz i can't see why on earth you would setup your db the way i kinda think you set it up... Quote Link to comment https://forums.phpfreaks.com/topic/11766-id-wont-generate-in-the-url/#findComment-44538 Share on other sites More sharing options...
newb Posted June 12, 2006 Author Share Posted June 12, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]are you saying that if you do this:echo $row['link'];it spits out this?"view.php?id=$id"??[/quote]yes.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]i'm gonna go on a hunch and tell you to put the $id = $row['id'] before the echo instead of after it. but that's just a hunch, cuz i can't see why on earth you would setup your db the way i kinda think you set it up...[/quote]ill try that thankxz. Quote Link to comment https://forums.phpfreaks.com/topic/11766-id-wont-generate-in-the-url/#findComment-44701 Share on other sites More sharing options...
poirot Posted June 12, 2006 Share Posted June 12, 2006 First, your code is missing some closing "}" and a single quote, this would give you some errors.Let me see if I got it, you are storing PHP code in the database? If you are, you should use:[code]<?php$query = "SELECT * FROM `thumbnails` ORDER BY title ASC";$result = mysql_query($query);if (!$result) { die($query . '<br />' . mysql_error());}while ($row = mysql_fetch_assoc($result)) { $id = $row['id']; eval("\$link = \"{$row['link']}\";"); echo '<a href="' . $link . '">' . $row['thumb'] . '<br /></a>';}?>[/code]Although I would not store the links, supposing they'll always the same, but only the id will change:[code]<?php$query = "SELECT * FROM `thumbnails` ORDER BY title ASC";$result = mysql_query($query);if (!$result) { die($query . '<br />' . mysql_error());}while ($row = mysql_fetch_assoc($result)) { echo '<a href="view.php?id=' . $row['id'] . '">' . $row['thumb'] . '<br /></a>';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11766-id-wont-generate-in-the-url/#findComment-44710 Share on other sites More sharing options...
newb Posted June 12, 2006 Author Share Posted June 12, 2006 ah ok.[code] echo '<a href="view.php?id=' . $row['id'] . '">' . $row['thumb'] . '<br /></a>';[/code]that got me what i wanted, thanks alot. Quote Link to comment https://forums.phpfreaks.com/topic/11766-id-wont-generate-in-the-url/#findComment-44740 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.