Jump to content

superkingkong

Members
  • Posts

    46
  • Joined

  • Last visited

Everything posted by superkingkong

  1. thanks, i managed to figure it out. I must use alias what i did earlier was, using inet_ntoa on select statement, then on displaying, i use $row['ipaddress'], which is not working. after using expression with alias, AS IP, no problem now thanks
  2. Basically any time you use an expression. thank you for the info
  3. thanks a lot i've learnt some thing new today btw, how do i know when do i need to use alias or like the one above ? thanks.
  4. If you converted all the row to integer you don't need inet_ntoa() anymore. Except maybe when you want to insert new row. right now, it's integer in mysql, but i need to show the result on the web page. so, by just pulling it straight it out, it only display 10 int. how can i use the NTOA or ATON to display it as dotted ip address (on mysql side). thanks.
  5. hmm... strange. I'm using datetime as the datatype, and the field name is datetime initially i was using timestamp, but changed it to datetime. $result = mysql_query("SELECT id, referrer, DATE_FORMAT(datetime, '%W %M %Y'), timezone, ipaddress, hostname, page, useragent FROM weblog ORDER BY id DESC"); echo "<table border=2>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td><a href="' . $row['referrer'] . '">Referrer</a> 22</td>'; echo "<td>" . $row['datetime'] . " (" . $row['timezone'] . ") 33</td>"; echo "<td>" . $row['page'] . " 44</td>"; echo "</tr>"; echo "<tr>"; echo "<td>" . long2ip($row['ipaddress']) . " </td>"; echo "<td>" . $row['hostname'] . " </td>"; echo "<td>" . $row['useragent'] . " </td>"; echo "</tr>"; } echo "</table>";
  6. hi guys, I'm trying to display the datetime field with a particular format, unfortunately it is not showing anything using the date_FORMAT () function. if i remove the date_FORMAT () function, it is displaying YYY-MM-DD HH:MM:SS here is my select statement. $result = mysql_query("SELECT id, referrer, DATE_FORMAT(datetime, '%W %M %Y'), ipaddress, hostname, page, useragent FROM weblog ORDER BY id DESC"); would appreciate if you can please help, thanks.
  7. thank you very much I did backup my table earlier i knew that i'll do something wrong anyway, i have another question, now that everything is in the right order, i'm trying to display the table. Unfortunately, the ipaddress field is not showing anything (if i use the INET_NTOA()), but it shows integer if i use without the inet_ntoa function. Appreciate if you could help further, thanks. <?php $result = mysql_query("SELECT id, INET_NTOA('ipaddress'), referrer, datetime, page, hostname, useragent FROM weblog ORDER BY id DESC"); echo "<table border=2>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td><a href="' . $row['referrer'] . '">Referrer</a> </td>'; echo "<td>" . $row['datetime'] . " (" . $row['timezone'] . ") </td>"; echo "<td>" . $row['page'] . " </td>"; echo "</tr>"; echo "<tr>"; echo "<td>" . $row['ipaddress'] . " </td>"; echo "<td>" . $row['hostname'] . " </td>"; echo "<td>" . $row['useragent'] . " </td>"; echo "</tr>"; } echo "</table>"; ?>
  8. thanks for the reply. i've done a script, it ran successfully, but when i look at the table, the ipaddress field is showing the same value "1176924178" for all the 2000+ records. is it supposed to be like that? or is my logic wrong? i'm just a newbie in PHP would appreciate if someone could please help. below is the code: btw, i've tried the INET_ATON or the ip2long, both also showing the same result. All ips int are the same. As you suggested, i'm doing it on a varchar(15) datatype field. It is still the same result after i converted it to int(12) unsigned $result = mysql_query("SELECT * FROM weblog"); while($row = mysql_fetch_array($result)) { $ipaddress = ip2long($row['ipaddress']); // $upd = mysql_query("UPDATE weblog SET ipaddress = INET_ATON('$ipaddress')"); $upd = mysql_query("UPDATE weblog SET ipaddress = $ipaddress"); if (!$upd) { echo "<br />Failed to update"; } else { echo "<br />Success!"; } } ?>
  9. hi guys, i have a table with ip address as varchar15 datatype. I need to convert it to int. how can i do that? appreciate your help, thanks.
  10. thanks. That means, if i want specific date and time format, i won't be able to use the timestamp/datetime for mysql, right? in my case above, i will have to create a varchar field of 38? thanks
  11. thanks for the fast reply. so, the date(... ) will be replacing now() - during insertion into mysql or it's only for displaying the date? and i still use now() to insert date? sorry, i'm new in php-mysql. i know the datetime format in mysql. just that, i'm not sure, after it is inserted into mysql in YYYY-MM-DD HH:MM:SS format, can i still change/manipulate the format for displaying purpose? thanks.
  12. Hi guys, I've managed to insert the timestamp into mysql using now() but to display the date on the report, i would like it to be displayed in this format. would that be possible? Thu, Apr 9, 2009 (CDT) at 02:49:52 PM i need it this way because previously i was using a flat text db, and all records have this format as the 'datetime' field. my second problem would be "importing" this text file into the same table. btw, the current table has the 'datetime' field of timestamp type. appreciate your help, thanks.
  13. thanks... it works btw, why you don't use numbers as get variables in URLs? i did a search and manage to find another function, query_string. is it the same or less reliable than get? thanks.
  14. Hi guys, how can I get certail value from a uri and do if statement? eg, url: http://geocities.com/~myusername/file.php?1 url: http://geocities.com/~myusername/file.php?2 url: http://geocities.com/~myusername/file.php?3 if ($_SERVER['REQUEST_URI'] == 1) do this elseif == 2 do this else do this I'm a newbie in php, appreciate if you could help me, thanks.
  15. sure... thanks for the help <?php $Page = (int)(!empty($_GET['page']))?htmlspecialchars($_GET['page']):1; $Entries = 20; // Open log file $logfile = "log.db"; if (file_exists($logfile)) { $fulllog = file($logfile); } else { die ("The log file doesn't exist!"); } $NumRecords = count($fulllog); $totalPages = ceil($NumRecords/$Entries); $end = $Entries*$Page; $start = $end-$Entries; $end = ($end > $NumRecords)?$NumRecords:$end; // Seperate each part in each logline $log = array(); for ($i = $start; $i < ($end); $i++) { $log[$i] = trim($fulllog[$i]); $log[$i] = explode('|', $fulllog[$i]); } echo "<p>Total Entries : " . count($fulllog) . "</p>"; echo "<br />"; // create first page link if($Page>2) { echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($Page==1).'"><< First</a> '; } else { echo '<< First '; } // create previous link if($Page>1) { echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($Page-1).'">< Prev</a> '; } else { echo '< Prev '; } // create intermediate links for ($n = 1; $n <= $totalPages; $n++) { echo "<a href='?page=".$n."' >$n</a>"; } // create next link if($Page<$totalPages) { echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($Page+1).'">Next ></a> '; } else { echo 'Next > '; } // create last page link if($Page<$totalPages && $Page!=($totalPages-1)) { echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.($totalPages).'">Last >></a>'; } else { echo 'Last >>'; } echo '<p></p>'; // Show a table of the logfile echo '<style type="text/css"> body { background-color: #000; color: #ffff80; text-align: center; font-family: "Trebuchet MS", "Times New Roman", Arial, Times, serif; font-size: 13px; } .wrapper { width: 90%; text-align: center; margin: 0 auto; } a { color: #33ccff; text-decoration: underline; } a:hover { text-decoration: none; } img { border: 0; } .italic { font-style:italic; } table { width: 100%; border-collapse: separate; text-align: center; margin: 0 auto; font-size: 13px; } td { background-color: #0f0f4f; padding: 3px; border: 1px ridge #ccc; vertical-align: top; } td.a { width: 12%; } td.b { width: 32%; } td.c { width: 56%; border: 1px ridge #ccc; } td.d { background-color: #000; } </style>'; echo '<div class="wrapper">'; echo '<table>'; foreach ($log as $logline) { if ($logline['1'] == '') { echo '<tr>'; echo '<td colspan="2"><b>' . $logline['2'] . '</b></td>'; echo '<td class="c"><span class="italic"> ' . htmlspecialchars(urldecode($logline['5'])) . '</span></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="a"><b>IP Address</b><br /><span class="italic">' . $logline['0'] . '</span></td>'; echo '<td class="b"><b>Hostname</b><br /><span class="italic">' . $logline['4'] . '</span></td>'; echo '<td class="c"><b>Browser/OS</b><br /><span class="italic">' . $logline['3'] . '</span></td>'; echo '</tr>'; echo '<tr><td class="d" colspan="3"></td></tr>'; } else { echo '<tr>'; echo '<td class="a"><a href="' . htmlspecialchars(urldecode($logline['1'])) . '"><b>Referer</b></a></td>'; echo '<td class="b"><b>' . $logline['2'] . '</b></td>'; echo '<td class="c"><span class="italic"> ' . htmlspecialchars(urldecode($logline['5'])) . '</span></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="a"><b>IP Address</b><br /><span class="italic">' . $logline['0'] . '</span></td>'; echo '<td class="b"><b>Hostname</b><br /><span class="italic">' . $logline['4'] . '</span></td>'; echo '<td class="c"><b>Browser/OS</b><br /><span class="italic">' . $logline['3'] . '</span></td>'; echo '</tr>'; echo '<tr><td class="d" colspan="3"></td></tr>'; } } echo '</table></div>'; ?>
  16. i can't edit my previous post. i have managed to figured out the previous/next link. but i'm stuck with the.. when i'm on page 3, page 3 will not be hyperlinked. would you be able to help, please? thank you.
  17. thanks a lot it is displaying the right thing about the page link, instead of 1 2 3 do u know how can i display something like 1 2 3 ... Next > Last Page >> or the < Previous and << first page? and if i'm on page 3, page 3 will not be hyperlinked. thank you very much
  18. thanks. it is still displaying 10 records on the last page. but right now, it is getting last five values from page 5th, and repeat it in page 6 as first five values, then follow by the real five values of page 6th as the last five values.
  19. thanks, the pagination is working, but there is a slight problem. for eg, i have 55 records, so, it displays 6 pages (10 records/page) on the 6th page (last page), after the last 5 records, the script continues to display the "title of the column" until it reaches "10" (the count of $Entries), without the value, since the record ends at 55, if u know what i mean. example is here: http://premium.sfdns.net/~superkin/logv.php?page=6 anyway to prevent that?
  20. no, I just used the same code on post#2 as you posted. where do i need to update this code? $Page = (int)(!empty($_GET['page']))?$_GET['page']:1; ? pardon me for my lack of knowledge in php. update: i managed to get the link (page number) to display after i change one of the variable: is it correct?
  21. somehow, when i type the url?page=2 ..., it is still showing the same page.
  22. Hi, i did something like this for ($n = 1; $n <= $totalPages; $n++) { echo "<a href='?page=".$n."' >$n</a>"; } i think it's wrong, because it's not displaying anything Sorry, i'm not good at programming.
  23. hi, thanks for the reply. it is displaying according to the $Entries. Where can i get the link to the following page? thanks.
  24. Hi guys, I have a flat text database file with about 200 over records. How can i paginate them? Appreciate if you can help me out, thanks. Below is the script to get the records from the file <?php // Open log file $logfile = "log.db"; if (file_exists($logfile)) { $handle = fopen($logfile, "r"); $log = fread($handle, filesize($logfile)); fclose($handle); } else { die ("The log file doesn't exist!"); } // Seperate each logline $log = explode("\n", trim($log)); // After that it may be useful to get each part of each logline in a separate variable. // This can be done by looping through each logline, and using explode again: // Seperate each part in each logline for ($i = 0; $i < count($log); $i++) { $log[$i] = trim($log[$i]); $log[$i] = explode('|', $log[$i]); } echo "<p>Total Entries : " . count($log) . "</p>"; // Show a table of the logfile echo '<style type="text/css"> body { background-color: #000; color: #ffff80; text-align: center; font-family: "Trebuchet MS", "Times New Roman", Arial, Times, serif; font-size: 13px } .wrapper { width: 90%; text-align: center; margin: 0 auto; } a { color: #33ccff; text-decoration: underline; } a:hover { text-decoration: none; } img { border: 0; } .italic { font-style:italic; } table { width: 100%; border-collapse: separate; text-align: center; margin: 0 auto; font-size: 13px } td { background-color: #0f0f4f; padding: 3px; border: 1px ridge #ccc } td.a { width: 12%; } td.b { width: 32%; } td.c { width: 56%; } td.d { background-color: #000; } </style>'; echo '<div class="wrapper"><table>'; foreach ($log as $logline) { if ($logline['1'] == '') { echo '<tr>'; echo '<td colspan="2"><b>' . $logline['2'] . '</b></td>'; echo '<td class="c"><span class="italic">' . htmlspecialchars(urldecode($logline['5'])) . '</span></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="a"><b>IP Address</b><br /><span class="italic">' . $logline['0'] . '</span></td>'; echo '<td class="b"><b>Hostname</b><br /><span class="italic">' . $logline['4'] . '</span></td>'; echo '<td class="c"><b>Browser/OS</b><br /><span class="italic">' . $logline['3'] . '</span></td>'; echo '</tr>'; echo '<tr><td class="d" colspan="3"></td></tr>'; } else { echo '<tr>'; echo '<td class="a"><a href="' . htmlspecialchars(urldecode($logline['1'])) . '"><b>Referer</b></a>'; echo '<td><b>' . $logline['2'] . '</b></td>'; echo '<td class="c"><span class="italic">' . htmlspecialchars(urldecode($logline['5'])) . '</span></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="a"><b>IP Address</b><br /><span class="italic">' . $logline['0'] . '</span></td>'; echo '<td class="b"><b>Hostname</b><br /><span class="italic">' . $logline['4'] . '</span></td>'; echo '<td class="c"><b>Browser/OS</b><br /><span class="italic">' . $logline['3'] . '</span></td>'; echo '</tr>'; echo '<tr><td class="d" colspan="3"></td></tr>'; } } echo '</table></div>'; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.