I have a MySQL table "visit" that has colums: id, engine_id, useragent, ip, date. What's the easiest way to retrieve the data where you can print/manipulate it easily?
Right now I am using the below code but it only retrieves ONE record for some reason when there is 20-30 in the database.
You notice I am only printing back the useragent right now. This is because I don't understand how I could pull back all the needed columns at one time and be able to manipulate them freely.my $useragent = "SELECT useragent FROM visit WHERE engine_id = 'Junk'"; $sth = $dbh->prepare($useragent); $sth->execute() or die $dbh->errstr; my @row = $sth->fetchrow_array; foreach (@row) { print "<center>$_</center>"; }
Using the following code everything I need is in one glob of data @row. How am I supposed to created HTML tables in such a specific order when it's one massive variable?
One idea I had was demonstrated with the first code sample. I could run through all that code each time for each column and store it in @row1, @row2, @row3 etc. But that seems to be a ton of extra coding which is needed for something as ordered data printing like this. And then you'd have to worry about making sure all the variables' data matches up when you display it on the screen.my $data = "SELECT engine_id,useragent,ip,date FROM visit WHERE engine_id = 'Junk'"; $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; while (my @row = $sth->fetchrow_array) { print "$_<br>" for @row }
In short what I'm trying to do is print in a format like:
As much as I'd like code to do just that I'd really appreciate also having an explanation of what you did. I'd much rather understand it so I don't have to ask this again next time I do something like this.<td>COUNT (ID)</td> <td>UserAgent</td> <td>IP</td> <td>time</td> <td>< +/td><tr> ...... again ....
Thank you everyone.
In reply to printing records in MySQL by coldfingertips
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |