Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting a query

Status
Not open for further replies.

thumbelina

Programmer
Jun 4, 2001
58
CA
part of this might be a query problem, but the biggest problem i think is going to be formatting with php. i have a table in my database of projects and each project is part of one category so i want to take both fields from the database and put them into a drop down box so that each line looks and saves like this: benfits - sickleave. where benifts is one of the projects and sickleave is the project. i have about 6 different projects and i also want the list ordered by category, this way all the benifts are listed together regardless of what order they are in, in the table. my query looks like this right now: SELECT project, category FROM ProjectList ORDER BY category. not sure if that will work here, but that's what i'm trying to do.
 
Here's what I'm interpreting that you want to see:

benefits - sickleave
benefits - vacation
benefits - .......and so on

The order you've selected the fields will be important only when you write the code to output the selected rows. I think you want something like this (pseudo code only):

<? do your query here in case it fails ?>
{some form code goes here}
<select name=&quot;cateproj&quot; size=&quot;1&quot;>
<? for each entry in your query
echo &quot;<option value=\&quot;.Queryfield(2).Queryfield(1).\&quot;> Queryfield(2) - Queryfield(1)\n&quot;
?>
echo &quot;</select>\n&quot;
{other form stuff and submit button here}

I hope that makes sense (and answers your question) and my apologies for not having actual code.

DjangMan
 
Try this
[tt]
<select name=&quot;CatProj&quot;>
<?php
$SqlRes = mysql_query( $YourSelect );
if( $SqlRes )
{
$NumRows = mysql_num_rows( $SqlRes );
for( $i=0; $i<$NumRows; $i++ )
{
$ARow = mysql_fetch( $SqlRes );
echo( &quot;\t<option value=\&quot;$ARow[0]:$ARow[1]\&quot;>$ARow[0] - $ARow[1]</option>\n&quot; );
}
mysql_free_result( $SqlRes );
}
else
{
echo( &quot;\t<option value=\&quot;-1\&quot;>There was no projects!</option>\n&quot; );
}
?>
</select>
[/tt]
I think this will give you a idea...
I hope it works...
Unix was made by and for smart people.
 
thanks for your help but i think i have found a simplar way to do this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top