My Sql data into PHP ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
J#xx
Forum Newbie
Posts: 6
Joined: Wed Feb 04, 2009 2:30 pm

My Sql data into PHP ?

Post by J#xx »

Hi, i'm trying to get some data stored in mysql into a php file without luck.

I created some fields in another php file and they work perfectly, now I just need to call the data from the database to appear in another php file. Could someone please explain why it does'nt seem to want to work ?

Or if simpler, what's the simplest code to get a varchar entry just to appear as text within a php page ?

example: Ive got data stored in customer_rsphere in the Database how would i get that data to appear on the page ?

Yours hopefully,
J#xx
(Scott Perry)
CanMikeF1
Forum Newbie
Posts: 8
Joined: Wed Feb 18, 2009 7:32 am

Re: My Sql data into PHP ?

Post by CanMikeF1 »

I'm assuming that you have connection to your MySQL database, for example:

Code: Select all

<?php #mysql_connect.php
 
// This file contains the database access information.
// This file also establishes a connection to MySQL and selects the database.
 
// Set the database access information as constants.
DEFINE ('DB_USER',     'username');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST',     'localhost');
DEFINE ('DB_NAME',     'db_name');
 
 
// Make the connection
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) 
  OR die ('Could not connect to MySQL: ' . mysql_error());
 
// Select the database
@mysql_select_db(DB_NAME) 
  OR die ('Could not select the database: ' . mysql_error());
?>
 
 
Once connected create a select statement and retrieve the data from MySQL to your PHP code:

Code: Select all

$query = "SELECT column1, column2 FROM table_1;
 
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
 
$value1_from_table  = $row['column1'];
$vallue2_from_table  = $row['column2'];
 
There a ton of ways to handle the data once retrieved from the base. I found that documentation at the PHP website is pretty darn good.
J#xx
Forum Newbie
Posts: 6
Joined: Wed Feb 04, 2009 2:30 pm

Re: My Sql data into PHP ?

Post by J#xx »

Hi, thanks for the reply, I've posted a link to the forum of Zencart regarding this that explains in more detail including the original code.. My fields i'm trying to get to work are rsphere, lsphere, rcyl, lcyl, raxis, laxis, rnearadd, lnearadd, pupdis, optician.

http://www.zen-cart.com/forum/showthread.php?t=120516

If you could take a look because when I applied your suggested changes it all dissapeared.

Appreciate any assistance !

Cheers
J#xx
(Scott Perry)
Post Reply