Jump to content


Photo

$id wont generate in the URL


  • Please log in to reply
4 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 12 June 2006 - 06:48 AM

<?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'];
?>
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"

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 12 June 2006 - 07:34 AM

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...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 12 June 2006 - 06:19 PM

[!--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.

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 12 June 2006 - 06:38 PM

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:

<?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>';
}

?>

Although I would not store the links, supposing they'll always the same, but only the id will change:

<?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>';
}

?>

~ D Kuang

#5 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 12 June 2006 - 07:42 PM

ah ok.

   echo '<a href="view.php?id=' . $row['id'] . '">' . $row['thumb'] . '<br /></a>';
that got me what i wanted, thanks alot.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users