How to use PHP to read/fetch the database's first attribute/entry?

Discussion in 'PHP' started by project168, Mar 27, 2011.

  1. #1
    I want my PHP coding to read/fetch my database's first attribute/entry like the first number of the client in that first row and then fetch it to be shown on PHP so that it will show '1'. How would I do that?

    Here's the table of my example database (MySQL)
    [​IMG]

    I know the command to select the line via the database is this:

    SELECT * FROM CUSTOMER WHERE CUST_NO=1;
     
    project168, Mar 27, 2011 IP
  2. project168

    project168 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Oh and my primary key is CUST_NO
     
    project168, Mar 28, 2011 IP
  3. WoRLDLiFE

    WoRLDLiFE Peon

    Messages:
    116
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    <?php
    mysql_connect('localhost','username','password');
    mysql_select_db('database name');
    
    $get = mysql_query('SELECT * FROM CUSTOMER LIMIT 1');
    $row = mysql_fetch_assoc($get);
    echo "Customer No :".$row['CUST_NO']."<br />";
    echo "Customer First Name :".$row['CUST_FNAME']."<br />";
    echo "Customer Last Name :".$row['CUST_LNAME']."<br />";
    echo "Customer Phone :".$row['CUST_PHONE']."<br />";
    ?>
    
    Code (markup):
    This will display the 1st record in the database. :)
     
    WoRLDLiFE, Mar 29, 2011 IP
  4. theofficialSJ

    theofficialSJ Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Is the issues solved. let us know
     
    theofficialSJ, Mar 29, 2011 IP
  5. project168

    project168 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thank you for replying.


    How would I implement to this coding:

    <?PHP
    
    exec("mode com8: BAUD=9600 PARITY=n DATA=8 STOP=1 to=off dtr=off rts=off");
    $fp =fopen("com3", "w");
    fwrite($fp,"[B]x[/B]");[B] //WRITE TO THE CUSTOMER # BY REPLACING X[/B]
    fclose($fp);
    
    ?>
    Code (markup):
    Basically, fwrite writes the data to my USB device so 'x' is my customer # which I want it to fetch from my database. How would I do this?
     
    project168, Mar 29, 2011 IP