[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to access the inidividual names coming from database?

Posted on 2009-04-30
12
Medium Priority
?
212 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:designersx
  • 6
  • 6
12 Comments
 
LVL 6

Expert Comment

by:twocandles
ID: 24268986
0
 
LVL 6

Expert Comment

by:twocandles
ID: 24268993
0
 

Author Comment

by:designersx
ID: 24269158
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:twocandles
ID: 24269199
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
 

Author Comment

by:designersx
ID: 24269282
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
 
LVL 6

Expert Comment

by:twocandles
ID: 24269319
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
 

Author Comment

by:designersx
ID: 24269578
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
 
LVL 6

Expert Comment

by:twocandles
ID: 24269954
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
 

Author Comment

by:designersx
ID: 24270176
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
 
LVL 6

Accepted Solution

by:
twocandles earned 375 total points
ID: 24270316
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
 

Author Comment

by:designersx
ID: 24270421
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
 

Author Comment

by:designersx
ID: 24270429
please rectify my code.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question