PC Pals Forum

Technical Help & Discussion => Website Design & Programming => Topic started by: psp83 on January 20, 2010, 19:34

Title: php advice needed
Post by: psp83 on January 20, 2010, 19:34
Hi all..

Simon told me to come post here from IDnetters.

I've been coding websites in PHP for over 10yrs now but today i have come across something i need help/advice for.

I have a client that has a website that allows users to upload ads.. width/height (10px,20px to 100px). These dimensions are in a drop down.

Now comes the tricky part.. they want the ads displayed on the home page just like the million dollar home page site (http://www.milliondollarhomepage.com/)

The only data i have to work with is the image and sizes.

Any ideas how i can do this?

Thanks in advance!
Title: Re: php advice needed
Post by: Clive on January 20, 2010, 19:39
Hi psp83 and  :welcome:  Sam is our resident expert on PHP and will be online later tonight.  He is working in Canada at the moment so his 'evening' is a bit later than ours!   :laugh:
Title: Re: php advice needed
Post by: psp83 on January 20, 2010, 19:44
hey,

thats cool, i'm in no rush at the mo, i have 3 weeks to find a solution.

Paul
Title: Re: php advice needed
Post by: Simon on January 20, 2010, 19:48
Hi Paul, glad you managed to fight your way in!  ;D  :welcome:

As Clive said, hopefully Sam should be able to help you with this.
Title: Re: php advice needed
Post by: Baz on January 20, 2010, 21:00
hey Paul, so youve had your arm twisted too eh?  ;)
Title: Re: php advice needed
Post by: sam on January 21, 2010, 03:15
ooh just like that page, eh?

Interesting problem - not sure why anyone would wanna do that but still.

The milliondollar website cheats... they make a large png file: http://www.milliondollarhomepage.com/img-pix/image-map.png?r=397

This could be done in imagemagik (what does the server run?) and then they overlay a grid..

Code: [Select]
<area onmouseover="d(this)" onmouseout="e(this)" shape="rect" coords="630,310,640,320" href="http://www.getpixel.net" title="getpixel.net, stock photography"/>
Do you have todo it in PHP?

I guess in php you could just make a grid of images, now you'd have to do some image location optimisation to get it like that though..  just need to create an array of images and loop over them in the html.

I'll have a think a bit more - I've been coding in python all day and a bit wiped now.
Title: Re: php advice needed
Post by: psp83 on January 21, 2010, 14:26
Thanks for the reply sam.

The server is PHP 5 with GD and not imagemagik :(

Do i have to do it in PHP ? Well to be honest no, It can be done in javascript aswell. But i'm limited to what i can work with here. I'm just doing extras to a site already coded.

I have an array of the images and sizes.

Code: [Select]
Array
(
    [0] => Array
        (
            [image] => ad30x70.jpg
            [width] => 30
            [height] => 70
        )

    [1] => Array
        (
            [image] => ad70x30.jpg
            [width] => 70
            [height] => 30
        )
)

Thats the only data i have to work with.

And to be honest with you.. I have no idea where to start with this.

Paul
Title: Re: php advice needed
Post by: sam on January 21, 2010, 15:08
well if you could take the data from the array then you could easily cast it into a grid (case below would just be 1 x 1) ..  in the below case each image is called photo*.jpg (* = 1 - 9), $image_path = the location of the images and $toptext = some kind of array or individual element that has the alt text for the image. ...

Code: [Select]
<?php

for($i=0$i<=9$i++) {

?>
<li> <a href="<?php echo $image_path?>photo<?php echo $i

?>
.jpg"><img src="<?php echo $image_path?>photo<?php echo $i?>.jpg"

alt="<?php echo $toptext?>" />   <img src="<?php echo $image_path

?>
photo<?php echo $i?>.jpg" alt="<?php echo $toptext?>" /></a> <br /> <?php }

?>


I'm unsure how todo this in a more random manner like in the website example... will have a think
Title: Re: php advice needed
Post by: psp83 on January 21, 2010, 15:59
Hi.

This is what I've got so far..

(https://www.pc-pals.com/smf/proxy.php?request=http%3A%2F%2Fimg63.imageshack.us%2Fimg63%2F3021%2Fgridx.jpg&hash=3af656ee0b5903d1bd43e5d0be439bf74a21576e)

Now just to remove the spaces to make it like million dollar website.

Paul
Title: Re: php advice needed
Post by: sam on January 21, 2010, 23:57
excellent, how did you generate the above?
Title: Re: php advice needed
Post by: psp83 on January 22, 2010, 02:19
Just simple html & php

Code: [Select]
<div id="grid">
<?php foreach($ad_array as $key=>$ad) : ?>
<img src="./<?php echo $ad['image']; ?>" width="<?php echo $ad['width']; ?>px" height="<?php echo $ad['height']; ?>px" />
<?php endforeach; ?>
</div>

Now just the tricky part.. removing the spaces and making the ads fit together. any ideas?
Title: Re: php advice needed
Post by: sam on January 22, 2010, 03:52
some kind of optimization code... hmmm, do you want it so it stays static?  you could just hard feed them in...

Or maybe you just produce the big image by grabbing all the smaller images, in gimp and just create an image map over the top?

There has to be some code to fit box into a bigger box..

I have to say this such an odd thing todo!
Title: Re: php advice needed
Post by: psp83 on January 22, 2010, 15:35
It cant be static. Has to be done on the fly as more ads are being added all the time.

User fills in the form, uploads the ad, pays for it and it becomes active.

I've been trying to google for some code/tips but its a hard thing to google for as i dont exactly know what to search for or call it  ???
Title: Re: php advice needed
Post by: Rik on January 22, 2010, 15:37
Could you not find a similar site and take a look at the page source, Paul?
Title: Re: php advice needed
Post by: psp83 on January 22, 2010, 15:42
Tried that with the million dollar home page script package you can download, its like looking for a needle in a haystack!

Plus most sites like this gives you the option to select where you want in the grid and you have more information then to use php GD to position the image. like in the million dollar home page, just create one large pic with image maps. But i dont have that to work with.. only thing i've got is the image and sizes :(

I think this part of the extras might have to get outsourced to a firm over seas or something.
Title: Re: php advice needed
Post by: Rik on January 22, 2010, 15:45
Good luck, Paul, it's way over my head.
Title: Re: php advice needed
Post by: sam on January 23, 2010, 04:02
I'll have another think tomorrow - I've been busy calibrating the Arecibo telescope all day and am now shattered.
Title: Re: php advice needed
Post by: Clive on January 23, 2010, 09:59
Will you have to return to Arecibo again this year? 
Title: Re: php advice needed
Post by: Rik on January 23, 2010, 12:20
Is that something like 'Torna a Surriento ', Clive? ;)
Title: Re: php advice needed
Post by: Clive on January 23, 2010, 12:47
Yes, but sung with a Spanish accent.   ;D
Title: Re: php advice needed
Post by: Rik on January 23, 2010, 12:50
Si. :)
Title: Re: php advice needed
Post by: Simon on January 23, 2010, 13:00
you called?
Title: Re: php advice needed
Post by: Rik on January 23, 2010, 13:08
Close.  ;D
Title: Re: php advice needed
Post by: sam on January 23, 2010, 17:15
Will you have to return to Arecibo again this year? 

hopefully, not sure though
Title: Re: php advice needed
Post by: sam on January 24, 2010, 19:35
I've been thinking about this problem a bit more...

How about this:

Have an array of the dimensions of the overall image.

Then when you add an image to the array change the values of the array to something say -9. Then you have an idea of what positions are used up.

Each time you add an new image find all values that aren't -9 then take the first x,y location that fits for the image input (I guess you'd need to also hunt down the first one that matches the same dimensions). As the loop is left add -9 to it.. and so on for new images. You could do the inverse to remove images.

Then have a final loop that prints out the html code of the images at the correct array positions.

I'd like to try and write the code too but I don't really have the time at the moment. I think the above would work but I'm not entirely sure.

You could possibly also produce the image on a on the fly with imagemagik. Just figure out ħow you would stick the images together in gimp and follow the same procedure...
Title: Re: php advice needed
Post by: psp83 on January 31, 2010, 14:29
Thanks Sam.

I'll be trying something this week and will let you know how it goes, just been too busy to try it yet  :(
Title: Re: php advice needed
Post by: psp83 on June 08, 2010, 12:49
I am pleased to say I think this problem is no more.

I'm working in "blocks" instead of pixels. So I have a db table thats 100x100 block, a 40x40px ad is a 4x4 block.

I have code that loops through vert & horz to check available blocks, if there is any then allocate the blocks with the ad id.

For display I can then take the first vert & horz number for each ad and use that to absolute position the ad on the page.
Title: Re: php advice needed
Post by: Rik on June 08, 2010, 13:01
I understood every other word, Paul. ;)
Title: Re: php advice needed
Post by: Simon on June 08, 2010, 13:05
I understood the first line.  :)
Title: Re: php advice needed
Post by: sam on June 08, 2010, 14:59
cool glad you got it working, if the page is public I'd love to take a look.
Title: Re: php advice needed
Post by: psp83 on June 08, 2010, 16:17
I understood every other word, Paul. ;)

I understood the first line.  :)

Hehe  :crazy:
Title: Re: php advice needed
Post by: psp83 on June 08, 2010, 16:18
cool glad you got it working, if the page is public I'd love to take a look.

Its not public yet but as soon as it is I'll post a link.
Title: Re: php advice needed
Post by: sam on June 08, 2010, 21:00
cool... would be good to see - glad you got it working.
Title: Re: php advice needed
Post by: psp83 on June 08, 2010, 22:24
Here's a screen grab of the ad area, sorry I cant show a whole screen shot but its not live yet.

Images are stacking nicely  ;D