Thank you, That was the conceptual problem I was having.
jozef
Juffermans, Jos wrote:
In that case the best way is to read all the data at once. Something like
this:
// first read all the data
$sql = "SELECT street, town, state, zip, phone FROM offices";
$result = mysql_query($sql, $link);
$all_data = array();
while ($this_row = mysql_fetch_array($result)){
array_push($all_data, $this_row);
}
// then create the HTML
echo "<table>";
echo "<tr>";
foreach ($all_data as $this_row) {
echo "<th>" . $this_row{"town"} . "</th>";
}
echo "</tr>";
echo "<tr>";
foreach ($all_data as $this_row) {
echo "<td>" . $this_row{"town"} . "</td>";
}
echo "</tr>";
echo "<tr>";
foreach ($all_data as $this_row) {
echo "<td>" . $this_row{"street"} . ", " .
$this_row{"state"} . " " . $this_row{"zip"} . "</td>";
}
echo "</tr>";
echo "<tr>";
foreach ($all_data as $this_row) {
echo "<td>Phone: " . $this_row{"phone"} . "</td>";
}
echo "</tr>";
echo "</table>";
Jos
PS: Please always reply to php-db@xxxxxxxxxxxxxx
-----Original Message-----
From: J. Connolly [mailto:web@xxxxxxxxxx]
Sent: 02 May 2005 16:14
To: Juffermans, Jos
Subject: Re: Sorting multidimensional arrays from mysql
I have the data which comes out like this from a select all statement
"1"," 1510 New State Highway (Rte. 44)","Raynham", "MA","2767"
"2"," 646 Washington St.", "South Easton","MA","2375"
"3"," 47 Broad St.", "Bridgewater", "MA","2324"
"4"," 605 Belmont St.", "Brockton", "MA","2301"
"5"," 662 Main St.", "Falmouth", "MA","2540"
I need to be able to pull out certain cells when necessary and place
them in a table. When I need to fetch one entire row, it is no problem.
I just do not understand how to define each cell as unique. Perhaps this
is not possible?
I need the data to be inputted something like:
<th>
Easton
</th>
<th>
Raynham
</th>
</tr>
<tr>
<td>
646 Washinton Street
</td>
<td>
1510 New State Highway (Rte.44)
</td>
</tr>
<tr>
<td>
South Easton, MA 02375
</td>
<td>
Raynham, MA 02767
</td>
</tr>
<tr>
<td>
Phone: (508) 238-8400
</td>
<td>
Phone: (508) 822-7444
</td>
</tr>
thanks,
jozef
Juffermans, Jos wrote:
mysql_fetch_array will always only return 1 row. $array['town'] won't be an
array but just a text and is therefor interpreted differently.
If you can give us more information (ie data model, output sample) we might
be able to help you a bit better.
Jos
-----Original Message-----
From: J. Connolly [mailto:web@xxxxxxxxxx]
Sent: 02 May 2005 15:42
To: PHP list
Subject: Sorting multidimensional arrays from mysql
Morning all,
I am having problems understanding what I need to do. Usually for most
of my work, all i need to do is pull the information and place it like
this:
function office_list(){
global $link;
echo "<table><tr>";
$sql = "SELECT town
FROM offices";
$result = mysql_query($sql, $link);
while ($array = mysql_fetch_array($result)){
$office = $array['town'];
$state = $array['state'];
$zip = $array['zip'];
echo "<td>$office</td>
<td>$state</td>
<td>$zip</td>";
}
echo "</tr></table>";
}
But now I need to separate the information in order to build a more
complex table. I do not understand how to obtain each cell. I have a
fixed number so it will never change.
I thought multidimensional arrays came as array[0][0], but when i try
$office = $array['town'][0]
I just get the first letter of that office. If someone could point me in
the right direction I'd greatly appreciate it. I think I just do not
know the terminology I am looking for. The PHP manual keeps brining me
to pages that are not what I need.
Thank you,
jozef
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php