Links in a table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
whakir
Forum Newbie
Posts: 4
Joined: Sat Nov 22, 2003 10:33 am
Location: UK

Links in a table

Post by whakir »

OK, this is my first post so, hello to everyone here, and thanks for this forum. im a bit of a noob to PHP, SQL and trying to learn in the time i have available so here goes. What im trying to do is simple, create a table of files available to download through a website. The only problem i have is the link doesnt work and i need help getting it to work. So who better to ask that the experts. The site is a fan site with a list of game maps, the table is populated ok, but the link? ARRGGHHH!

Code: Select all

$rest = "";
$proj = "5";
$type = "7";

$sql = "SELECT D.auth,D.titl,D.dirn,D.file,D.isdi,D.refe,
               P.opt as proj,T.opt as type
        FROM documents as D, proj as P, type as T
        WHERE D.proj like '%".$proj."%' AND
		D.type like '%".$type."%' AND
		D.type = T.id and D.proj = P.id".$rest."
	ORDER BY D.titl".$rest;
if (($result = mysql_query("$sql"))!=0) {
  echo "<TABLE BORDER=0 table width=390 cellpadding=0 cellspacing=0 class=text><tr>\n";
  echo "<TR><TH>Map Name</TH><TH>Size</TH><TH>File Name</TH>\n";
  while ($row = mysql_fetch_array($result))
  
  &#123; echo "<TR><TD>";
    echo "<A HREF=\**************"";
	  printCol($row,'file');
      echo "">";
	  printCol($row,'titl');
	  echo "</A>";
	  echo "<TD>";
	  printCol($row,'refe');
	  echo "<TD>";
	  printCol($row,'file');
	  echo "<TD>"; &#125;
	
  echo "</table>\n";
&#125; 
else 
  echo "Error ".mysql_errno()." : ".mysql_error();

?>
            <?php mysql_free_result($result); ?>
What can i put where the ************ are to get the download link to work? i tried the folder path but it doesnt work.
Also the code is not all mine so is there any other way to do what i want?

Thanks to all
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

I'm going to guess that printCol is custom function, right? In that case ( I don't know what you're column name for links is) you just want to do:

Code: Select all

<?php
    echo "<A HREF="printCol($row,'link')"";
?>
See if that works, just replace 'link' with what column the links are stored in.
whakir
Forum Newbie
Posts: 4
Joined: Sat Nov 22, 2003 10:33 am
Location: UK

Post by whakir »

Thanks for the response but it didnt work, not sure if i explained it correctly, ive put the origonal uncut table script below. The files are 3 levels deep at the moment, would this effect the d/l link in the table? ive tried different aliases and have been trying to figure this out for ages, its the only thing putting a dampener on my future site. :cry: If i cant figure it out im gonna stick to playing the games instead of trying to contribute to the community. Any help is gratefully accepted.

Code: Select all

<?php
 echo "<TABLE BORDER=0 table width=390 cellpadding=0 cellspacing=0 class=text><tr>\n";
  echo "<TR><TH>Map Name</TH><TH>Size</TH><TH>File Name</TH>\n";
  while ($row = mysql_fetch_array($result))
  
  { echo "<TR><TD>";
    echo "<A HREF=\documents\wolf_files\maps"";  #link to file
	  printCol($row,'file');
      echo "">";
	  printCol($row,'titl');   #title of map
	  echo "</A>";
	  
	  echo "<TD>";
	  printCol($row,'refe');   #file size
	  
	  echo "<TD>";
	  printCol($row,'file');   #file name
	  echo "<TD>"; }
	
  echo "</table>\n";
} 
?>
this is the page http://www.somepleb.co.uk/wolfy/wolfmaps.php

It all seems so simple, but its really doing my nut in, also what does the /n switch do? (if thats what it is)
Last edited by whakir on Sat Nov 22, 2003 2:57 pm, edited 1 time in total.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

OK, I can kinda see whats happening now.
Can you tell me where your script is in relation to the maps?

Ex:
Script folder - /root/Development/wolfy
Maps folder - /root/files/wolf_maps

BTW, \n means new line. THis will cause a newline in the HTML source so you can make your code look nicer.
whakir
Forum Newbie
Posts: 4
Joined: Sat Nov 22, 2003 10:33 am
Location: UK

Post by whakir »

Ahhh. i think i can guess what your gonna say, but i dont know how to sort it.
The script 'is' in a completely different folder,

script: root/development/wolfy/wolfmaps.php
file: root/documents/wolf_files/maps/*.zip

should i put them all in the same place?(big restructure of database and site) or could the script be adjusted to accomidate the difference in locations?

thanks for the help duff. :wink:
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

I think it can still work without restructuring. Try this, still not 100% but i think it might work.

Code: Select all

<?php
echo "<TABLE BORDER=0 table width=390 cellpadding=0 cellspacing=0 class=text><tr>\n";
  echo "<TR><TH>Map Name</TH><TH>Size</TH><TH>File Name</TH>\n";
  while ($row = mysql_fetch_array($result))
 
  { echo "<TR><TD>";
    echo "<A HREF="../../documents/wolf_files/maps/";  //link to file
     printCol($row,'file');
      echo " ">";
     printCol($row,'titl');   //title of map
     echo "</A>";
    
     echo "<TD>";
     printCol($row,'refe');   //file size
    
     echo "<TD>";
     printCol($row,'file');   //file name
     echo "<TD>"; }
   
  echo "</table>\n";
}
?>
whakir
Forum Newbie
Posts: 4
Joined: Sat Nov 22, 2003 10:33 am
Location: UK

Post by whakir »

Duff you are a top bloke (or babe) it works perfect, You cant imagine how much i appreciate this :P :P

I can see it now (i think)
The ../../ denotes the root and how deep?

PS i will restructure and put relevant files in the same folder as the script, im assuming this is the general way of doing things. Thanks again Duff.
:lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:
http://www.somepleb.co.uk/wolfy/wolfmaps.php
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

The ../../ in English pretty much means "Go up 2 folders". Then from there you can specify anywhere you want the link to go. Here's the example I learned by:

Code: Select all

<?php
// Examples:
// forum in /aaa/bbb/ccc/ and this script in /aaa/bbb/ccc/
// --> $phpbb_root_path = './';
// forum in /aaa/bbb/ccc/ and this script in /aaa/bbb/
// --> $phpbb_root_path = './ccc/';
// forum in /aaa/bbb/ccc/ and this script in /aaa/bbb/ddd/
// --> $phpbb_root_path = '../ccc/';
?>
By the way, I'm a guy :)
Post Reply