Jump to content


Photo

PHP database link, show a link?


  • Please log in to reply
15 replies to this topic

#1 howrandom

howrandom
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 15 June 2006 - 07:09 PM

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\" /]



#2 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 15 June 2006 - 07:15 PM

echo '<TD><a href="'.$myrow['7'].'">Link</a></TD>';

Personal site: NewEnigma  |  Java and JSF Discussion

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 15 June 2006 - 07:16 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 howrandom

howrandom
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 15 June 2006 - 07:28 PM

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


This doesnt work


I dont understand what you mean businessman332211

#5 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 15 June 2006 - 07:38 PM

Try removing the ' ' around the 7
Personal site: NewEnigma  |  Java and JSF Discussion

#6 howrandom

howrandom
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 15 June 2006 - 07:53 PM

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

#7 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 15 June 2006 - 07:54 PM

on that page, on line 30 add a ; at the end. or show your entire code on that page, and mark line 30

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#8 howrandom

howrandom
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 15 June 2006 - 08:01 PM

<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...

#9 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 15 June 2006 - 08:03 PM

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.

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";

Personal site: NewEnigma  |  Java and JSF Discussion

#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 15 June 2006 - 08:05 PM

he is right I recently found out you can't do concatenations with single quoted strings, you have to use double quotes

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#11 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 15 June 2006 - 08:11 PM

[!--quoteo(post=384344:date=Jun 15 2006, 09:05 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Jun 15 2006, 09:05 PM) View Post[/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.
echo "<a href='".$row[1]."'>Link</a>";

Personal site: NewEnigma  |  Java and JSF Discussion

#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 15 June 2006 - 08:15 PM

ah, now I see, thanks. Did the script work for you random.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#13 howrandom

howrandom
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 16 June 2006 - 11:28 AM

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

#14 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 June 2006 - 11:49 AM

[!--quoteo(post=384526:date=Jun 16 2006, 11:28 AM:name=howrandom)--][div class=\'quotetop\']QUOTE(howrandom @ Jun 16 2006, 11:28 AM) View Post[/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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#15 howrandom

howrandom
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 16 June 2006 - 04:30 PM

im doing it using a local server as it is only for a college project

#16 howrandom

howrandom
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 19 June 2006 - 07:44 PM

thank you for your help it is now working :) i just needed to do a little bit of tweaking




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users