Jump to content

Archived

This topic is now archived and is closed to further replies.

howrandom

PHP database link, show a link?

Recommended Posts

Hi i am doing a database for a college project and i am getting really confused, my code is the following:

<HTML>
<BODY>
<body bgcolor="#FFFFCC" text="#006600" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<?php
$db=mysql_connect("localhost","hnd","");
mysql_select_db("hnd",$db);
$result=mysql_query("SELECT * FROM RB_Products",$db);
echo "<table border=1>\n";
echo "<TR>
<TD><h2>Item Number</h2></TD>
<TD><h2>Item Name</h2></TD>
<TD><h2>Cost</h2></TD>
<TD><h2>Postage</h2></TD>
<TD><h2>Category</h2></TD>
<TD><h2>In Stock</h2></TD>
<TD><h2>Image</h2></TD>
<TD><h2>Order</h2></TD>
</TR>\n";
while($myrow = mysql_fetch_array($result)){

echo
"<TR>
<TD><h3>$myrow[0]</h3></TD>
<TD><h3>$myrow[1]</h3></TD>
<TD><h3>$myrow[2]</h3></TD>
<TD><h3>$myrow[3]</h3></TD>
<TD><h3>$myrow[4]</h3></TD>
<TD><h3>$myrow[5]</h3></TD>
<TD><img src=$myrow[6]></TD>
<TD><a href=$myrow[7]></TD>
</TR>";
}
echo "</table>\n";
?>
</BODY>
</HTML>

how do i make the line "<TD><a href=$myrow[7]></TD>" display a link when something is typed in? so far when something is typed into the form it shows up when i look in the actual database but it doesnt display in this view stock section, how can i make it so that if i type in for example orderitem1.html how can i make it so it makes it a link to click? [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

Share this post


Link to post
Share on other sites
I am about to have to do something similar, so this will help both of us, but I was pointed in the direction earlier of creating the following code, something to go by anyway.
for the 3 oldest
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]SELECT * FROM `records` ORDER BY date ASC LIMIT 3[/quote]

for the 3 newest
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]SELECT * FROM `records` ORDER BY date DESC LIMIT 3[/quote]
These will sort them based on date, but there might be other ways to do this as well, but when you sort just have it sort the fields with a url, or have it display the urls, but sort by the other field, I don't know but some ideas.

Share this post


Link to post
Share on other sites
[!--quoteo(post=384327:date=Jun 15 2006, 08:15 PM:name=annihilate)--][div class=\'quotetop\']QUOTE(annihilate @ Jun 15 2006, 08:15 PM) [snapback]384327[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]echo '<TD><a href="'.$myrow['7'].'">Link</a></TD>';[/code]
[/quote]


This doesnt work


I dont understand what you mean businessman332211

Share this post


Link to post
Share on other sites
Parse error: parse error, expecting `','' or `';'' in c:\program files\nusphere\apache\htdocs\viewstock.php on line 30

Share this post


Link to post
Share on other sites
on that page, on line 30 add a ; at the end. or show your entire code on that page, and mark line 30

Share this post


Link to post
Share on other sites
<HTML>
<BODY>
<body bgcolor="#FFFFCC" text="#006600" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<?php
$db=mysql_connect("localhost","hnd","");
mysql_select_db("hnd",$db);
$result=mysql_query("SELECT * FROM RB_Products",$db);
echo "<table border=1>\n";
echo "<TR>
<TD><h2>Item Number</h2></TD>
<TD><h2>Item Name</h2></TD>
<TD><h2>Cost</h2></TD>
<TD><h2>Postage</h2></TD>
<TD><h2>Category</h2></TD>
<TD><h2>In Stock</h2></TD>
<TD><h2>Image</h2></TD>
<TD><h2>Order</h2></TD>
</TR>\n";
while($myrow = mysql_fetch_array($result)){

echo
"<TR>
<TD><h3>$myrow[0]</h3></TD>
<TD><h3>$myrow[1]</h3></TD>
<TD><h3>$myrow[2]</h3></TD>
<TD><h3>$myrow[3]</h3></TD>
<TD><h3>$myrow[4]</h3></TD>
<TD><h3>$myrow[5]</h3></TD>
<TD><img src=$myrow[6]></TD>
(line 30!)echo '<TD><a href="'.$myrow[7].'">Link</a></TD>';
</TR>";
}
echo "</table>\n";
?>
</BODY>
</HTML>


there is a ; at the end, still doesnt work...

Share this post


Link to post
Share on other sites
If you have just copied and pasted my code then it wont work as my code works on the premise that your echo statements use single quotes rather than double quotes. So here is the full echo statement with your img tag fixed as well.

[code]echo
'<TR>
<TD><h3>$myrow[0]</h3></TD>
<TD><h3>$myrow[1]</h3></TD>
<TD><h3>$myrow[2]</h3></TD>
<TD><h3>$myrow[3]</h3></TD>
<TD><h3>$myrow[4]</h3></TD>
<TD><h3>$myrow[5]</h3></TD>
<TD><img src="'.$myrow[6].'" alt="Image" /></TD>
<TD><a href="'.$myrow[7].'">Link</a></TD>
</TR>';
}
echo "</table>\n";[/code]

Share this post


Link to post
Share on other sites
he is right I recently found out you can't do concatenations with single quoted strings, you have to use double quotes

Share this post


Link to post
Share on other sites
[!--quoteo(post=384344:date=Jun 15 2006, 09:05 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Jun 15 2006, 09:05 PM) [snapback]384344[/snapback][/div][div class=\'quotemain\'][!--quotec--]
he is right I recently found out you can't do concatenations with single quoted strings, you have to use double quotes
[/quote]
You can, you would just swap each one round, ie where you had a double quote, put a single quote.
[code]echo "<a href='".$row[1]."'>Link</a>";[/code]

Share this post


Link to post
Share on other sites
yes this works i can click on the links but now the data doesnt show it will just paste "$myrow[0] or 1 in the according field but the link is working

Share this post


Link to post
Share on other sites
[!--quoteo(post=384526:date=Jun 16 2006, 11:28 AM:name=howrandom)--][div class=\'quotetop\']QUOTE(howrandom @ Jun 16 2006, 11:28 AM) [snapback]384526[/snapback][/div][div class=\'quotemain\'][!--quotec--]
yes this works i can click on the links but now the data doesnt show it will just paste "$myrow[0] or 1 in the according field but the link is working
[/quote]
Post the page that the link is gooing to ok.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.