alphabetize my listings
Moderator: General Moderators
alphabetize my listings
I am having problems sorting the names that are being pulled from the database in alphabetical order. I have tried several things but nothing is working. Here is the code.
<?php
require ("config.php");
$row = mysql_query ("SELECT * FROM `locations` where Type <> 0");
$count =0 ;
echo("<tr>");
while ($print = mysql_fetch_object($row)) {
if($count == 0) echo("<td> </td>");
echo ("<td class='text'><b>". $print->Name . "</b></td>");
$count++;
if($count == 5 )
{
echo("</tr><tr>");
$count = 0;
}
}
if($count != 0)
echo("</tr>");
?>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
</td>
</tr>
<tr>
can anyone help? What is the piece of code that is missing?
<?php
require ("config.php");
$row = mysql_query ("SELECT * FROM `locations` where Type <> 0");
$count =0 ;
echo("<tr>");
while ($print = mysql_fetch_object($row)) {
if($count == 0) echo("<td> </td>");
echo ("<td class='text'><b>". $print->Name . "</b></td>");
$count++;
if($count == 5 )
{
echo("</tr><tr>");
$count = 0;
}
}
if($count != 0)
echo("</tr>");
?>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
</td>
</tr>
<tr>
can anyone help? What is the piece of code that is missing?
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: alphabetize my listings
What have you tried?
Re: alphabetize my listings
Since you did not use an ORDER BY clause in your query, what is it that you thought would cause the records to be in alphabetic sequence?
Re: alphabetize my listings
I tried the order by statement and it caused the code not to appear at all, could someone show me the appropriate place to put this piece of code?
and what I tried WAS the order by, but it would not work, maybe i am putting it in the wrong place.
and what I tried WAS the order by, but it would not work, maybe i am putting it in the wrong place.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: alphabetize my listings
post the code you tried and we will show you want is wrong!
Re: alphabetize my listings
<?php
require ("config.php");
$row = mysql_query ("SELECT * FROM `locations` where Type <> 0 ORDER BY ASC");
$count =0 ;
echo("<tr>");
while ($print = mysql_fetch_object($row)) {
if($count == 0) echo("<td> </td>");
echo ("<td class='text'><b>". $print->Name . "</b></td>");
$count++;
if($count == 5 )
{
echo("</tr><tr>");
$count = 0;
}
}
if($count != 0)
echo("</tr>");
?>
require ("config.php");
$row = mysql_query ("SELECT * FROM `locations` where Type <> 0 ORDER BY ASC");
$count =0 ;
echo("<tr>");
while ($print = mysql_fetch_object($row)) {
if($count == 0) echo("<td> </td>");
echo ("<td class='text'><b>". $print->Name . "</b></td>");
$count++;
if($count == 5 )
{
echo("</tr><tr>");
$count = 0;
}
}
if($count != 0)
echo("</tr>");
?>
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: alphabetize my listings
If you had done a google search for 'mysql order' the first result is the one you want!!!
I'll even post it here for you
http://dev.mysql.com/doc/refman/5.0/en/ ... ation.html
I'll even post it here for you
http://dev.mysql.com/doc/refman/5.0/en/ ... ation.html
Code: Select all
SELECT * FROM t1
WHERE key_part1=1
ORDER BY key_part1 DESC;
Re: alphabetize my listings
is this alphabetically order from a to z or z to a? i get confused with asc and desc
Re: alphabetize my listings
so in this case, would the correct code be
<?php
require ("config.php");
$row = mysql_query ("SELECT * FROM `locations` where Type <> 0 ORDER BY Name ASC");
$count =0 ;
echo("<tr>");
while ($print = mysql_fetch_object($row)) {
if($count == 0) echo("<td> </td>");
echo ("<td class='text'><b>". $print->Name . "</b></td>");
$count++;
if($count == 5 )
{
echo("</tr><tr>");
$count = 0;
}
}
if($count != 0)
echo("</tr>");
?>
<?php
require ("config.php");
$row = mysql_query ("SELECT * FROM `locations` where Type <> 0 ORDER BY Name ASC");
$count =0 ;
echo("<tr>");
while ($print = mysql_fetch_object($row)) {
if($count == 0) echo("<td> </td>");
echo ("<td class='text'><b>". $print->Name . "</b></td>");
$count++;
if($count == 5 )
{
echo("</tr><tr>");
$count = 0;
}
}
if($count != 0)
echo("</tr>");
?>
Re: alphabetize my listings
Run it and see.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: alphabetize my listings
Come on, it probably easier to try both than to type the question here!studio29 wrote:is this alphabetically order from a to z or z to a? i get confused with asc and desc
That looks ok, did it work?studio29 wrote:so in this case, would the correct code be
SELECT * FROM `locations` where Type <> 0 ORDER BY Name ASC
Re: alphabetize my listings
gosh im trying it, give me a sec lol. You guys are a bit pushy 
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: alphabetize my listings
If you want to play that card...and we are all being honest here...you are a bit lazy! I dont want to alienate you or discourage you from coming back. But you ask simple questions that would be easier to try it than to post the question itself. We are here helping you, giving you are knowledge & time for FREE! The least you can do is try to help yourself!studio29 wrote:gosh im trying it, give me a sec lol. You guys are a bit pushy
I have a better idea, post your brief and code so far, and I will write the entire thing for you
Re: alphabetize my listings
it worked to a certain degree, they are in alphabetical order, except for the one i entered in the other day -
http://www.gatewaymortgagesml.com/servicesareas.php
any thoughts?
http://www.gatewaymortgagesml.com/servicesareas.php
any thoughts?
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: alphabetize my listings
How I Help Here: I will put in an equal amount of effort to the amount of effort you put in. If it's obvious you're not bothered about your problem (eg you don't post any code, you've not got any error messages) then I won't bother helping very much. If you make it clear you care and you're trying your best (eg you post code inCode: Select all
tags, you've tried a few different fixes already) I'll do my best to help you.[/quote] This is from [color=#00BF00]onion2k [/color]'s signature...read it, learn it, we all think it!!!