[PHP-DB] Select statement drops 10th digit during table lookup?
I hope this is something easy I am overlooking but here goes: I have a table called: country which has the following fields: FieldType ip_from double(11,0) ip_todouble(11,0) country_code char(2) country_name varchar(50) IP_FROM NUMERICAL (DOUBLE)Beginning of IP address range. IP_TONUMERICAL (DOUBLE)Ending of IP address range. COUNTRY_CODE CHAR(2) Two-character country code based on ISO 3166. COUNTRY_NAME VARCHAR(50) Country name based on ISO 31 Here are a few lines from the country table which starts at 33996344 and ends at: ip_from ip_to country_code country_name 33996344 33996351 GB UNITED KINGDOM 50331648 83886079 US UNITED STATES 94585424 94585439 SE SWEDEN 3714175488 3714175743 DK DENMARK 3715104768 3715629055 JP JAPAN 3717201920 3718840319 KR KOREA, REPUBLIC OF The IP_FROM and IP_TO fields of the database are numeric representations of the dotted IP address. The formula to convert an IP Address of the form A.B.C.D to an IP Number is: IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D So here is what I do in PHP: $resolvingip=sprintf("%u",ip2long($ip)); $resolved=$DB_site->query_first("SELECT * FROM country WHERE '$resolvingip' BETWEEN ip_from AND ip_to"); $resolvecountry = $resolved[country_code]; so I type in: 213.21.158.96 and $resolvingip shows as: 3574963808 when I check $resolved[ip_from] I find out the SELECT statement looks up this line: 335544320 369098751 US UNITED STATES instead of looking up this line: 3574956032 3574972415 IT ITALY which really makes me think the SELECT statement is dropping the last digit... I tried ip: 10.25.215.30 and $resolvingip shows as 169465630 which looks up correctly since it is only 9 digits. When I try ip: 68.109.155.135 $resolvingip shows as 1148033927 but the SELECT statement drops the last digit and goes to a 9 digit again: 114803392 Any help is greatly appreciated.. Thanks! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] How can I get the number of entries retrieved by a"SELECT - FROM"
On 12 Jun,2003 at 18:21 Becoming Digital wrote: > > The PHP "SELECT FROM" below (before snip) listed the expected data. > > Is there a way to get the digit "3" into a PHP variable > > $data = mysql_result($result,1,"name")); > > > > How do I trap or collect or save the digit "3" generated the > > mysql "SELECT COUNT(*)" statement below? > Or do SELECT COUNT(*) AS mycount ... which will give you a result set with, eg: an array key called 'mycount' that you can grab. Ronan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select statement drops 10th digit during table lookup?
On 13 Jun,2003 at 0:48 G & E Holt wrote: > $resolved=$DB_site->query_first("SELECT * FROM country WHERE > '$resolvingip' BETWEEN ip_from AND ip_to"); Don't think you should have the '' around the ip number. Does that help? Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select statement drops 10th digit during table lookup?
On Friday 13 June 2003 15:48, G & E Holt wrote: > I hope this is something easy I am overlooking but here goes: > > I have a table called: country which has the following fields: > > FieldType > ip_from double(11,0) > ip_todouble(11,0) > country_code char(2) > country_name varchar(50) Shouldn't you be using some INTEGER type instead of DOUBLE? An unsigned INT will just about handle it (2^32). -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* It seems like the less a statesman amounts to, the more he loves the flag. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select statement drops 10th digit during table lookup?
Here's how I did it when playing with this... Table definition:- CREATE TABLE ip_list ( ip_from double default NULL, ip_to double default NULL, country_code char(2) default NULL, country_name varchar(100) default NULL, KEY ip_from (ip_from,ip_to,country_code,country_name) ) TYPE=MyISAM; Basic code to query it (takes a parameter 'ip' as GET paramter):- "; echo "cn:".$data["cn"].""; echo "cc:".$data["cc"]; dbclose($conn); ?> HTH !! Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select statement drops 10th digit during table lookup?
Why not use the built-in conversion functions in mysql? >From the manual: INET_NTOA(expr) Given a numeric network address (4 or 8 byte), returns the dotted-quad representation of the address as a string: mysql> SELECT INET_NTOA(3520061480); -> "209.207.224.40" INET_ATON(expr) Given the dotted-quad representation of a network address as a string, returns an integer that represents the numeric value of the address. Addresses may be 4 or 8 byte addresses: mysql> SELECT INET_ATON("209.207.224.40"); -> 3520061480 Doug On Fri, 13 Jun 2003 10:19:32 +0100, Ronan Chilvers wrote: >Here's how I did it when playing with this... > >Table definition:- > >CREATE TABLE ip_list ( > ip_from double default NULL, > ip_to double default NULL, > country_code char(2) default NULL, > country_name varchar(100) default NULL, > KEY ip_from (ip_from,ip_to,country_code,country_name) >) TYPE=MyISAM; > >Basic code to query it (takes a parameter 'ip' as GET paramter):- > /* > IP Lookup script > * prints a country code and name for an ip in the $_GET array > */ > > //Vars & Constants > define("HOST","myhost"); > define("USER","myuser"); > define("PASS","mypassword"); > define("DB","ips"); > define("IP",$_GET["ip"]); > > // Functions > function dbconnect() { > if (($conn=mysql_pconnect(HOST,USER,PASS))===false) { > die("Couldn't connect to server"); > } > if (!mysql_select_db(DB,$conn)) { > die("Couldn't select database"); > } > return $conn; > } > function dbclose($conn) { > if (!mysql_close($conn)) { > die("Couldn't close database connection"); > } > return true; > } > function dosql($SQL) { > if (($result=mysql_query($SQL))===false) { > die("Couldn't do sql : $SQL"); > } > return $result; > } > > //Core > $SQL = "SELECT COUNTRY_NAME AS cn, COUNTRY_CODE AS cc FROM ips.ip_list WHERE > IP_NUM BETWEEN ip_from AND ip_to"; > > $conn = dbconnect(); > > $ip = "127.0.0.1"; > > $QSQL = str_replace("IP_NUM",sprintf("%u",ip2long(IP)),$SQL); > > $result = dosql($QSQL); > $data = mysql_fetch_array($result); > > echo "ip:".IP.""; > echo "cn:".$data["cn"].""; > echo "cc:".$data["cc"]; > > dbclose($conn); >?> > >HTH !! > >Ronan >e: [EMAIL PROTECTED] >t: 01903 739 997 >w: www.thelittledot.com > >The Little Dot is a partnership of >Ronan Chilvers and Giles Webberley > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: MySQL, PHP, and XML
Hello, On 06/12/2003 10:21 AM, Hardik Doshi wrote: Hi Manuel, Do you have any references for generating XML files from any of the persistent database? That depends on what you want to do. This class can generate arbitrary XML documents: http://www.phpclasses.org/xmlwriter This package can access many types of databases in a database independent manner: http://www.phpclasses.org/metabase --- Manuel Lemos <[EMAIL PROTECTED]> wrote: Hello, On 06/11/2003 11:53 PM, [EMAIL PROTECTED] wrote: Is there an automatic way to insert an XML file into a MySQL DB through say, Load Data InFILE? Or does one have to Pick apart the XML with PHP and insert data into the fields one by one, record by record? You may want to try this class: Class: MySQL to XML - XML to MySQL http://www.phpclasses.org/mysql_xml -- Regards, Manuel Lemos Free ready to use OOP components written in PHP http://www.phpclasses.org/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Time input formatting in PHP-12 hour clock
Hi, All-- Has anyone already solved the problem of how to get a time input from the user in people time (12-hour clock) and format it to be INSERTed in a mySQL time field? The mySQL time field is 24-hour and of course it can be formatted in the SELECT statement to be displayed as 12-hour for the user. But--presumably in PHP--I need the user to be able to input a time, then validate it as to whether it is complete (e.g., expresses AM or PM and evaluates correctly), then pass it into an INSERT statement into the time field of a database. I suspect this already exists, just can't find an example. TIA Dave Shugarts -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Time input formatting in PHP-12 hour clock
Hi David Comments inline... On 13 Jun,2003 at 10:26 David Shugarts wrote: > PHP--I need the user to be able to input a time, then validate it as to > whether it is complete (e.g., expresses AM or PM and evaluates correctly), > then pass it into an INSERT statement into the time field of a database. > How about using a radio button for the AM / PM selection on the form? Then if its PM you can simply adjust the hour figure accordingly to convert to 24hr (add 12 or whatever) and then concatenate a string together for the INSERT, eg: HHMMSS. Validating is just a matter of making sure the numbers are sanea few if then's should do the trick. Alternatively use select dropdowns on the form to only allow a user to choose a valid time. Its up to them to get the RIGHT time, of course !!! If you go the validation route I think I would probably use a little javascript snippet to validate the numbers before the form is submitted. Personal preference really... Does this help at all? Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Time input formatting in PHP-12 hour clock
There are several ways you can do it. But the first step is to translate to 24 hour time. So the first thing we have to check is if the am or pm flag was set. Then add 12 hours or leave as is OR set the hour to 00 (midnight). Something like this may help: Switch(strtoupper($ampm_flag)) { // if it's am all we have to worry about is midnight because all hours before noon in 12 hour time //are the same as 24 except midnight. Case "AM": { If ($hour = 12) { $hour = 0; } break; } case "PM": { /* now we gotta check to see if the pm time is smaller that 12 if so add 12 hours if not leave it. Because the only thing that is the same in the afternoon between 12 and 24 hour time is 12 PM */ if ($hour < 12) { $hour += 12; } } /* now sprintf into mysql format. I'm more familiar with PERL's sprintf so check the PHP docs and make sure I got this right */ $mysqldate = sprintf ("%04d-%02d-%02d %02d:%02d:%02d", $year, $month, $day, $hour, $minute, $second); /*Then insert $mysqldate into your date field. You could also concatinate, just make sure that your digits are the right length, you could also check the mysql manual for the different formats of inserting datetimes. There are less friendly ways of inserting datetimes. */ /* by the way this was sort of done on the fly and was not tested. If anyone encounters any bugs, let me know */ Carl. -Original Message- From: David Shugarts [mailto:[EMAIL PROTECTED] Sent: Friday, June 13, 2003 10:27 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Time input formatting in PHP-12 hour clock Hi, All-- Has anyone already solved the problem of how to get a time input from the user in people time (12-hour clock) and format it to be INSERTed in a mySQL time field? The mySQL time field is 24-hour and of course it can be formatted in the SELECT statement to be displayed as 12-hour for the user. But--presumably in PHP--I need the user to be able to input a time, then validate it as to whether it is complete (e.g., expresses AM or PM and evaluates correctly), then pass it into an INSERT statement into the time field of a database. I suspect this already exists, just can't find an example. TIA Dave Shugarts -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Keeping entries of a select-box after submitting the form
Hi everyone, Well, I have already formulated my problem several times, always in a different way, but yet I have no solution. I try to say it as easy as it gets: I simply want one specific selction-box to 'keep' ALL options present after having submited the form! I'm thinking about a variable or something that contains all that options, and not just only ONE like the value-variable. I hope this is clear now. Regards, André -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Keeping entries of a select-box after submitting the form
What you can do is replicate all s with hidden fields: Al di Meola John McLaughlin ... ... But I fail to see why so doing would be useful. Your dynamic form is created after some query; therefore why not simply call the same query after submission to obtain all possible values of the options? Or perhaps I failed to understand your problem. HTH Ignatius _ - Original Message - From: "André Sannerholt" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, June 13, 2003 6:42 PM Subject: [PHP-DB] Keeping entries of a select-box after submitting the form > Hi everyone, > > Well, I have already formulated my problem several times, always in a > different way, but yet I have no solution. > > I try to say it as easy as it gets: > > I simply want one specific selction-box to 'keep' ALL options present after > having submited the form! > > I'm thinking about a variable or something that contains all that options, > and not just only ONE like the value-variable. > > I hope this is clear now. > > Regards, > > André > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Problem with 4.3.2
Interesting. They say the ISAPI module isn't production quality yet... we use it, though, w/o problems. We're running IIS on Win2000 and php 4.3.2. Does it work besides the phpinfo() problem? Jake LandEZ "Ryan Jameson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] More info... I only get that message in ISAPI mode. :-\ <>< Ryan -Original Message- From: Ryan Jameson (USA) Sent: Thursday, June 12, 2003 11:10 AM To: [EMAIL PROTECTED] Subject: Problem with 4.3.2 When I change over to 4.3.2 I get this message from phpinfo(); The operating system cannot run %1. ... any ideas? Thanks... <>< Ryan Ryan Jameson Software Development Services Manager International Bible Society -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] addslashes, stripslashes, htmlspecialchars
Hi this is about PHP commands even though has mysql too. I go to mysql board when I find one they said MySQL is not necessarily PHP driven and if I want PHP specific questions to go to a PHP list. How do you deal with forms, db storage of the data and calling it up in a form to edit? The online tutorials I have covered to not address this except with addslashes on one of them. My web page broke when I added a hyperlink in the description because of the ' Previously: used .asp and always set the db in a way similar to parameters? in MySQL Sometimes I did urlencode() on a get string to make the spaces and other characters work. tried addslashes and noticed it does add them, right in the db. Is this the standard? add and remove slashes? other thing confusing me is the htmlentities which may do this better? Thanks, Steve __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Strange phpmyadmin 2.2.3 bug?
Hi there everyone, I'm trying to insert the below text into phpmyadmin, and it inserts fine, but when I try to access it via PHP it doesn't access it, and via phpmyadmin 2.2.3 I can't delete it OR edit it, so is there any illegal character in the below text that you can see? I put it into a text block thinking that the HTMl caused a problem but it doesn't. Anyway help would be appreciated as it's driving me nuts :-) Chris Antigua claim to have a different beach for every day of the year although we have not visited them all the islands many beautiful soft sandy beaches and coves certainly constitute its main attraction. The most popular tourist resorts have hotels located either on beaches or close by many of them taking their names from the beaches. However for the more energetic there is plenty to see and do away from the beaches. The island is rich in colourful bird and insect life; off-shore beneath the waters of the Caribbean are splendid tropical fish and coral and there are several sites of historic interest.IntroductionAntigua Barbuda comprises three islands; Antigua Barbuda and Redonda. All low-lying and volcanic in origin they are part of the Leeward Islands group in the northeast Caribbean. Antiguas coaantiguaine curves into a multitude of quaint coves and harbours there are more than 365 beaches of fine white sand fringed with swaying palms trees. The islands highest point is Boggy Peak (402m 1318ft); its capital is St Johns. Barbuda lies 40km (25 miles) north of Antigua and is an unspoiled natural haven for wild deer and exotic birds. Its 8km-long (5-mile) beach is reputed to be amongst the most beautiful in the world. The islands village capital Codrington was named after the Gloucestershire family that once leased Barbuda from the British Crown for the price of one fat pig per year. There are excellent beaches and the ruins of some of the earliest plantations in the West Indies. The coastal waters are rich with all types of crustaceans and tropical fish. Redonda smallest in the group is little more than an uninhabited rocky islet. It lies 40km (25 miles) southwest of Antigua. An excursion to Great Bird Island can be made from Dickenson Bay. Many hotels offer excursions in glass-bottomed boats for a leisurely view of the reef. A restored pirate ship sails around the island and takes passengers for day or evening trips; food unlimited drink and entertainment are included.Nelsons Dockyard in English Harbour is one of the safest landlocked harbours in the world. Admirals Nelson Rodney and Hood as a safe base used it for the British Navy during the Napoleonic Wars. Clarence House overlooking Nelsons dockyard was once the home of the Duke of Clarence later King William IV. It is now the Governor Generals summer residence and is periodically open to visitors. Dows Hill Interpretation Centre provides visitors with a good overview of the island s history including information on the early Amerindians and the impact of slavery on Antiguas culture and economy.Shirley Heights and Fort James are two examples of the efforts made by the British to fortify the colony during the 18th century. Shirley Heights was named after General Shirley later Governor of the Leeward Islands in 1781. General Matthew erected one of the main buildings known as the Block House as a stronghold in the event of a siege in 1787. Close by is the cemetery containing an obelisk commemorating the soldiers of the 54th Regiment.St Johns Cathedral appears on postcards and in almost all visitors photographs. The church was originally built in 1683 but was replaced by a stone building in 1745. An earthquake destroyed it almost a century later and in 1845 the cornerstone of the present Anglican cathedral was laid. The figures of St John the Baptist and St John the Divine erected at the south gate were supposedly taken from one of Napoleons ships and brought to the island by a British man-of-war.The Market is in the west of St Johns and makes a lively and colourful excursion especially on busy Saturday mornings its ideal for purchasing locally hand crafted goods and souvenirs.Indian Town one of Antiguas national parks is at the northeastern point of the island. Breakers roaring in with the full force of the Atlantic behind them have carved Devils Bridge and have created blow-holes with foaming surf.A lake now monopolises the countryside in the centre of Antigua. The result of the Potworks Dam it is Antigua's largest artificial lake with a capacity of one thousand million gallons.Fig Tree Drive is a scenic route through the lush tropical hills and picturesque fishing villages along the southwest coast. Taxis will take visitors on a round-trip. At Greencaantiguae Hill there are megaliths said to have been erected for the worship of the Sun God and Moon Goddess. Parham in the east of the island is notable for its octagonal church built in the mid-18th century, which still retains s
Re: [PHP-DB] addslashes, stripslashes, htmlspecialchars
The functions you're wondering about are designed for dealing with inserting user input into a database. If you have a form in which someone can enter text, you need to process the input with addslashes() in case the user input contains quotes. htmlspecialchars() and htmlentities() have similar uses. If your webpage broke because a hyperlink in the database included quotes, you need to either manually add slashes to the text in the database or re-write your form processing script to include addslashes() and insert the data again. Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: "Steve B." <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, 13 June, 2003 19:22 Subject: [PHP-DB] addslashes, stripslashes, htmlspecialchars Hi this is about PHP commands even though has mysql too. I go to mysql board when I find one they said MySQL is not necessarily PHP driven and if I want PHP specific questions to go to a PHP list. How do you deal with forms, db storage of the data and calling it up in a form to edit? The online tutorials I have covered to not address this except with addslashes on one of them. My web page broke when I added a hyperlink in the description because of the ' Previously: used .asp and always set the db in a way similar to parameters? in MySQL Sometimes I did urlencode() on a get string to make the spaces and other characters work. tried addslashes and noticed it does add them, right in the db. Is this the standard? add and remove slashes? other thing confusing me is the htmlentities which may do this better? Thanks, Steve __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP transfer variable question?????
PHP transfer variable question? My program is ok in apache_1.3.19 and php-4.1.2£¬but when I change over to php_4.3.2 and apache_1.3.27,I can't get variable¡£ code: //newsList.php: $querystring = "SELECT id,title FROM $nTable ORDER BY id DESC LIMIT 3"; $result = mysql_query($querystring) or die ("can't query£¡£¡£¡"); while ($row = mysql_fetch_row($result)){ echo "$row[1]"; } code: //show.php $querystring = "SELECT * FROM $nTable WHERE id='$id'"; $result = mysql_query($querystring) or die ("can't query£¡£¡£¡"); echo $querystring; //test while ($row = mysql_fetch_row($result)) echo display£º SELECT * FROM news_tb WHERE id='' ?? why is empty??? $id can't receive! How to resolve it?? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php