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?
 
spoxoxConnect With a Mentor Commented:
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
 
nplibConnect With a Mentor Commented:
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 NatarajanConnect With a Mentor LAMP DeveloperCommented:
0
All Courses

From novice to tech pro — start learning today.