1

Topic: A multiple URI question

Been trying to figure out for a few days which may the best way to approach this one, but still unsure, so thought I would ask for advice. smile

Have a script with an input field for a single URI, at the moment. Wanting to add the possibility of adding extra URI's so that if the primary or any of the other URI's listed for that item are not available, the lot of them can be looped through until one is found which is available.

Hence the question. Would I be best extending the size of that single column in the db, and entering all the URI's into that single field, suitably separated by a comma or such, or would I be better placed giving each URI it's own separate field, so to speak, and keeping them completely separate?


Cheers,

Matt

Re: A multiple URI question

The second option, but with a table set up so that you add a new row for each one, not a new column if you start exceeding a certain number tongue

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

3 (edited by MattF 2008-01-27 16:22)

Re: A multiple URI question

Cheers. With the db side of things not being my strongpoint, big_smile what exactly would be the method for doing that? Am I correct in thinking that means to create a duplicate entry in the table with regards to the download name and such, but with just the download URI being distinctly separate in each one? i.e: use the same method as creating a completely new entry into the table, so that it's technically an exact copy of the primary entry but with just that one difference of the URI? (Apologies if this seems like another of my completely dense mode questions). big_smile


Cheers Smartys. smile

Re: A multiple URI question

OK
So, lets say you have a downloads table. It has an ID, a name, maybe filesize, number of downloads, etc.
Then you would create a download_uris table. That would have at least two columns, one being the ID of the download in the downloads table and the other being the URI.

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

5

Re: A multiple URI question

Cheers. I understand now. smile I was having one of my slow moments again there. big_smile

Thanks again. smile

6

Re: A multiple URI question

Just been having a look. That method will work with hardly any alteration on the actual download script. smile

The admin script will be slightly more work. That one works roughly along the same lines as the admin_forums script, (which it's derived from). If I create an id column in that new table, (along with the download_uri and download_id columns), with an incrementing count, that will also allow me to keep them in order of how they were entered, (and hence their priority), when looping through them, if I actually create the entries in order of preference too, will it not?

Re: A multiple URI question

Yes. You could also just have the equivalent of disp_position wink

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

8

Re: A multiple URI question

Smartys wrote:

Yes. You could also just have the equivalent of disp_position wink

So that I could order them to suit? big_smile

Could I just ask one last question? If I had something along the lines of the following:

<input type="text" name="alternates['.$cur_uri['id'].']"

would that, when I extract the _POST['alternates'] array, give me keys in the array which match those original id's, or would the keys in the post array be sequential?


Thanks once again. smile

Re: A multiple URI question

The keys for alternatives are the original IDs in that case, yes

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

10

Re: A multiple URI question

Cheers. smile

Re: A multiple URI question

MattF wrote:

would I be better placed giving each URI it's own separate field, so to speak, and keeping them completely separate?

FWIW, WordPress uses separate fields (in its postmeta table).

12

Re: A multiple URI question

That's the route I've gone down too. smile Just a few little tweaks and checks to make, and then it should hopefully be ready for testing. big_smile

13

Re: A multiple URI question

Just wondered if I might ask a small favour? smile I've got this script on test now, and things appear to be functioning as expected, (thanks again Smartys), smile but just wondered, if I popped the code up, if someone might be willing to give it a quick once over and double check that I haven't made any schoolboy type mistakes? big_smile

14

Re: A multiple URI question

Just on a related note, is there a way to define the maximum amount of time that a single command can run, before being terminated? On the loop script for the multiple URI's, it does a fopen just to check that the file is available and the server is responding/accepting connections. If there are several URI's, I'd prefer to limit it to X seconds per location, to counter problems such as DNS not resolving and such, which could cause things to take a while otherwise.

Re: A multiple URI question

Use fsockopen instead of fopen, that allows you to set a timeout

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

16

Re: A multiple URI question

Cheers. smile Found out I needed to use fsockopen to workaround a minor ftp glitch too, so it's made things quite a bit easier. big_smile