FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Importing info from database





DjMilez
Hi,

if I had a chunk of text in a database, what code would I use to import it?

(I already have a syntax to connect to the database)

Thanks...
badai
select field from table?
Fire Boar
$result = mysql_query("SELECT field1 FROM table WHERE field2='sample'");
$row = mysql_fetch_array($result);

field1 can be one field, a comma seperated list of fields or * (* being every field in the table). You can then reference the result by $row['fieldname']. mysql_fetch_array fetches the next row as an array and returns it, or returns false if the next row is invalid. So, for example:

Code:
// Run the database query
$result = mysql_query("SELECT name FROM people WHERE age>='18' ORDER BY name ASC");
$n = 0;
// Loop through all the rows
while ($row = mysql_fetch_array($result))
{
    // Count up the people and echo, each on a different line.
    echo $row['name']." is allowed to drink alcohol. He/she is person number ".++$n.".<br />\n";
}


The query selects the field "name" from each row in "people" provided that on that row the person's age is greater than or equal to 18. It also sorts them so that the names are in ascending order. Then the while loop runs through each row, outputting a comment about each person. Notice that the while loop does not appear to have a conditional statement in it - the actual condition is $row; if it is empty (i.e. the rows have all been dealt with) then the loop will terminate.
Related topics
script backup database
Fantastico could be updated
database problem
Windows Vista Official Thread
Programming links, info, and tutorials
Importing an existing database...
[RESOLVED] 'localhost' database connection error!
New CMS - ToendaCMS - No database necessary!
PHPBB MYSQL Database Question.
SMF install: Unable to connect to FTP server
World of Warcraft - itemstats database
Need Database help!!! Will pay!
Install Joomla...Okay?
http://www.sourcex.info/ - The source code database
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.