how to access the inidividual names coming from database?

i have a mysql database. my field is

name
a1
a2
a3

now if i want to access them how should i ? how to echo them?
designersxAsked:
Who is Participating?
 
twocandlesCommented:
So let's simplify your problem. You have a string like "n1,n2,n3" and you want to display individual elements of the string?

If so, you can explode with

$values = explode( ",", $mystring );

and you'll have:

$values[0] = n1
$values[1] = n2
$values[2] = n3
0
 
twocandlesCommented:
0
 
twocandlesCommented:
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
designersxAuthor Commented:
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {

with this i cannot access a single name like


if i have n1,n2,n3,n4 as names .how can i access them.

please can u tell me.
0
 
twocandlesCommented:
n1, n2, n3 are field names? or values in a field?

With this statement

while ($row = mysql_fetch_array($result, MYSQL_BOTH))
you're fetching a database row into $row.

Then, inside the loop you just have to use

echo( "Row: " . $row[0] );

or

echo ("Row: ".$row["n1"] );
0
 
designersxAuthor Commented:
n1, n2, n3,n4............. are the values and it can be more. field is name.

echo( "Row: " . $row[0] ); this will echo the whole row but i want only n1 outside, how can i achieve that?please echo the value n1 only.

do i need explode or implode?
0
 
twocandlesCommented:
n1, n2, n3 ... I guess they're different row values, am I right? or they're all stored in the same row?

If they are different row values, then don't loop. You just:

$row = mysql_fetch_array($result, MYSQL_BOTH;
echo( $row[0] );

if they are in the same row, then

$row = mysql_fetch_array($result, MYSQL_BOTH;
 $values = explode( ',', $row[0] );
echo( $values[0] );
 
0
 
designersxAuthor Commented:
it is like

name
n1
n2
n3 values of 1 field

$row = mysql_fetch_array($result, MYSQL_BOTH);

this will fetch only first record from the database and will show first entry. what if i want to show n2 or n3 ??

0
 
twocandlesCommented:
If you know what you're looking for, then include it in your query: For example:

SELECT *
FROM YOUR_TABLE
WHERE name = 'n2'

Thus you'll get only one row with your value.
0
 
designersxAuthor Commented:
sir i don't need to fire a query actually.

actually i want to use the names outside the loop that's why i was trying to solve this.please see this , i was trying to do it.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24365101.html
0
 
designersxAuthor Commented:
in line 21 i want to bring the names n1 n2 n3 loop wise .that's it.
<form name="form" action="2.php" method="post">
<input type="submit" name="submit" id="submit" value="save" /><br />
 
<?php
$m=mysql_connect("localhost","root","");
$db=mysql_select_db('try');
 
$sql="select * from tablename1 order by id";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query, MYSQL_BOTH))
{
?>
	<input type="text" name="<?php echo "t".$row['id']; ?>" />
	<a href="2.php?id=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a>
	<br /><br />
<?php
}
 
	if(isset($_POST['submit'])){
		for($i=1;$i<=count($_POST);$i++){
			$c[$_POST["t".$i]]=;// here i want to bring the name line wise so that they can be echoed ??
		}	
		
		for($i=1;$i<=count($_POST);$i++){
			echo $c[$i]."<br>";		// echo in this fashion $a[1], $a[2] and so on in the order wise
		}	
	}

Open in new window

0
 
designersxAuthor Commented:
please rectify my code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.