Jump to content


Photo

PHP Echo Tables Help.


  • Please log in to reply
19 replies to this topic

#1 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 13 March 2006 - 10:35 PM

I have been working on this but it hasn't worked ALL DAY! Please help me.

<?php $sql = mysql_query("SELECT * FROM files WHERE 'game id'='$game id'"); 
$rows = mysql_num_rows($sql); 

if(isset($rows))
{
echo "<table width='600' border='0'><tr><td width='150'>";
echo "<a href='/games.php?<?php echo $row_GameFiles['game id']; ?>=<?php echo $row_GameFiles['game id']; ?>&amp;<?php echo $_GET['fileid']; ?>=<?php echo $row_GameFiles['id']; ?'>";
echo "<?php echo $row_GameFiles['title']; ?></a></td>
			<td width='390'>&nbsp;</td>
			<td width='46'><a href='/games.php?<?php echo $_GET['fileid']; ?>=<?php echo $row_GameFiles['id']; ?>'>Download</a></td>";
			
echo "
		  </tr>
		  </table>";
		  }
		?>
I know this doesn't work but WHY! :-/ help me please!

#2 coolaid

coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 13 March 2006 - 11:35 PM

it dont work cause you havent defined the rows (well.. from what you posted)

<?php $sql = mysql_query("SELECT * FROM files WHERE 'game id'='$game id'");
$row_GameFiles = mysql_fetch_array($sql);

echo "<table width='600' border='0'><tr><td width='150'>";
echo "<a href='/games.php?<?php echo $row_GameFiles['game id']; ?>=<?php echo $row_GameFiles['game id']; ?>&<?php echo $_GET['fileid']; ?>=<?php echo $row_GameFiles['id']; ?'>";
echo "<?php echo $row_GameFiles['title']; ?></a></td>
			<td width='390'> </td>
			<td width='46'><a href='/games.php?<?php echo $_GET['fileid']; ?>=<?php echo $row_GameFiles['id']; ?>'>Download</a></td>";
			
echo "
		  </tr>
		  </table>";
		?>
oh, and im not sure about the sql, but for a fact '$game id' is not a variable. no spaces allowed.

Edited by coolaid, 13 March 2006 - 11:36 PM.


#3 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 13 March 2006 - 11:48 PM

I've got no idea what you mean when you say it doesn't work, but i can take a few guesses as to what's wrong.
$sql = mysql_query("SELECT * FROM files WHERE game id'='$game_id'") or die(mysql_error()); 
$rows = mysql_num_rows($sql); 

if(isset($rows))
{
echo "<table width='600' border='0'><tr><td width='150'>";
echo "<a href='/games.php".$row_GameFiles['game id']."=".$row_GameFiles['game id']."&amp;".$_GET['fileid']."=".$row_GameFiles['id'];
// etc...
Your mysql_query was wrong, and it probably prevented anything from being echoed. You were also re-opening/closing the php tag from with-in php (more info about echoing properly: http://php.net/manua...ction.echo.php).

Also, where did $row_GameFiles come from?

Edit: Coolaid, you did it again... But i will admit, i forgot to mention the $game id thing.

Edited by rc69, 13 March 2006 - 11:49 PM.


#4 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 14 March 2006 - 01:31 AM

HEre are my two tables ill explain what im trying to do.

CREATE TABLE `files` (
  `game id` int(11) NOT NULL,
  `title` char(255) NOT NULL,
  `description` char(255) NOT NULL,
  `author` char(255) NOT NULL,
  `timestamp` char(255) NOT NULL,
  `rateing` char(255) NOT NULL,
  `file dir` char(255) NOT NULL,
  `status` char(255) NOT NULL,
  `type` char(255) NOT NULL,
  `id` mediumint(9) NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2008;

and

CREATE TABLE `games` (
  `name` char(255) NOT NULL,
  `id` mediumint(9) NOT NULL auto_increment,
  `files` char(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8;

Im trying to check have it sowhen someone clicks on the game name (NAME COLUM from games) that it will match the game's ID with all the files that has been submited and show all the ones w/ the same game id.

Im pretty new at this but im learning fast :P

Edited by styles, 14 March 2006 - 01:32 AM.


#5 coolaid

coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 14 March 2006 - 01:51 AM

ok heres a script. dont flood the script with html untill you get it working in php first (thats the way i do it)

but first, its better to leave all variables without spaces (so to replace the column 'game id' with 'gid' or 'game_id').

*******file listing for game*******
<?
$result = mysql_query("select * from files where gid = '". $_GET['id'] ."'");
while($r = mysql_fetch_array($result)){
echo $r['title'] ."<br />\n";
}
?>

and in the file where it lists the games, have it something like this:
*********games listing******
<?
$result = mysql_query("select * from games");
while($r = mysql_fetch_array($result){
echo "<a href=\"file_listing.php?id=". $r['id'] ."\">". $r['name'] ."</a><br />\n";
}
?>

that should clear things up?

#6 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 14 March 2006 - 03:52 AM

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /cheatersdb.com/games.php on line 169

doesn.t like me.. thats if i only have the one script. if i have both it totabbly fucks up. by the one script i mean the top one.

Heres like what im trying to do. Look at the page with only one php script in there that generates the Games from a table. That was simple drag and drop shit. http://www.cheatersdb.com/games.php thats the page. Now i want it so you can click on the games and it will generate from the gameid all the files for that game. how would I do that? I want it all on the games.php page no outside pages.
Thanks So Much!

Edited by styles, 14 March 2006 - 03:55 AM.


#7 coolaid

coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 14 March 2006 - 06:03 PM

man... you have to do it the way i said it.

BUT i changed the column 'game id' to 'gid'..... thats why you get a fetch error.
you just have to switch a few things around. IF you realy dont want to change your column 'game id' to 'gid' then use this code in the file that displays all the files.

<?
$result = mysql_query("select * from files where `game id` = '". $_GET['id'] ."'");
while($r = mysql_fetch_array($result)){
echo $r['title'] ."<br />\n";
}
?>


#8 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 14 March 2006 - 07:05 PM

The first script works great. but
<?
$result = mysql_query("select * from games");
while($r = mysql_fetch_array($result){
echo "<a href=\"file_listing.php?id=". $r['id'] ."\">". $r['name'] ."</a><br />\n";
}
?>
doesn't like the
){
echo "<a href=\"file_listing.php?id=". $r['id'] ."\">". $r['name'] ."</a><br />\n";
}
part. Im getting

Parse error: syntax error, unexpected '{' in /home/.beowulf/hyp3r/cheatersdb.com/games.php on line 162


I did change it and take the space out of games id.

#9 coolaid

coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 14 March 2006 - 09:23 PM

oh tahts cause i forgot to add ) for the while loop....
<?
$result = mysql_query("select * from games");
while($r = mysql_fetch_array($result)){
echo "<a href=\"file_listing.php?id=". $r['id'] ."\">". $r['name'] ."</a><br />\n";
}
?>

Edited by coolaid, 14 March 2006 - 09:23 PM.


#10 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 14 March 2006 - 11:49 PM

Wow you are good. Now all I want is to make the URL Var fid to get the field filedir and thats the collum where the file is location information is and i would like it to download it. Ive had troubles w/ this. Help! Ive even googled this for the past day!

<?php
$result = mysql_query("select * from games");
while($r = mysql_fetch_array($result)){
echo "<a href=\"games.php?id=". $r['id'] ."\">". $r['name'] ."</a><br />\n";
}
?>
<hr>
<?php
$result = mysql_query("select * from files where gid = '". $_GET['id'] ."'");
while($r = mysql_fetch_array($result)){
//echo $r['title'] ."<br />\n"; 
echo "<a href=\"games.php?fid=". $r['id'] ."\">". $r['title'] ."</a><br />\n";


}
	   $filename = $filedir;
		   $filename = realpath($filename);

		   $file_extension = strtolower(substr(strrchr($filename,"."),1));

		   switch ($file_extension) {
			   case "pdf": $ctype="application/pdf"; break;
			   case "exe": $ctype="application/octet-stream"; break;
			   case "zip": $ctype="application/zip"; break;
		   case "rar": $ctype="application/x-rar-compressed"; break;
			   case "doc": $ctype="application/msword"; break;
			   case "xls": $ctype="application/vnd.ms-excel"; break;
			   case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
			   case "gif": $ctype="image/gif"; break;
			   case "png": $ctype="image/png"; break;
			   case "jpe": case "jpeg":
			   case "jpg": $ctype="image/jpg"; break;
			   default: $ctype="application/force-download";
		   }

		   if (!file_exists($filename)) {
			   die("NO FILE HERE");
		   }

		   header("Pragma: public");
		   header("Expires: 0");
		   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		   header("Cache-Control: private",false);
		   header("Content-Type: $ctype");
		   header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
		   header("Content-Transfer-Encoding: binary");
		   header("Content-Length: ".@filesize($filename));
		   set_time_limit(0);
		   @readfile("$filename") or die("File not found.");
?>
whats wrong? its not working right. I want it to grab the filename from the mysql table. on url click download it. But its not working also when you just click on the game name it gives you a File not found.

Thanks

Edited by styles, 15 March 2006 - 09:49 PM.


#11 coolaid

coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 15 March 2006 - 09:58 PM

ok, i didnt understand. you already have a file that displays all games.
then you have a file that displays all files for that game.
now you want what? and post the relavent sql tables too, that would help :o

#12 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 15 March 2006 - 10:07 PM

Ok
<?php
$result = mysql_query("select * from games");
while($r = mysql_fetch_array($result)){
echo "<a href=\"games.php?id=". $r['id'] ."\">". $r['name'] ."</a><br />\n";
}
?>
[
This shows the games. You click on a game then

<hr>
<?php
$result = mysql_query("select * from files where gid = '". $_GET['id'] ."'");
while($r = mysql_fetch_array($result)){
//echo $r['title'] ."<br />\n";
echo "<a href=\"games.php?fid=". $r['id'] ."\">". $r['title'] ."</a><br />\n";
This shows the file with the FILE ID (This is the same tables as i posted before files and games.

Now i wan't it so that when you click on the name of the file inside the game it starts your download thats what this is suposted to do but doesn't work.

$filename = $filedir;
		   $filename = realpath($filename);

		   $file_extension = strtolower(substr(strrchr($filename,"."),1));

		   switch ($file_extension) {
			   case "pdf": $ctype="application/pdf"; break;
			   case "exe": $ctype="application/octet-stream"; break;
			   case "zip": $ctype="application/zip"; break;
		   case "rar": $ctype="application/x-rar-compressed"; break;
			   case "doc": $ctype="application/msword"; break;
			   case "xls": $ctype="application/vnd.ms-excel"; break;
			   case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
			   case "gif": $ctype="image/gif"; break;
			   case "png": $ctype="image/png"; break;
			   case "jpe": case "jpeg":
			   case "jpg": $ctype="image/jpg"; break;
			   default: $ctype="application/force-download";
		   }

		   if (!file_exists($filename)) {
			   die("NO FILE HERE");
		   }

		   header("Pragma: public");
		   header("Expires: 0");
		   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		   header("Cache-Control: private",false);
		   header("Content-Type: $ctype");
		   header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
		   header("Content-Transfer-Encoding: binary");
		   header("Content-Length: ".@filesize($filename));
		   set_time_limit(0);
		   @readfile("$filename") or die("File not found.");
?>


#13 coolaid

coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 15 March 2006 - 10:38 PM

why dont you just make the link in the file listing diretly to the file url.

e.g.
<?php
$result = mysql_query("select * from files where gid = '". $_GET['id'] ."'");
while($r = mysql_fetch_array($result)){
//echo $r['title'] ."<br />\n";
echo "<a href=\" $thecolumn['withthefileurl']  ."\">". $r['title'] ."</a><br />\n";

just change the column id with the real thing
<a href=\" $thecolumn['withthefileurl'] ."\">". $r['title'] ."</a>

#14 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 15 March 2006 - 11:23 PM

I don't get what you mean? I want it the other way so i can have a script (Ive allreay made) and i can upload a file and it will generate where it is and then by the ID of the file it will retreve the info and dl it.

#15 coolaid

coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 16 March 2006 - 11:43 PM

Now i wan't it so that when you click on the name of the file inside the game it starts your download thats what this is suposted to do but doesn't work.


ok, i dont understand what you're tryin to do. from what i read it sounds like you just want a file that can start a download... if thats the case, use a direct link that echoes out the file url in the file-listing page.

#16 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 17 March 2006 - 07:46 PM

Yea alost like that but they have to start the download by clicking hte name of hte file. :P

#17 coolaid

coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 17 March 2006 - 09:22 PM

hrmm ok. so then below is the page that displays all the files right? so that means the file id is is named 'fid'. ok.

<?php
$result = mysql_query("select * from files where gid = '". $_GET['id'] ."'");
while($r = mysql_fetch_array($result)){
//echo $r['title'] ."<br />\n";
echo "<a href=\"games.php?fid=". $r['id'] ."\">". $r['title'] ."</a><br />\n";
?>

so in a new page (actually games.php). you need to use this code to display the files info.
<?
if(isset($_GET['fid'])){
$result = mysql_query("select * from files where fid = '". $_GET['fid'] ."'");
$r = mysql_fetch_array($result);
   echo $r['title'] ."<br />\n";
   echo $r['author'] ."<br />\n";
   echo $r['description'] ."<br />\n";
   echo "<a href=\"". $r['file dir'] ."\" target=\"_blank\">Download the file</a>";
}
?>

that should work....

#18 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 19 March 2006 - 09:08 PM

The only thing that doesn't is the download link its not getnerated right. IT allways shows the link as http://www.cheatersdb.com/ and it allways goes to about:blank and doesn't download. And the description doesn't show or anything like that just download file and that doesn't work. :P

Edited by styles, 19 March 2006 - 09:09 PM.


#19 dotbart

dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 20 March 2006 - 11:36 AM

You're allready in PHP when doing this:
echo "<a href='/games.php?<?php echo $row_GameFiles['game id']; ?>=<?php echo $row_GameFiles['game id']; ?>&<?php echo $_GET['fileid']; ?>=<?php echo $row_GameFiles['id']; ?'>";


Try doing the following:
echo "<a href='/games.php?<?php echo $row_GameFiles['game id']; ?>=<?php echo $row_GameFiles['game id']; ?>&<?php echo $_GET['fileid']; ?>=<?php echo $row_GameFiles['id']; ?'>";


Echo "<a href='games.php?myVariable=$row_GameFiles['game id']'>Blahblah</a>

Don't open PHP inside PHP ;)

Dotbart


I have been working on this but it hasn't worked ALL DAY! Please help me.

<?php $sql = mysql_query("SELECT * FROM files WHERE 'game id'='$game id'"); 
$rows = mysql_num_rows($sql); 

if(isset($rows))
{
echo "<table width='600' border='0'><tr><td width='150'>";
echo "<a href='/games.php?<?php echo $row_GameFiles['game id']; ?>=<?php echo $row_GameFiles['game id']; ?>&<?php echo $_GET['fileid']; ?>=<?php echo $row_GameFiles['id']; ?'>";
echo "<?php echo $row_GameFiles['title']; ?></a></td>
			<td width='390'> </td>
			<td width='46'><a href='/games.php?<?php echo $_GET['fileid']; ?>=<?php echo $row_GameFiles['id']; ?>'>Download</a></td>";
			
echo "
		  </tr>
		  </table>";
		  }
		?>
I know this doesn't work but WHY! :-/ help me please!



#20 styles

styles

    Young Padawan

  • Members
  • Pip
  • 58 posts

Posted 20 March 2006 - 08:25 PM

Yea i understand now and it works the dl and evertying
<?
$resulta = mysql_query("select * from games");
while($ra = mysql_fetch_array($resulta)){
echo "<a href=\"games.php?id=". $ra['id'] ."\">". $ra['name'] ."</a><br />\n";
}

if(isset($_GET['id'])){
$result = mysql_query("select * from files where gid = '". $_GET['id'] ."'");
$r = mysql_fetch_array($result);
   echo $r['title'] ."<br />\n";
   echo $r['author'] ."<br />\n";
   echo $r['description'] ."<br />\n";
   echo "<a href=\"". $r['filedir'] ."\" target=\"_blank\">Download the file</a>";
} else {
   echo "Please Select A Game.";
}
?>

The problem is i don't want the users to know where the file is living so that it saids file=IDOFFILE and while it saids that it downloads it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users