Jump to content

Recommended Posts

Hi all

 

At present my PHP script  echo's the address's direct from the DB id, I would like to change this so it lists by alphanumeric:

 

address1 contains the number and street so at present lists as:

 

8 better street, city, postcode

1 better street, city, postcode

9 any street, city, postcode

1 any street, city, postcode

 

I would like:

 

1 any street, city, postcode

9 any street, city, postcode

1 better street, city, postcode

8 better street, city, postcode

 

Present script:

 




<?php   
     $useron = $_SESSION['user_on'];
      if (isset($_GET['msg'])) {
     echo "<div class=\"error\">$_GET[msg]</div>";
     }     
    

$query="SELECT * FROM $useron";
$result=mysql_query($query);

$num=mysql_num_rows($result);

   if ($num > 0 ){
      
   };
mysql_close();

if ($num > 0 ) {
$i=0;
while ($i < $num) {
$address1 = mysql_result($result,$i,"address1");
$address2 = mysql_result($result,$i,"address2");
$postcode = mysql_result($result,$i,"postcode");
$status = mysql_result($result,$i,"status");
$id = mysql_result($result,$i,"id");

?>
<table width="850" border="0" style="font-size:12px" >
  <tr>
    <th width="350" height="10" scope="col" align="left"><? echo $address1, ", ",  $address2, ", ", $postcode; 
  ?></th>
    <th width="150"  height="10"scope="col" align="left"> Work Status: <font color="#FF0000"> 
      <?php   echo $status; ?></font>

 

this script may seem rubbish but it works :)

 

Any help much appreciated.

 

regards

 

johnliverpool

Link to comment
https://forums.phpfreaks.com/topic/244747-change-list-from-id-to-alpabetical/
Share on other sites

$query="SELECT * FROM $useron ORDER BY `address1` ASC";

 

thanks for your quick reply

 

Inserted the query string you gave the list is no longer by id but still not alphanumeric

 

20, 121 Grant Av, Wavertree, L15 7GH         Work Status: Idle    Update - Delete - work request

19, 276 Smithdown Rd, Wavertree, L15 0RT Work Status: Idle    Update - Delete - work request

18, 29 Kenmare Rd, Wavertree, L15 3HG Work Status: Idle    Update - Delete - work request

17, 33 Connaught Rd, Kensington, L7 8RW Work Status: Idle    Update - Delete - work request

24, 37 Ferndale Rd, Wavertree, L15 8FG Work Status: Idle    Update - Delete - work request

 

first number is id second house number and street, hope this helps.

 

 

In order to efficiently sort alphabetically, you would need to store the street separately from the street number.

 

Thanks for the response have done as requested;

New script:

 


  <?php	
  $useron = $_SESSION['user_on'];
      if (isset($_GET['msg'])) {
  echo "<div class=\"error\">$_GET[msg]</div>";
  }	  

$query="SELECT * FROM $useron ORDER BY `address1` ASC";
$result=mysql_query($query);

$num=mysql_num_rows($result);

if ($num > 0 ){

};
mysql_close();

if ($num > 0 ) {
$i=0;
while ($i < $num) {
$housenum = mysql_result($result,$i,"housenum");
$address1 = mysql_result($result,$i,"address1");
$address2 = mysql_result($result,$i,"address2");
$postcode = mysql_result($result,$i,"postcode");
$status = mysql_result($result,$i,"status");
$id = mysql_result($result,$i,"id");

?>
<table width="850" border="0" style="font-size:12px" >
  <tr>
    <th width="350" height="10" scope="col" align="left"><? echo $id, ", ", $housenum, " ", $address1, ", ",  $address2, ", ", $postcode; 
  ?></th>
    <th width="150"  height="10"scope="col" align="left"> Work Status: <font color="#FF0000"> 
      <?php	echo $status; ?></font>
   
<th width="350"  height="10"scope="col" align="left"><? 
echo " <a href=\"update.php?id=$id&useron=$useron\">Update</a> - 
<a href=\"delete.php?id=$id&useron=$useron\">Delete</a> - 
<a href=\"workrequest.php?id=$id&useron=$useron\">work request</a>";

if ($status=="Active"){
 echo " <a href=\"vwr.php?id=$id&useron=$useron\">View work requested</a>";
} ?>   

 

Hope you can work something with this Thorpe :thumb-up:

 

Regards

 

John

Noticed that by seperating the house number the address1 field is now list alphabetically:

 

29, 69 Connaught Rd, Kensington, L7 8RW Work Status: Idle    Update - Delete - work request

32, 76 Connaught Rd, Kensington, L7 8RW Work Status: Idle    Update - Delete - work request

33, 33 Connaught Rd, Kensington, L18 7HX Work Status: Idle    Update - Delete - work request

34, 16 Grant Av, Wavertree, L15 0RT         Work Status: Idle    Update - Delete - work request

31, 8 Greenhill Close, Kensington, L18 7HX Work Status: Idle    Update - Delete - work request

35, 51 Kenmare Rd, Wavertree, L18 7HX Work Status: Idle    Update - Delete - work request

30, 21 Longfellow Street, Toxteth, L8 0RR Work Status: Idle    Update - Delete - work request

 

If I can also get the number numerically then that would be great

 

Thanks for the help

 

John

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.