Jump to content

Archived

This topic is now archived and is closed to further replies.

newb

$id wont generate in the URL

Recommended Posts

[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"

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
ah ok.

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.