howrandom Posted June 15, 2006 Share Posted June 15, 2006 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\" /] Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/ Share on other sites More sharing options...
annihilate Posted June 15, 2006 Share Posted June 15, 2006 [code]echo '<TD><a href="'.$myrow['7'].'">Link</a></TD>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46044 Share on other sites More sharing options...
Ninjakreborn Posted June 15, 2006 Share Posted June 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46045 Share on other sites More sharing options...
howrandom Posted June 15, 2006 Author Share Posted June 15, 2006 [!--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 workI dont understand what you mean businessman332211 Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46050 Share on other sites More sharing options...
annihilate Posted June 15, 2006 Share Posted June 15, 2006 Try removing the ' ' around the 7 Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46052 Share on other sites More sharing options...
howrandom Posted June 15, 2006 Author Share Posted June 15, 2006 Parse error: parse error, expecting `','' or `';'' in c:\program files\nusphere\apache\htdocs\viewstock.php on line 30 Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46056 Share on other sites More sharing options...
Ninjakreborn Posted June 15, 2006 Share Posted June 15, 2006 on that page, on line 30 add a ; at the end. or show your entire code on that page, and mark line 30 Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46058 Share on other sites More sharing options...
howrandom Posted June 15, 2006 Author Share Posted June 15, 2006 <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... Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46059 Share on other sites More sharing options...
annihilate Posted June 15, 2006 Share Posted June 15, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46060 Share on other sites More sharing options...
Ninjakreborn Posted June 15, 2006 Share Posted June 15, 2006 he is right I recently found out you can't do concatenations with single quoted strings, you have to use double quotes Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46061 Share on other sites More sharing options...
annihilate Posted June 15, 2006 Share Posted June 15, 2006 [!--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] Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46065 Share on other sites More sharing options...
Ninjakreborn Posted June 15, 2006 Share Posted June 15, 2006 ah, now I see, thanks. Did the script work for you random. Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46068 Share on other sites More sharing options...
howrandom Posted June 16, 2006 Author Share Posted June 16, 2006 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 Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46229 Share on other sites More sharing options...
redarrow Posted June 16, 2006 Share Posted June 16, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46235 Share on other sites More sharing options...
howrandom Posted June 16, 2006 Author Share Posted June 16, 2006 im doing it using a local server as it is only for a college project Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-46340 Share on other sites More sharing options...
howrandom Posted June 19, 2006 Author Share Posted June 19, 2006 thank you for your help it is now working :) i just needed to do a little bit of tweaking Quote Link to comment https://forums.phpfreaks.com/topic/12095-php-database-link-show-a-link/#findComment-47445 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.