By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,968 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,968 IT Pros & Developers. It's quick & easy.

displaying specific data from mysql table using php

P: 89
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
Share this Question
Share on Google+
3 Replies


code green
Expert 100+
P: 1,726
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
Expert 100+
P: 938
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

P: 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,
Expand|Select|Wrap|Line Numbers
  1. while($row=mysql_fetch_result($query))
  2. {
  3.  echo $row['columnname'].'<br>';
  4. }
  5.  
Jun 28 '14 #4

Post your reply

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