User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,552 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,469 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2652 | Replies: 3
Reply
Join Date: Oct 2007
Posts: 3
Reputation: nickw is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nickw nickw is offline Offline
Newbie Poster

Populating an array with results from a mysql query...

  #1  
Oct 17th, 2007
I'm working on a project (lord knows why, I'm a below average coder) where I need to identify a phone number and its country code and national code to obtain the billing info..

I have been able to obtain the the country code without problems, but I'm having problems getting the national calling code.

I have 2 ways to do this, either way I need to take the full number from my database, find the country code, then do a substr(full number, country code length, 10*) and decrement it until I either find a match or 10 counts down to 0, after which I can select the id from the database using the country code and the national code as NULL.

The first way is to do a query for each decremented number, until it either hits, or ends up querying for NULL, the other way is to take all the matches for the country code (except for NULL) and create an array (at most I've seen 60 records). I then want to look for the decrementing number in the array.

I wanted to see which method was more efficient, but for some reason I'm not populating my array properly (at least as far as I can tell.. I'm not even 100% on how to do that).

My question is, am I doing it wrong?

  1. $query2 = "select nspec from routing_codes where ccode = '$true_cc' and nspec IS NOT NULL"; //grab all nspec codes to fill array
  2. $result = mysql_query($query2) or die('Query1 failed: ' . mysql_error());
  3. $totalRows = mysql_num_rows($result);
  4. $tf_result = array();
  5. for ($j=0; $j<$totalRows; $j++) {
  6. $tf_result[$j] = mysql_fetch_row($result);
  7. }





* For some reason orange has a 10 digit national calling number in the UK, otherwise 6 is the usual length... I'll probably test for the UK cc, and adjust the length accordingly when I get the damn thing functioning correctly.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is online now Online
Practically a Master Poster

Re: Populating an array with results from a mysql query...

  #2  
Oct 17th, 2007
the mysql_fetch_row returns data as a numerical array. you don't need to make it into one. if you could explain your problem in more detail, i think i can help you.
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: Populating an array with results from a mysql query...

  #3  
Oct 17th, 2007
$last = mysql_query($query2);
$totalrows = mysql_num_row($last);
while ( $addtoarray = mysql_fetch_array($last))
{

$tf_result = $write[0];
}
Do a favour, leave me alone
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: nickw is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nickw nickw is offline Offline
Newbie Poster

Re: Populating an array with results from a mysql query...

  #4  
Oct 18th, 2007
Originally Posted by kkeith29 View Post
the mysql_fetch_row returns data as a numerical array. you don't need to make it into one. if you could explain your problem in more detail, i think i can help you.


Numerical or Associative is unimportant, there are only 3 columns in the DB.

There are 3 columns, id, ccode and nspec.

id is the id that refers directly to the country (and local dialing code), ccode is the country code, and nspec is the number after the country code.

Here in italy, a number looks like this 00 39 392 1234567 00 is the international prefix (I toss that), 39 is the country code (a unique number..) then I need to find the characters which identify the national dialing code (392 is a cell number, which has a different price than a PSTN number).

I can see that I'm selecting the numbers correctly, my problem lies in the fact that I'm not inserting the correct values into my array. I'm going to give the code that fatihpiristine suggested a go..
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:13 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC