Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...The level of expertise is awesome. The nature in which people respond is professional helpful and not the least condescending. I can't say that for most forums..."

Geography

Where in the world do Tek-Tips members come from?
Bersani (Programmer)
27 Jun 12 18:21
I want to be able to show a field value using echo. I have tried $fielname with no success.
vacunita (Programmer)
27 Jun 12 18:24
Can you be a bit less vague?

By "field value" you mean a field from a database?

What does your code look like?

Help us help you.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Bersani (Programmer)
27 Jun 12 18:45
I want to display the value of a field (lastname) from a table.
vacunita (Programmer)
27 Jun 12 19:00
Again too vague.

What Database? MYSQL? MSSQL?

What connection method are you using? ADO? OBDC? Standard MYSQL functions? Improved MYSQL functions? Some wrapper framework?

Assuming you have already made the connection to the database and have run a query that returned some results, each method has a different way of accessing those results.

For example if you used mysql_query(); to run the query, then you would have a variable that holds the results, and then you would need to use mysq_fetch_array, or mysql_fetch_assocto get an array containing the fields of one row at a time.

For instance:

CODE

$results = mysql_query('SELECT fieldname1,fieldname2,fieldname3 FROM mytable');
while($row=mysql_fetch_array($results)
{
  echo $row['fieldname1'];
} 

This would output the fieldname1 field of each row that was returned by the query.

But this is all guess work, you could be using ADO or something else and the example would be completely different.

Look at the PHP Online Manual For lots of examples of how to get data out of a database based on your connection method.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Bersani (Programmer)
27 Jun 12 19:11
I am using a MySQL database (thru Xampp) and PHP. I am new to MySQL and am using PHP runner. However, this program makes it very difficult to insert changes
vacunita (Programmer)
27 Jun 12 22:25
Sorry, I've never used PHP Runner. but perhaps learning the basic way to do it before entrusting it to an application would be better.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Bersani (Programmer)
29 Jun 12 16:31
I agree with you vacunita. However, I have tried several programs with little success. I have trial versions of Dreamweaver, Embarcadero RAD PHP, Zend studio, PHP Runner, Microsoft Expression web, and others. I love MySQL and find it very easy especially with SQLog, but have difficulty with PHP. I am used to Visual Foxpro. I cannot seem to find a good web design program to use with MySQL and the PHP server side scripts. Do you have any suggestions?
vacunita (Programmer)
29 Jun 12 18:21
Personally I've never used a GUI to build the interactions between MYSQL and PHP. I've always done the connections directly.

At its core, the connections are very simple. And getting data is also very easy.


As I said try the basic approach, code the connection by hand so you know what it needs to do, and how it needs to do it. And what each part returns.

As en example, here's a quick code snippet that will connect to a database, and query a table, and display the results from it.

CODE

<?php
// Setup the connection Paramters:  Host, (either an IP address, or a URL, or even localhost if mysql resides in the same physical server as the PHP processor and webserver.),database, user and password
$host		='localhost';
$database	= 'dbname';
$user		= 'username';
$pass		='pwasword';

//Initiate the connection, usage of mysql_error in the die statement is suggetsed when in development to catch any potential mysql errors.
$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
// Select the database to be used 
$db = mysql_select_db($database) or die(mysql_error());

//Setup the query to be run 
$query = 'SELECT * FROM mytable';

// Execute the query
$result = mysql_query($query) or die (mysql_error());

//Display the results. mysql_fetch_array, mysql_fetchAssoc, mysql_fetch_row etc... retrieve one row at a time from the result set returned by mysql_query.
echo "<table border=2>";
while($row = mysql_fetch_array($result))
{
	echo "<tr><td>" . $row['idmytable'] . "</td><td>" . $row['myfield1'] . "</td><td>" . $row['myfield2'] . "</td></tr>";
}

echo "</table>";

?> 


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech

Bersani (Programmer)
29 Jun 12 21:31
I do not understand if 'idmytable' is the same as 'mytable'. I want to thank you for your patience. I am a beginner in PHP.
vacunita (Programmer)
29 Jun 12 22:15
Idmytable refers to just one of your fields.

In the example I chose the ID or primary key of my table as the first column of the HTML table. But it could be any of your fields, just like the other 2 fields.

My primary key is named idmytable.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech

Bersani (Programmer)
29 Jun 12 22:28
I tried it several times but keep on getting:
"; while($row = mysql_fetch_array($result)) { echo "" . $row['id'] . "" . $row['lastname'] . "" . $row['firstname'] . ""; } echo ""; ?>

This is what I see in Firefox and Chrome ; in IE I see nothing.

I am also using SQLyog and can access the database and table easily.

id = primary key
lastname = field 1
firstname = field 2
vacunita (Programmer)
29 Jun 12 22:44
Looks like the PHP isn't getting parsed.

Are you sure you have the webserver correctly set up to parse PHP, and are accessing the file through the web server, such as

http://localhost/nameoffile.php

Rather than opening it directly as a file?

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech

Bersani (Programmer)
29 Jun 12 22:58
I am accessing as you indicated. I have tried placing the test file both in the root (C:\xampp) and the htdocs subdirectory where I have other PHP files (open source) that I can access from a browser. I have had no success.
Bersani (Programmer)
29 Jun 12 23:06
I finally got it. I have installed both Xampp and Xampp lite and was using the wrong one. Thank you very much. You have been very helpful. Where are you located?
Bersani (Programmer)
30 Jun 12 19:32
Now that I know the basic way to display field results on a page, how do I set up controls and make it appealing?
jpadie (TechnicalUser)
1 Jul 12 17:42
just the same way as with normal html output.
either echo html or break out of php and have the html directly on the page

CODE

<?php
/* some php goes here */
?>
<form method="post" action="#" >
 <input type="text" value="test" name="textbox"/>
</form> 
vacunita (Programmer)
2 Jul 12 13:48
Yup. HTML and CSS to make it appealing, and usage of forms and inputs for controls.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web &amp; Tech

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close