Jump to content

Need Help Setting Up Dynamic URL's


nbasso713

Recommended Posts

I've been working on this for the last few hours and haven't had much luck. Basically, every time you visit the index of my site a random image is shown. The images are stored in a directory, and i use a table to hold the id, name, and url of each image. When the index page is loaded a random int is chosen, and the id equal to the int prints the corresponding url for the image.

 

Now i'm trying to add the id into the url, "domain.com?img=1". I also need this url to always refer to the image in row 1.

 

My table is called uploaded_images and the columns are id(primary key), name, url.

 

I'm pretty lost, any help is greatly appreciated.

Link to comment
Share on other sites

Thanks for getting back to me, I can't tell if i'm over tired or just retarded but i'm still not having any luck.  :shrug:

Can someone please just hold my hand through this it's driving me crazy and it seems like it should be simple. here's an example of what i'm working with.

 

<?php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="****"; // Mysql password
$db_name="****"; // Database name
$tbl_name="uploaded_images"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$query = mysql_query(" SELECT max(id) AS id FROM uploaded_images ");
while ($row = mysql_fetch_assoc($query)) {
    $id = $row['id'];
}


$imgid = rand(18,$id);
$next = rand(18,$id);
while($next == $imgid){
		$next = rand(18,$id);
}



$ImageQuery = "SELECT name, url FROM uploaded_images WHERE id = '".$imgid."';";


$ImageResult = mysql_query($ImageQuery);

$ImageArray = mysql_fetch_array($ImageResult);
htmlspecialchars($_GET["name"]);
$ImageName = $ImageArray['name'];
      $url = $ImageArray['url'];
  
<html>
<head></head>
<body>
<h5>Click or Browse For Another Random Image</h5>
<p id="img"><a id="img" href="http://domain.com/test.php?img=<?php echo $next;?>">
<img src="<?php echo $url;?>"/>
</a></p>
</body>
</html>

?>

Link to comment
Share on other sites

<?php

 

$image = $_GET['img'];

 

$query = mysql_query("SELECT * FROM uploaded_images WHERE id LIKE $image");

while ($rows = mysql_fetch_array($query)) {

 

?>

 

<img src="<?php echo $rows['url']; ?>" />

 

<?php

 

}

 

?>

 

Is there anyway to have the page load to a ?img=# by default? I'm receiving an error if it's just  domain.com/test.php But if it's domain.com/test.php?img=1 for example, it works perfectly.

 

I eventually plan on moving all this to my index.php, so if someone just enters the domain i need it to redirect to a ?img=# by default, or the page will not load properly.

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.