Jump to content

Dynamically changing a link in php to have it point to a external page


Go to solution Solved by scuttzz,

Recommended Posts

Hi all,

 

Need some guide line, im outputing images from a databse on a page, ive gotten to the point that the images show as i want them to however Im putting a link under each image. so my question is, is there a way to have a image link change depending on the image id, but that page that it points to is a separate page that is not connected to a database.

The thought process is as follows: admin uploades the image => image shows in a page with a link =>User clicks the link and it directs them to a page(example www.mysite.com/image_information/image1.php) again the links p[age is completely seperate, the image has an id.
Heres the code id have so far

PHP:

$uploadedImage = "";
$sql = mysql_query("SELECT * FROM products");
$imageCount = mysql_num_rows($sql); // count the output amount
if ($imageCount > 0) {
while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
             $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '
<div class="itemWrapper">
<a id="inventoryImage" href="product.php?id =' . $id .'"><img src="uploaded_images/' . $id . '.jpg"></a>
<div id="imageInfo">
<ul border="1">
<li><span>Date Added : ' . $date_added . '</span></li>
<li><a href="">Read more about this image</a></li>
</ul>
</div>
<div class="clear"></div>
</div>
'; 
    }
} else {
uploadedImage = "We have no images uploaded yet";
}

 

This line

<a id="inventoryImage" href="product.php?id =' . $id .'"><img src="uploaded_images/' . $id . '.jpg"></a>

Outputs the products image and the link to display the products information.

 

Are you saying some products information are not stored in the database. Those that are not stored in the database have static html pages defined for them?

Yes that's the jist of it.. The database has no information about the image in it, its just a table with 2 columns (id, image). I've created pages for each image that are not connected to the database itself. Do you think it would be a better option to add information to the database and not show it, and when the user chicks the link have the page change to the one with all the information instead? The reason why I'm going this route is the information about the image is rather long with jquery tabs involved.

You don't store the whole webpage in the database.

 

Each product you add to the database should contain just the raw information about it.

Such as

  • product id
  • image(s)
  • name
  • description
  • price (if applicable)
  • etc

Then in product.php you grab all the information about that product. Once you have got all data about that product you use PHP to generate the page.

 

Using the database to just store the product image and then coding static webpages for each product is not very efficient.

Edited by Ch0cu3r
  • Solution

Understandable, so ill only store information in the database, and call it where see fit. think im going to change my thoughts with this one, as getting a link to change depending on the image id and to make it link to a external page is a little out of my understanding at this point. Ill just store more information on the database and call it on the products.php? page. sorry for wasting your time. 

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.