displaying specific data from mysql table using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • printline
    New Member
    • Jul 2006
    • 89

    displaying specific data from mysql table using php

    Hello All

    I need a little help with a phph script to display some specific data from a mysql table.

    I have a mysql table with 4 columns and 10 rows. I want to display fx. data from row 4, 6, 8 and 10.

    I can display either the first row or all the rows using the below code:

    [PHP]$row = mysql_fetch_arr ay($result) or die(mysql_error ());
    echo $row['id']. " - ". $row['Thickness']. " <img src=images/arlon.jpg /> ". $row['Type']. " - ". $row['Sum'];
    echo "<br />";[/PHP]

    [PHP]while($row = mysql_fetch_arr ay($result)){
    echo $row['id']. " - ". $row['Thickness']. " <img src=images/arlon.jpg /> ". $row['Type']. " - ". $row['Sum'];
    echo "<br />";[/PHP]
    }

    Can someone tell me how to fetch a specific row of data......????? ?

    I have tried with $row[2] but without any luck.....

    Below is my entire code:

    [PHP]<?
    $username="xxxx xx";
    $password="xxxx xx";
    $database="prin tline";
    $localhost="mys ql.webglobe.dk" ;

    mysql_connect($ localhost,$user name,$password) ;
    @mysql_select_d b($database) or die( "Unable to select database");
    //$query="SELECT * FROM test";
    $query="SELECT * FROM test3";
    $result = mysql_query($qu ery) or die(mysql_error ());

    $row = mysql_fetch_arr ay($result) or die(mysql_error ());
    echo $row['id']. " - ". $row['Thickness']. " <img src=images/arlon.jpg /> ". $row['Type']. " - ". $row['Sum'];
    echo "<br />";

    $row[2] = mysql_fetch_arr ay($result) or die(mysql_error ());
    echo $row['id']. " - ". $row['Thickness']. " <img src=images/arlon.jpg /> ". $row['Type']. " - ". $row['Sum'];
    echo "<br />";


    ?>[/PHP]
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    A row number is a meaningless concept in a database.
    Do you mean a specific record?
    If so then
    Code:
    SELECT * FROM test3 WHERE `id` = 4
    OR `id` = 6 OR `id` = 8"

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Originally posted by code green
      A row number is a meaningless concept in a database.
      Do you mean a specific record?
      If so then
      Code:
      SELECT * FROM test3 WHERE `id` = 4
      OR `id` = 6 OR `id` = 8"
      Hi,

      You could streamline this with the use of 'in':
      Code:
      SELECT * FROM test3 WHERE `id` in (4,6,8)
      But the idea of a row is not much use when you are selecting data out of a database.

      Cheers
      nathj

      Comment

      • johndavid19
        New Member
        • Jun 2014
        • 4

        #4
        If you want to display specific row then you need to use $row[nth column] ie, $row[0] or $row['column_name'].
        For example,
        Code:
        while($row=mysql_fetch_result($query))
        {
         echo $row['columnname'].'<br>';
        }

        Comment

        Working...