Processing database with only one field

Hello,

I have a database with nothing but URLs.

I want to process each of them.  Something like this:

                              foreach (URL) {
                                 echo  $URL;
                              }

How can I do this?
CREATE TABLE `url` (
  `url` varchar(256) character set utf8 collate utf8_unicode_ci default NULL,
  KEY `url` (`url`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
INSERT INTO `url` VALUES('http://www.example.com/');
INSERT INTO `url` VALUES('http://www.example.net/');
INSERT INTO `url` VALUES('http://www.example.org/');

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nplibCommented:
connect to the database,

run a query "select * from url"

create a recordset

the loop through the recordset

if you don't know how to do this,

you need to tell me what sql server you are using.

also

INSERT INTO `url` VALUES('http://www.example.com/');
 is incorrect

insert into 'url' ('column`) values ('http://www.example.com/');

0
Loganathan NatarajanLAMP DeveloperCommented:
0
spoxoxCommented:
There are two forms for the SQL INSERT instruction. nplib shows one; hankknight is also correct.

Having executed the SQL from the original post, the attached PHP script will cycle through the rows.
<?php 
//connect to MySQL
  $username = "ee";
  $password = "";         
  $hostname = "localhost";
  $dbconn   = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
 
//connect to one MySQL database
  $database = mysql_select_db("ee",$dbconn);
 
//text of the query to execute against the database 
  $query    = "SELECT url FROM url";
 
//execute the query, store the result set
  $result   = mysql_query($query) or die(mysql_error());
 
//access all the data, one row at a time
  while ($row = mysql_fetch_array($result)) {
    echo $row["url"] . "\n";
  }
 
   mysql_close($dbconn);
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.