PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jeremyclover
Forum Newbie
Posts: 2 Joined: Tue Jan 12, 2010 3:42 pm
Post
by jeremyclover » Wed Jan 13, 2010 11:22 pm
I'm trying to have one query populate what will eventually be multiple input list. Right now I'm just cycling through the arrays. I want each list to be filtered differently based on the ITEM_SRC field.
I feel there has to be a better way to do this. Thoughts?
Code: Select all
$query = "SELECT ITEM_SRC, ITEM_ID, ITEM_DESC ";
$query .= "FROM vWEB_LIST ";
//execute the SQL query and return records
$result = mssql_query($query);
//Return AD_SIZE list
while($row = mssql_fetch_array($result))
{
if($row[0]=='AD_SIZE')
{
echo $row['ITEM_SRC']." - ".$row['ITEM_ID']." - ".$row['ITEM_DESC']."<br>";
}
}
mssql_data_seek($result,0);
while($row = mssql_fetch_array($result))
{
echo $row['ITEM_SRC']." - ".$row['ITEM_ID']." - ".$row['ITEM_DESC']."<br>";
}
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Jan 13, 2010 11:49 pm
You can do the sorting in the query itself. No PHP code needed.
What other item_src's are there? Do you want the results sorted by that field?
jeremyclover
Forum Newbie
Posts: 2 Joined: Tue Jan 12, 2010 3:42 pm
Post
by jeremyclover » Thu Jan 14, 2010 12:21 am
It's not about sorting the lists as much as subdividing them. There's about 7 different ITEM_SRC values, each representing a different lookup list.
More expanded code example:
Code: Select all
mssql_data_seek($result,0);
echo "<form method=post name=prod action=insert.php>";
echo "<span class='select_title'>Select Ad Size:</span>";
echo "<select name='ad_size'><option value='' selected='selected'>-</option>";
while($row=mssql_fetch_array($result))
{
if($row[0]=='AD_SIZE')
{
echo "<option value='$row[ITEM_ID]'>$row[ITEM_DESC]";
echo "</option><br>";
}
}
echo "</select>";
mssql_data_seek($result,0);
echo "<span class='select_title'>Select Color:</span>";
echo "<select name='color'><option value='' selected='selected'>-</option>";
while($row=mssql_fetch_array($result))
{
if($row[0]=='COLOR')
{
echo "<option value='$row[ITEM_ID]'>$row[ITEM_DESC]";
echo "</option><br>";
}
}
echo "</select>";
echo "<input type=submit value=Submit>";
echo "</form>";
Make a little more sense. I'm filtering the array for each list, then resetting the index, and filtering again for the next list.