473,748 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

displaying specific data from mysql table using php

89 New Member
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]
Feb 8 '08 #1
3 7404
code green
1,726 Recognized Expert Top Contributor
A row number is a meaningless concept in a database.
Do you mean a specific record?
If so then
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM test3 WHERE `id` = 4
  2. OR `id` = 6 OR `id` = 8"
Feb 8 '08 #2
nathj
938 Recognized Expert Contributor
A row number is a meaningless concept in a database.
Do you mean a specific record?
If so then
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM test3 WHERE `id` = 4
  2. OR `id` = 6 OR `id` = 8"
Hi,

You could streamline this with the use of 'in':
Expand|Select|Wrap|Line Numbers
  1. 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
Feb 8 '08 #3
johndavid19
4 New Member
If you want to display specific row then you need to use $row[nth column] ie, $row[0] or $row['column_name'].
For example,
Expand|Select|Wrap|Line Numbers
  1. while($row=mysql_fetch_result($query))
  2. {
  3.  echo $row['columnname'].'<br>';
  4. }
  5.  
Jun 28 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
508
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time store in the database. However asp recognizes the data type as date and displays the date instead of the time. If I change the data type in mysql to varchar then asp will display the time correctly, but I cannot do it this way. I want to be able...
2
4352
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control displaying the contents of the data source, whilst another control updates the datasource via a command buttons implementation of 'Click', an event raised in the 'Handle Postback Events' stage of the control execution life cycle (via the...
8
3302
by: Jon Weston | last post by:
I'm setting up an Access2003 database with pictures. I put a bound ole picture ctrl on a form that's source is the table that contains the pictures and follow ALL the directions for embedding a picture. The ctrl in the form only displays the filename of the picture. The underlying table, when opened in table view, shows the word "package" in the field. When I double-click on either it opens the picture, but I can't get it to display. ...
13
3881
by: hornedw | last post by:
I have been working on a ecommerce website for myself. What I needed some assistance on was when i was trying to display the categories/subcategories for the different products. I decided to use the modified preorder tree transversal algorithm. What I wanted was on the first page is to display the catogories as follows Books (35) Electronics(23) The number inside the parenthesis being the number of products in that
13
2900
by: David W. Fenton | last post by:
I've been struggling the last two days with something I thought was very easy, which is to open a web page with a form on it and populate the form with data passed in a query string (either POST or GET). I got Application.FollowHyperlink *kind* of working, but was having problem with double encoding of some characters (I had to do special things with + signs in the data, as well as never figuring out why some data was getting...
5
1738
by: L C | last post by:
Hello, Could someone point in the correct direction with regards to displaying my data in "nicer" format. I have figured out ( with the tutorials on the web, and the O'Reilly PHP & MySQL book) how to store, retrieve, manipulate, and display my data using PHP. But when I do display, it is the block format. I can't seem to find a tutorial that gets into a "prettier" type of display. Is this a HTML issue?
8
7556
by: bimeldip | last post by:
Hi, i would like to display the list of tables in a database in a drop down list then when user selects a table, the table will be dispalyed on the page. So far i've done this: <? $dbname = 'mysql_dbname'; // Get records from database (). $sql = "show tables from $dbname"; $result=mysql_query($sql);
10
2648
by: Lloyd Harold | last post by:
I'm very new to PHP and attempting to put together a simple script for retrieving MySQL data of personal records. The MySQL table I'm using consists of: 0: id 1: name 2: location (an integer relating to a separate table of locations). 3: details
14
3688
ddtpmyra
by: ddtpmyra | last post by:
Hi below is my script displaying all the information inside the table. Pupose: pupose of this php page is to display all the information on my table and have a check box at the last column that will allow the user to approved the member. Problem: I don't how to insert a checkbox on a loop condition. <?php
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.