Maybe(?) your query match to $identifier has extra spaces?

I will be willing to help you solve this if you want (later this week, not now), but I would need to know a bit more info.

Could you give me a sample of the input from the db (not the whole thing please), explain why you are querying based on 'user'=\"@user\", print out the select statement before querying, and print the results (as is) of each row fetched from the database.

It's possible that just doing this may help you solve the problem yourself.

UPDATE ... ignore above

Silly me, over lunch I realized what was wrong (at least I think that this is the problem).

When you query the database, you use a while loop. When a row is returned, you print the resulting CHECKED box. So far so good.

But, still within the while loop, a new query is performed, and there is no row returned. Now the $identifier is 'undef', and the while loop is exited.

So what happens next? The if statement is executed, and $identifier (which is 'undef' because of the last query to the db) is not equal to $id. The condition is true, and the unchecked box is printed.

There are certainly a lot better ways of doing this than what I am about to suggest, (it's a quick and dirty fix) but it should work.

PS: Note that I used a placeholder, which many people have mentioned in the other posts.
PSS: I don't have a db to play with, so I think that this works, but I actually haven't checked the syntax of the execute statement. Please check before using!

my $sth=$dbh->prepare( "SELECT Data,Identifier,User,Version FROM ddts, ". "delivery WHERE `User`=\"@user\" AND `Identifier`= ?" . " AND delivery.Data=ddts.Data"); foreach $id (@id){ $sth->execute($id); my $found = 0; while (my ($data,$identifier,$user,$version)=$sth->fetchrow_array ) { print "<tr><td><input type=\"checkbox\" name=\"rt\" CHECKED ". "value=\"$identifier\"> $identifier</td></tr>"; $found = 1; } unless ($found){ print "<tr><td><input type=\"checkbox\" name=\"rt\" ". "value=\"$id[$i]\"> $id[$i]</td></tr>"; } } $sth->finish;

In reply to Re: Re: Re: mysql database by Sandy
in thread mysql database by bory

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.