Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Mysql to PHP array
Name: jb60606 Date: June 16, 2007 at 14:11:01 Pacific OS: linux CPU/Ram: dontknow Product: dontknow
Comment:
I have a list of cities in a mysql table and I need to get them into a string separated by a minus ("-").
I used to have the cities in a simple text file, and used the following code to extract them into a string.
Name: Don Arnett Date: June 16, 2007 at 20:13:53 Pacific
Reply:
The page linked below talks about the mysql_fetch_array function. After you run a query to get the data, you'd use mysql_fetch_array to get each row from the returned data. There are some small examples on the page.
Post back if you need help figuring out the SQL or the database stuff.
Name: Michael J (by mjdamato) Date: June 17, 2007 at 12:13:08 Pacific
Reply:
Well, it would be helpful to know the structure of your table. BUt, assuming the name of the table is "locations" and the field is "city", this should work:
$query = "SELECT city FROM locations GROUP BY city";
$result = mysql_query($query) or die (mysql_error());
while ($record = mysql_fetch_assoc($result)) {
$arr[] = $record['city'];
}
$cities = implode('-',$cityAry);
Michael J
0
Response Number 3
Name: jb60606 Date: June 17, 2007 at 15:09:40 Pacific
Reply:
Thanks a lot guys. Your example worked perfectly, Michael.
I knew how to get the data into a MYSQL array, but getting it into a string from there is what I didn't have a clue on. I'm very new to both PHP and SQL.
Summary: First off hello, Ok, I’m new to mysql and php. I’m trying to create a registration form. I already have it to where the use can submit information. But I would like a way that they could review th...
Summary: I am attempting to create a database for my rather large collection of DVD-Rs. I have used phpMysql to create the database and have created two tables, one each for the two main types of content that...