I have two snippets that work with different data in the script. What this does is I have 2 link sections. 1 section is just normal links and the other 1 is a referal section. Both of this sections can be added to, edited or removed when logged into the admin panel.

The feature that is NOT working on one of them is the sorter. Since you can create as many links or referers as you want, it prints out all the current ones in a form consisting of radio boxes from 1- (total number of items in this area) so you can chose which order they'll be displayed in on the site.

Ie.

ID | radio buttons to select order --------------------------- link1 1(*) 2() 3() 4() link2 1() 2(*) 3() 4() link3 1() 2() 3(*) 4() link4 1() 2() 3() 4(*)
From here, the admin can change the order in how this displays on the site any way they want.

This code was developed by a programmer a number of years ago and I can't figure it out. Can someone take a look at the 2 snippets below and tell me why the first one DOES work for the links but the one for the referrers prints out

ID | radio buttons to select order --------------------------- link1 1() 1() 1() 1(*) link2 1() 1() 1() 1(*) link3 1() 1() 1() 1(*) link4 1() 1() 1() 1(*)
Here's the LINKS section that prints out the form correctly
print "<center><table border='1'>\n"; print "<tr><td colspan=\"2\"><center><b>Adjust link di +splay order</b></center></td></tr>\n"; print "<form action='process.cgi' method='post'>\n"; print "<input type='hidden' name='section' value='links'>\n"; print "<input type='hidden' name='action' value='link_order'>\ +n"; $sql = "SELECT * FROM $links_table ORDER BY link_order ASC"; $sth = $dbh->prepare($sql); $sth->execute; $orders_list = join(":", @orders); $id_list = join(":", @ids); print "<input type='hidden' name='orders_list' value='$orders_ +list'>\n"; print "<input type='hidden' name='link_id_list' value='$id_lis +t'>\n"; while ($i = $sth->fetchrow_hashref) { my $id = $$i{"id"}; my $name = $$i{"name"}; my $order = $$i{"link_order"}; print "<tr><td>$name</td>\n"; print "<td>\n"; foreach $t_order (@orders) { print "$t_order <input type='radio' name='order_" . $i +d . "' value='$t_order'"; if ($order eq $t_order) { print " checked" } print ">"; } print "</td></tr>\n"; } print "<tr><td colspan=\"2\"><center><input type='subm +it'></center>\n"; print "</table></center>\n"; print "</form>\n";
Here's the code for the referer section that prints out all 1s instead of the correct sortable form.
print "<b><i>Adjust referrers display order</i></b><br>\n"; print "<table border='1'>\n"; print "<form action='process.cgi' method='post'>\n"; print "<input type='hidden' name='section' value='referrers'>\ +n"; print "<input type='hidden' name='action' value='link_order'>\ +n"; $sql = "SELECT * FROM $referrers_table ORDER BY link_order ASC +"; $sth = $dbh->prepare($sql); $sth->execute; $orders_list = join(":", @orders); $id_list = join(":", @ids); print "<input type='hidden' name='orders_list' value='$orders_ +list'>\n"; print "<input type='hidden' name='link_id_list' value='$id_lis +t'>\n"; while ($i = $sth->fetchrow_hashref) { my $id = $$i{"id"}; my $name = $$i{"name"}; my $order = $$i{"link_order"}; print "<tr><td>$name</td>\n"; print "<td>\n"; foreach $t_order (@orders) { print "$t_order <input type='radio' name='order_" . $i +d . "' value='$t_order'"; if ($order eq $t_order) { print " checked" } print ">"; } print "</td></tr>\n"; } print "</table>\n"; print "<input type='submit'>\n"; print "</form></center>\n"; }

READMORE tags added by Arunbear


In reply to dynamic radio sorting by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.