I have a database with a TEXT field, which could have just one paragraph, or as many as 50 paragraphs. More likely it will have more than 10. I also have another database table with a number of sponsors that could be 0-10. No more than 10 ever.
I need to find a way to have it where the text that is displayed will automatically insert one sponsor for every equal number of paragraphs.
Such as this. Say there are 3 sponsors and 10 paragraphs, I would like it to print 3 paragraphs, then insert a table with the first sponsor, then print another 3 paragraphs, then insert another table with the second sponsor, then print another 3 paragraphs, then the final sponsor table, and then the last paragraph.
It really does not have to be in between the paragraphs, I guess it could be between words, but how can I just find equal places to put the sponsors in the text?
Would it work to count the "length" of the text, then divide that by the number of sponsors, then find the next "space" after the first number?(Such as this:
The text field has a length of 3000 characters, and there are 3 sponsors, then there would be 1 sponsor after every 1000 characters.)
How would I find the next space between words, AFTER 1000 characters(in the above example)?
Or do you know of a better way to do this?
I would appreciate any tips on a way to do this.
Thank you!
Richard
Edited by BazB - fixed .sig div tags.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.