Hoping someone can help me here. It's a simple question, but I'm just not
getting it.
I have two files:
<?php
$precinct = array (
array ( number=>2324,
centerlat=>-122.31705665588379,
centerlong=>47.710367959402525,
etc...
<?php
include ("precinctdata.php");
$filename = $_GET['id'];
$number = $precinct[filename-1][number];
etc...
I want to assign the value of "2324" to the variable $number. I've done
this with arrays that start with number=>1, 2, 3, etc., but not successfully
with specific values.
What am I missing?
--
Chad Lupkes ch********@gmail.com http://www.seattlewebcrafters.com/ 7 1486
Chad Lupkes wrote: Hoping someone can help me here. It's a simple question, but I'm just not getting it.
I have two files:
<?php $precinct = array ( array ( number=>2324, centerlat=>-122.31705665588379, centerlong=>47.710367959402525, etc...
<?php include ("precinctdata.php"); $filename = $_GET['id']; $number = $precinct[filename-1][number]; etc...
I want to assign the value of "2324" to the variable $number. I've done this with arrays that start with number=>1, 2, 3, etc., but not successfully with specific values.
What am I missing?
Try
$precinct = array (
array ('number'=>2324,
'centerlat'=>-122.31705665588379,
'centerlong'=>47.710367959402525,
...
$number = $precinct[$filename-1]['number'];
^ ^ ^
filename is a variable so it needs a $. number is a string, so it needs single
quotes. The same is true when you're creating the array.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
I noticed that Message-ID:
<Ch**************@newsread1.news.pas.earthlink.net > from Chad Lupkes
contained the following: $precinct = array ( array ( number=>2324, centerlat=>-122.31705665588379, centerlong=>47.710367959402525, etc...
<?php include ("precinctdata.php"); $filename = $_GET['id']; $number = $precinct[filename-1][number]; etc...
You haven't created an associative array.
The array key can be a number, as you have used before, or a string. If
you use a string you don't get a number as well. The only thing you
could do in this instance is assign the array to another array with
numerical indices.
eg
foreach($precinct as $value){
$precinct_num[]=$value;
}
then
$filename = $_GET['id'];
$number = $precinct_num[$filename-1];
However, I suggest you look at the overall logic of what you are trying
to do.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Hi Geoff,
Ok, what I'm trying to make happen is that when people type in or click
on a link that takes them to precinctmap.php?id=2324, it will pull the
data necessary to draw a map of that precinct. In the other arrays
that I have built similar to this, I have used numerical values
starting with 1. For example, in Washington State we have 9
Congressional Districts, 49 Legislative Districts and 39 Counties.
Each of the scripts that pull from these arrays work fine, because I'm
able to use array values of 0-8, 0-48 and 0-38 with the 'filename-1'
reference.
For the application I am trying to create now, the precinct numbers
start at 1281, and skip/jump up to 3423. It's not a sequential set of
numbers. There are 224 of them, so I could create the array and
display script to use key values of 0-223 if I have to, but I'd rather
be able to call the specific data I need based on the precinct number
instead of an arbritary number that only works when I know the key
value. That's why I'm trying to use strings.
I know a database might be a better way of doing this, but I have yet
to get a good understanding of how to use databases, so I'm trying to
work with what I know.
Does that description help? I've been trying to find a tutorial page
that explains how to call string values from arrays, but I can't find
one that I really understand.
Chad
I noticed that Message-ID:
<11**********************@g43g2000cwa.googlegroups .com> from chadlupkes
contained the following: Does that description help? I've been trying to find a tutorial page that explains how to call string values from arrays, but I can't find one that I really understand.
Ah yes gotcha. You want the precinct number to be the key to another
array. Try this:
$precinct = array(
2324=> array (
centerlat=>-122.31705665588379,
centerlong=>47.710367959402525,
)
);
print $precinct[2324]['centerlat'];
//prints -122.31705665588379
print"<br>";
print $precinct[2324]['centerlong'];
//prints 47.710367959402525
I have a very basic tutorial here http://www.ckdog.co.uk/phpcourse/3_arrays_and_loops.doc
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
JDS wrote: On Mon, 18 Jul 2005 23:23:26 -0500, Jerry Stuckle wrote:
JDS Computer Training Corp.
Those are my initials!
Mine, too! :-)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
"chadlupkes" <ch********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com... Hi Geoff,
Ok, what I'm trying to make happen is that when people type in or click on a link that takes them to precinctmap.php?id=2324, it will pull the data necessary to draw a map of that precinct. In the other arrays that I have built similar to this, I have used numerical values starting with 1. For example, in Washington State we have 9 Congressional Districts, 49 Legislative Districts and 39 Counties. Each of the scripts that pull from these arrays work fine, because I'm able to use array values of 0-8, 0-48 and 0-38 with the 'filename-1' reference.
For the application I am trying to create now, the precinct numbers start at 1281, and skip/jump up to 3423. It's not a sequential set of numbers. There are 224 of them, so I could create the array and display script to use key values of 0-223 if I have to, but I'd rather be able to call the specific data I need based on the precinct number instead of an arbritary number that only works when I know the key value. That's why I'm trying to use strings.
I know a database might be a better way of doing this, but I have yet to get a good understanding of how to use databases, so I'm trying to work with what I know.
Does that description help? I've been trying to find a tutorial page that explains how to call string values from arrays, but I can't find one that I really understand.
Chad
How about rather than the_array[$i], using the_array["$i"]? The index is
then a string rather than a number. You will only have the 224 elements,
but their names can be "1281" or "3423". This seem like the simplest
solution to you problem.
Shelly This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ajikoe |
last post by:
Hello,
Is anyone has experiance in running python code to run multi thread
parallel in multi processor. Is it possible ?
Can python manage which cpu shoud do every thread?
Sincerely Yours,...
|
by: Frank Jona |
last post by:
Intellisense with C# and a multi-file assembly is not
working. With VB.NET it is working.
Is there a fix availible?
We're using VisualStudio 2003
Regards
Frank
|
by: * ProteanThread * |
last post by:
but depends upon the clique:
...
|
by: frankenberry |
last post by:
I have multi-page tiff files. I need to extract individual frames from the
multi-page tiffs and save them as single-page tiffs. 95% of the time I
receive multi-page tiffs containing 1 or more black...
|
by: cody |
last post by:
What are multi file assemblies good for?
What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a
single multi file assembly (A.DLL+A.NETMODULE)?
|
by: mimmo |
last post by:
Hi! I should convert the accented letters of a string in the correspondent
letters not accented. But when I compile with -Wall it give me:
warning: multi-character character constant
Do the...
|
by: Shane Story |
last post by:
I can seem to get the dimensions of a frame in a multiframe tiff.
After selecting activeframe, the Width/Height is still really much larger
than the page's actual dimensions.
When I split a...
|
by: bobwansink |
last post by:
Hi, I'm relatively new to programming and I would like to create a C++
multi user program. It's for a project for school. This means I will
have to write a paper about the theory too. Does anyone...
|
by: Sabri.Pllana |
last post by:
We apologize if you receive multiple copies of this call for papers.
***********************************************************************
2008 International Workshop on Multi-Core Computing...
|
by: mknoll217 |
last post by:
I am recieving this error from my code:
The multi-part identifier "PAR.UniqueID" could not be bound.
The multi-part identifier "Salary.UniqueID" could not be bound.
The multi-part identifier...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |