Help - Search - Member List - Calendar
Full Version: php and MySQL
Krazy Letter Forums > Technology > Tech Help > Programming Help > PHP
peanut butter
hi, anyone know how to use php to print the value of a mysql feld? im trying to make it so i can use fckeditor to edit my website online. also how can i edit a feild in a MYSQL db?
Mynck
CODE
mysql_connect(localhost,$username,$password);
/* Connect to the MySQL thing on localhost, using the specified username and password */

@mysql_select_db($database) or die( "Unable to select database");
/* Select a certain database. If unable to, then stop and print an error message */

$result=mysql_query($query);
/* The $result variable is used to store the result of the query. If you're inserting data or doing some other query that gives no results, then omit the '$result=' */

mysql_close();
/* Close the connection. Having too many MySQL connections open on a server could impact performance. */


I'll assume that you know how to write a MySQL query.
If not, http://dev.mysql.com/doc/refman/5.0/en/tutorial.html


-----Edit-----

More on how to use the table stored in $result :
CODE
$num=mysql_numrows($result);
/* Find the number of rows in $result and store it in $num */

$variable=mysql_result($result,$i,"fieldname");
/* Get the value stored in $result, in row $i, in the column named 'fieldname' and assign it to $variable */
lappy512
What about $row = mysql_fetch_array($result);
It stores $result into an array in $row.
peanut butter
ok i think im getting the jist of it but how do i select a table?
Mynck
CODE
$query = "SELECT " + $fieldname + " FROM " + $tablename + " WHERE " + $conditional + ";";


Where $fieldname can be a single field, a list of fields, or a "*" to represent all fields.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.