By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,457 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,457 IT Pros & Developers. It's quick & easy.

Linking to webpage (Desperately in need of help!!)

P: n/a
I am desperately seeking some help with a program that was supposed to have
been completed last night. I have only been working with PHP for a week. I
have tried and tried and tried, but I am unable to get this program to work.
I posted a question earlier this week "Linking Query Results to a webpage",
however I could never figure out where to add the code and my client added
another complexity (open into a new window).

I have a very simple query that is writing out 4 variables from a 'mysql'
database. One of the variables is a 'url' (ie, www.pfo.biz,
www.corbanusa.com , etc.). I am trying to display the 'url' on a webpage and
let users click on the URL. When they click on the URL it NEEDS to open into
a new window.

I AM VERY BEHIND ON THIS PROJECT..and the little hair I had left I've
already pulled it out!

I am including my program below. The program is very simple and short. If
someone could please cut & paste the code directly into my program, so that
stupid me can't screw it up, I would really appreciate it. Again, I am sorry
for being so stupid this week Can somebody please help me!!!!!! Thanks!
BELOW IS MY CODE

<html><head><title>Get data</title></head>

<body>

<?php

$conn=@mysql_connect("localhost", "root", "")
or die("Err:Conn");
#select the specified database
$rs = @mysql_select_db("autoclub", $conn)
or die("Err:Db");

#create the query
$sql= "SELECT * from nc";

#execute the query
$rs=mysql_query($sql,$conn);

#write the data
while ( $row = mysql_fetch_array($rs) )
{
echo($row["name"]."<br>");
echo($row["address1"]."<br>");
echo($row["cszip"]."<br>");
echo($row["url"]."<br>");
}
?>
</body></html>
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Rudy wrote:
<html><head><title>Get data</title></head>

<body>

<?php

$conn=@mysql_connect("localhost", "root", "")
or die("Err:Conn");
#select the specified database
$rs = @mysql_select_db("autoclub", $conn)
or die("Err:Db");

#create the query
$sql= "SELECT * from nc";

#execute the query
$rs=mysql_query($sql,$conn);

#write the data
while ( $row = mysql_fetch_array($rs) )
{
echo($row["name"]."<br>");
echo($row["address1"]."<br>");
echo($row["cszip"]."<br>"); /* We modify the next line, this requiers that the url from
the db DON'T includes the http:// part of the url */
echo "<a href=\"http://" . $row["url"] . "\">" . $row["url"] ."</a><br>"; }
?>
</body></html>

Jul 23 '05 #2

P: n/a
<html>
<head>
<title>Get data</title>
</head>
<body>
<?php
error_reporting( E_ALL ); // turn off in production

$conn = @mysql_connect( 'localhost', 'root', '' );
if (!$conn)
{
echo "Err:Conn<br />\n";
echo mysql_error() . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}

if (!@mysql_select_db( 'autoclub', $conn ))
{
echo "Err:Db<br />\n";
echo mysql_error( $conn ) . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}

// create the query
$sql = 'SELECT name, address1, cszip, url FROM nc ORDER BY name';

// execute the query
$rs = @mysql_query( $sql, $conn );
// query can also fail !!
if (!$rs)
{
echo "Err:Qry<br />\n";
echo mysql_error() . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}
?>

<table border="1" cellspacing="0" cellpadding="3">
<thead>
<tr>
<th>name</th>
<th>address1</th>
<th>cszip</th>
<th>url</th>
</tr>
</thead>
<tbody>
<?php

// write the data
while ( $row = mysql_fetch_array( $rs ) )
{
echo " <tr>\n";

echo ' <td>';
echo htmlspecialchars( $row['name'] );
echo "</td>\n";
echo ' <td>';
echo htmlspecialchars( $row['address1'] );
echo "</td>\n";

echo ' <td>';
echo htmlspecialchars( $row['cszip'] );
echo "</td>\n";

// Use the url for 'href' atribute value
// and for anchor text. Atribute target="_blank"
// tells browser to open the url in new
// standard browser window. If you want it to
// be "special" (no addressbar wtc.), then you'll
// have to use JavaScript or another client-side
// mechanism.
echo ' <td><a href="';
echo htmlspecialchars( $row['url'] );
echo '" target="_blank">';
echo htmlspecialchars( $row['url'] );
echo "</a></td>\n";

echo " </tr>\n";
}
?>
</tbody>
</table>
</body>
</html>
Jul 23 '05 #3

P: n/a
Great! That works great! Thank you so much for your help!

Rudy
"J.O. Aho" <us**@example.net> wrote in message
news:30*************@uni-berlin.de...
Rudy wrote:
<html><head><title>Get data</title></head>

<body>

<?php

$conn=@mysql_connect("localhost", "root", "")
or die("Err:Conn");
#select the specified database
$rs = @mysql_select_db("autoclub", $conn)
or die("Err:Db");

#create the query
$sql= "SELECT * from nc";

#execute the query
$rs=mysql_query($sql,$conn);

#write the data
while ( $row = mysql_fetch_array($rs) )
{
echo($row["name"]."<br>");
echo($row["address1"]."<br>");
echo($row["cszip"]."<br>");

/* We modify the next line, this requiers that the url from
the db DON'T includes the http:// part of the url */
echo "<a href=\"http://" . $row["url"] . "\">" . $row["url"]

.."</a><br>";
}
?>
</body></html>

Jul 23 '05 #4

P: n/a
Hilario,

Thank you so much for your help. I really love the layout! There is one
small problem. When it "OPENS" a new window the URL appears within the
directory. For example:

When I click on a URL ( www.pfo.biz ) , the new window "opens" to
http://localhost/mysql/www.pfo.biz . All of the URLs are opening to the
directory like this. When I upload it to my site on the internet, it "opens"
to http://www.williams-global.com/www.pfo.biz . How can I get it to just
"open" to http://www.pfo.biz ?

Thanks so much for your help! That really looks good.
Rudy

"Hilarion" <hi******@SPAM.op.SMIECI.pl> wrote in message
news:cn**********@nemesis.news.tpi.pl...
<html>
<head>
<title>Get data</title>
</head>
<body>
<?php
error_reporting( E_ALL ); // turn off in production

$conn = @mysql_connect( 'localhost', 'root', '' );
if (!$conn)
{
echo "Err:Conn<br />\n";
echo mysql_error() . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}

if (!@mysql_select_db( 'autoclub', $conn ))
{
echo "Err:Db<br />\n";
echo mysql_error( $conn ) . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}

// create the query
$sql = 'SELECT name, address1, cszip, url FROM nc ORDER BY name';

// execute the query
$rs = @mysql_query( $sql, $conn );
// query can also fail !!
if (!$rs)
{
echo "Err:Qry<br />\n";
echo mysql_error() . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}
?>

<table border="1" cellspacing="0" cellpadding="3">
<thead>
<tr>
<th>name</th>
<th>address1</th>
<th>cszip</th>
<th>url</th>
</tr>
</thead>
<tbody>
<?php

// write the data
while ( $row = mysql_fetch_array( $rs ) )
{
echo " <tr>\n";

echo ' <td>';
echo htmlspecialchars( $row['name'] );
echo "</td>\n";
echo ' <td>';
echo htmlspecialchars( $row['address1'] );
echo "</td>\n";

echo ' <td>';
echo htmlspecialchars( $row['cszip'] );
echo "</td>\n";

// Use the url for 'href' atribute value
// and for anchor text. Atribute target="_blank"
// tells browser to open the url in new
// standard browser window. If you want it to
// be "special" (no addressbar wtc.), then you'll
// have to use JavaScript or another client-side
// mechanism.
echo ' <td><a href="';
echo htmlspecialchars( $row['url'] );
echo '" target="_blank">';
echo htmlspecialchars( $row['url'] );
echo "</a></td>\n";

echo " </tr>\n";
}
?>
</tbody>
</table>
</body>
</html>

Jul 23 '05 #5

P: n/a
I added this line:

==> echo ' <td><a href="http://';

It works great! Thanks you so much!

Rudy

"Hilarion" <hi******@SPAM.op.SMIECI.pl> wrote in message
news:cn**********@nemesis.news.tpi.pl...
<html>
<head>
<title>Get data</title>
</head>
<body>
<?php
error_reporting( E_ALL ); // turn off in production

$conn = @mysql_connect( 'localhost', 'root', '' );
if (!$conn)
{
echo "Err:Conn<br />\n";
echo mysql_error() . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}

if (!@mysql_select_db( 'autoclub', $conn ))
{
echo "Err:Db<br />\n";
echo mysql_error( $conn ) . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}

// create the query
$sql = 'SELECT name, address1, cszip, url FROM nc ORDER BY name';

// execute the query
$rs = @mysql_query( $sql, $conn );
// query can also fail !!
if (!$rs)
{
echo "Err:Qry<br />\n";
echo mysql_error() . "<br />\n"; // turn off in production
die(" </body>\n</html>");
}
?>

<table border="1" cellspacing="0" cellpadding="3">
<thead>
<tr>
<th>name</th>
<th>address1</th>
<th>cszip</th>
<th>url</th>
</tr>
</thead>
<tbody>
<?php

// write the data
while ( $row = mysql_fetch_array( $rs ) )
{
echo " <tr>\n";

echo ' <td>';
echo htmlspecialchars( $row['name'] );
echo "</td>\n";
echo ' <td>';
echo htmlspecialchars( $row['address1'] );
echo "</td>\n";

echo ' <td>';
echo htmlspecialchars( $row['cszip'] );
echo "</td>\n";

// Use the url for 'href' atribute value
// and for anchor text. Atribute target="_blank"
// tells browser to open the url in new
// standard browser window. If you want it to
// be "special" (no addressbar wtc.), then you'll
// have to use JavaScript or another client-side
// mechanism.
echo ' <td><a href="';
echo htmlspecialchars( $row['url'] );
echo '" target="_blank">';
echo htmlspecialchars( $row['url'] );
echo "</a></td>\n";

echo " </tr>\n";
}
?>
</tbody>
</table>
</body>
</html>

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.