473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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_array($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_array($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="xxxxxx";
$password="xxxxxx";
$database="printline";
$localhost="mysql.webglobe.dk";

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
//$query="SELECT * FROM test";
$query="SELECT * FROM test3";
$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($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_array($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 7385
code green
1,726 Expert 1GB
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 Expert 512MB
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
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
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...
2
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...
8
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...
13
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...
13
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...
5
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)...
8
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 =...
10
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...
14
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.