Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
cdickson
Forum Contributor
Posts: 120 Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA
Post
by cdickson » Tue Apr 06, 2004 10:33 am
Once again I think I am a victim of DMX's coding.
I'm trying to alphabetize the list/menu items that are drawn from one of the tables in the db. I can get the information into the menu, but I can't get the ORDER BY function to work. DMX generates this code:
Code: Select all
<option value="<?php echo $row_rsCategories['cat_desc1'] ?>"></option>
When I try to order the list alphabetically, I added to the code as follows:
Code: Select all
<option value="<?php echo $row_rsCategories['cat_desc1'] ORDER BY 'cat_desc1' ASC ?>"></option>
This code results in a parsing error message. I don't think the answer is too far off.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Tue Apr 06, 2004 10:47 am
you need to put
ORDER BY 'cat_desc1' ASC
on the end of your MySQL query, NOT in your PHP code.
the following
Code: Select all
<option value="<?php echo $row_rsCategories['cat_desc1'] ORDER BY 'cat_desc1' ASC ?>"></option>
is total nonsense.
I am guessing you want to display a number of options. You will need a while statement that itterates through each one of the row from the results.
Need to see more code to help you out thi.
Mark
cdickson
Forum Contributor
Posts: 120 Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA
Post
by cdickson » Tue Apr 06, 2004 11:00 am
The html/php code for the form that I created to conduct the search follows. The PHP was created by DMX.
Code: Select all
<form name="categorySearch" method="post" action="../category.php">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td class="bodytext"><div align="left">Search by Business Category</div>
<div align="left"></div> <div align="left">
</div></td>
</tr>
<tr>
<td class="bodytext"><div align="left">
<select name="selectCategory">
<?php
do {
?>
<option value="<?php echo $row_rsCategories['cat_desc1']?>"></option>
<?php
} while ($row_rsCategories = mysql_fetch_assoc($rsCategories));
$rows = mysql_num_rows($rsCategories);
if($rows > 0) {
mysql_data_seek($rsCategories, 0);
$row_rsCategories = mysql_fetch_assoc($rsCategories);
}
?>
</select>
</div><div align="left">
</div></td>
</tr>
<tr>
<td class="bodytext"><input type="submit" name="Submit2" value="Go"></td>
</tr>
<tr>
<td class="bodytext"><div align="center">
</div></td>
</tr>
</table>
</form>
Thanks for the help - it is frustrating being so new at this.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Tue Apr 06, 2004 11:04 am
Where is the query?
Mark
cdickson
Forum Contributor
Posts: 120 Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA
Post
by cdickson » Tue Apr 06, 2004 11:22 am
Sorry.
Code: Select all
<?php
foreach ($_GET as $key => $value) {
$_GET[$key] = trim($value);
}
mysql_select_db($database_hschamber, $hschamber);
$query_rsCategories = "SELECT * FROM Category1";
$rsCategories = mysql_query($query_rsCategories, $hschamber) or die(mysql_error());
$row_rsCategories = mysql_fetch_assoc($rsCategories);
$totalRows_rsCategories = mysql_num_rows($rsCategories);
?>
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Tue Apr 06, 2004 11:24 am
change
Code: Select all
$query_rsCategories = "SELECT * FROM Category1";
to
Code: Select all
$query_rsCategories = "SELECT * FROM Category1 ORDER BY 'cat_desc1' ASC ";
Mark
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Apr 06, 2004 11:25 am
Try $query_rsCategories = "SELECT * FROM Category1 ORDER BY cat_desc1";
[edit] Beaten to it