Jump to content

mysql_query to array


urtlking2jo

Recommended Posts

I've stored the options I would like to use in a drop down box on multiple pages in a mysql db table.  I am trying to run a query to retrieve those options (years in this case: 1990, 1991, 1992, etc.) and then store those options in an array so that I can output those options easily multiple times while only running the query once.  I'm not overly familiar with arrays however, and am running into difficulty.

My query is as follows, but I don't know where to go after that.  Any help would be appreciated!

$qry = "SELECT years FROM tbl_property WHERE login_name = '$fusername' AND room = '$room'";
$result = mysql_query($qry);
Link to comment
https://forums.phpfreaks.com/topic/28884-mysql_query-to-array/
Share on other sites

[code]<?php
$qry = "SELECT years FROM tbl_property WHERE login_name = '$fusername' AND room = '$room'";
$result = mysql_query($qry);

$years = array();
while ($row = mysql_fetch_array($result)) {
    $years[] = $row['years'];
}

//Then to create a select field (you could make this a function)
echo "<select name=\"selectName\">";
foreach ($years as $year) { echo "<option value=\"".$year."\">".$year."</option>";
echo "<\select>";
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/28884-mysql_query-to-array/#findComment-132280
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.