SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    order by and row number

    hi,Please i have been trying to include a row number that increases for each new row, and also make the list show by arranging the result of the query by the shop name but hitting brick wall.

    this is the code

    PHP Code:
    <tr>
        <th>ROW NO</th>
        <th>SHOP NAME</th>
        <th>PRODUCT NAME</th>
        <th>PRODUCT SIZE</th>
        <th>PRODUCT COLOUR</th>
        <th>PRODUCT QUANTITY</th>
        <th>PRICE</th>
        <th>TOTAL</th>
        <th></th>
        </tr>
        <?php
        
    // Get DB results and loop, outputting table rows with counter
        
    $pplresult mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());
       for (
    $i 0$row mysql_fetch_assoc($pplresult); $i++) {
        echo 
    "
        <tr>
     <td>""</td>
        <td>"
    .htmlspecialchars($row['Sname'])."</td>
        <td>"
    .htmlspecialchars($row['Pname'])."</td>
        <td>"
    .htmlspecialchars($row['Psize'])."</td>
        <td>"
    .htmlspecialchars($row['Pcolour'])."</td>
        <td>
        <input type='text' name='item[
    $i][Pquantity]' id='Pquantity' value='".htmlspecialchars($row['Pquantity'])."' />
        <input type='hidden' name='item[
    $i][Pidno]' id='Pidno' value='".htmlspecialchars($row['Pidno'])."' />
        </td>
        <td>
        <input type='text' name='item[
    $i][Price]' id='Pquantity' value='".htmlspecialchars($row['Price'])."' readonly>
        </td>
        <td>"
    .htmlspecialchars($row['Tprice'])."</td>
        <td><a href='deleteproduct.php?del="
    .htmlspecialchars($row['Pidno'])."'>delete</a></td>
        </tr>"
    ;
        }
    any suggestions or guide will be appreciated

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    applying a row number can be done very easily with php

    sorting by shop name requires an ORDER BY clause in your SELECT statement
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    i have sorted the "order by",statement, but applying the row numbers is not yielding, closest articles or forums am seeing re using sql functions like "@row := @row + 1" and its not working.

  4. #4
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    i have sorted it thanks for the guidance


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •