Jump to content

trouble with pulling the right image


elrobbo6

Recommended Posts

So I am trying to pull the first image that was uploaded to the database.  But for some reason this only works part of the time and if you delete any image in the database it seems to just pic another another random one.  Any suggestions?

 

<?php

{

$row = getad();

header("Content-type: image/jpeg");

$pic = ($row['image']);

print "$pic";

}

 

function getad()

{

$ads = array();

mysql_connect("localhost","******","********");

mysql_select_db("users");

 

 

$query  = "SELECT image FROM image_ads";

$result = mysql_query($query);

 

$i = 0;

 

while($row = mysql_fetch_array($result))

{

  $i ++;

  $ads[$i] = $row;

}

 

$id = date("z");

$index = $id % $i + 1;

 

mysql_close();

return $ads[$index];

}

 

?>

 

Link to comment
Share on other sites

Do you have a field that auto increments in the database?  If you do, you can put the name of that field where I have "id" below, and it should work.  If you want to pull the last image that was uploaded, replace "ASC" with "DESC".

 

$query  = "SELECT image FROM image_ads ORDER BY id ASC";

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.