English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi,

This is in my php code:

$map->addAddress($address,"This is another address that is italic");

It basically puts out an address for a google map application from a database.

How can I get it so that the above code is repeated until the entire contents of the database are put out?

Thanks

2007-07-27 03:09:59 · 3 answers · asked by jeff lemon 1 in Computers & Internet Programming & Design

3 answers

You need to put your data into an array. In this example, the field the address is in is called address. It will take the first one, store it to the variable $add, echo it to the screen and then keep looping until it hits the end of the database. (code not tested but should be close).

//search for all addresses
$sql_search = "select * yourdatabase";
$result_search = mysql_query($sql_search,$conn) or die(mysql_error());
if (mysql_num_rows($result_search)>= 1) {
while ($search = mysql_fetch_array($result_search)){
$add = $search['address'];
echo $add
}
}

For some reason yahoo leave some of the above out. sorry. Email me and I will send you the code.

2007-07-27 03:47:28 · answer #1 · answered by Mikee 2 · 0 0

First off, I'm assuming that addAddress() is your own function belong to the map class - cos I looked at the google map api and there's not such function.

Secondly, i'm ignoring the string text that comes after $address.

The way I would do it is to make $address as an array variable. That means $address will contain an array of addresses.

To populate the $address array with data from your database, just follow something similar to the sample script here.
http://www.php.net/manual/en/function.mysql-fetch-assoc.php
with the exception of the while loop, you will do

while ($row = mysql_fetch_assoc($result)) {
array_push($address,$row)
}

this will get you an array of datarows from your database.

Then you need to write your addAddress() function to extract the data rows within the array and submit them to google api

Hope that helps.

2007-07-30 22:10:52 · answer #2 · answered by diagnostix 3 · 0 0

Not sure what you are trying to do, but if it is to get all the entries from a database, do as this:
-------------------------
- If you want to know how many entries there are:
$query = "SELECT count(*) FROM `tablename` WHERE 1";
$list = mysql_query($query) or die("Query failed : " . mysql_error());
$count = mysql_fetch_array($list);
echo ("
Found ".$count[0]." records.
");
mysql_free_result($list);
------------------------
- If you want to read each entry and do something with each one:
$query = "SELECT * FROM `tablename` WHERE 1";
$list = mysql_query($query) or die("Query failed : " . mysql_error());
while ($lst = mysql_fetch_array($list))
{
$map = $lst[0]); // 0 is the field number in the table
.. do something with $map
}
mysql_free_result($list);
---------------
Of course, this depends on the table format you are using...
Check www.skytargets.com or email-me

2007-07-27 05:02:09 · answer #3 · answered by just "JR" 7 · 0 0

fedest.com, questions and answers