Jump to content

$id wont generate in the URL


newb

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"
Link to comment
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...
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.