473,385 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
5 1576
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
<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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Rodney King | last post by:
Hi, I have developed an ASP page which dynamically displays a list of checkbox options based on a SQL statement. Here is my code: <div style="OVERFLOW:auto; Height: 150px"> <table> <% dim...
2
by: robert | last post by:
I've made a gallery site for an artist and it works well -- the gallery page has a central large image which is swapped when thumbnail images are clicked. I'm using Dreamweaver's "SwapImage"...
17
by: EkteGjetost | last post by:
This is definitely not the smart thing to do as far as my learning goes, but desperate situations call for desperate measures. The final lab for my introduction to C programming class is due...
2
by: Lior | last post by:
Hi, I have an ASP.NET website that crashes under heavy load. I use a SQL Server DB. I get around 5500 hits per day. I keep getting the timeout expieried connection pool error. Sometimes it even...
6
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I have a drop down list which store all the different brands of product.When i selected the particular brand from the drop down list, it will display all the products with the selected...
9
by: Gordon | last post by:
Hello again, Sorry to repost this request, but I'm under a bit of pressure to find a quick solution. All I basically want is an automatically updating link (OLE, not DDE) between a control in...
8
by: pamelafluente | last post by:
I am beginning aspNet, I know well win apps. Need a simple and schematic code example to start work. This is what I need to accomplish: ---------------------- Given button and a TextBox on a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.