Jump to content

Problem with getting from database


illuz1on

Recommended Posts

Hey,

 

I have this form that when I add the following bit into the big piece of code at the bottom:

 

Parse error: parse error, unexpected $ in /home/capetown/public_html/patrick/display1.php on line 37

 

Anyone know why?

 

 

include("db.php");
$sql = "SELECT * FROM uploaddb";
$data = mysql_query($sql);
while($record = mysql_fetch_assoc($data)) {

$id = $record['id'];
$name1 = $record['name1'];
$desc1 = $record['desc1'];
$publisher = $record['publisher'];

 

<?php
include("db.php");
$sql = "SELECT * FROM uploaddb";
$data = mysql_query($sql);
while($record = mysql_fetch_assoc($data)) {

$id = $record['id'];
$name1 = $record['name1'];
$desc1 = $record['desc1'];
$publisher = $record['publisher'];

$dir = "uploads/";

// Open a known directory, and proceed to read its contents

echo "Current Documents:";
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file!='.' && $file!='..') {
                echo "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#999999\">
  <tr> 
    <td width=\"12%\" rowspan=\"2\" valign=\"top\"><img src=\"file.png\" width=\"94\" height=\"78\"></td>
    <td height=\"64\" colspan=\"2\" valign=\"top\"><strong>$name1</strong><br>
      $desc1</td>
  </tr>
  <tr> 
    <td width=\"75%\" valign=\"top\">Publisher<strong>:</strong> $publisher</td>
    <td width=\"13%\" valign=\"top\"><a href=\"$file\">Download</a></td>
  </tr>
</table><br>";
            }
        }
        closedir($dh);
    }
}
?> 

 

Link to comment
https://forums.phpfreaks.com/topic/62644-problem-with-getting-from-database/
Share on other sites

<?php

include("db.php");

$sql = "SELECT * FROM uploaddb";

$data = mysql_query($sql);

while($record = mysql_fetch_assoc($data)) {

 

$id = $record['id'];

$name1 = $record['name1'];

$desc1 = $record['desc1'];

$publisher = $record['publisher'];

 

$dir = "uploads/";

 

// Open a known directory, and proceed to read its contents

 

echo "Current Documents:";

if (is_dir($dir)) {

    if ($dh = opendir($dir)) {

        while (($file = readdir($dh)) !== false) {

            if ($file!='.' && $file!='..') {

                echo "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#999999\">

  <tr>

    <td width=\"12%\" rowspan=\"2\" valign=\"top\"><img src=\"file.png\" width=\"94\" height=\"78\"></td>

    <td height=\"64\" colspan=\"2\" valign=\"top\"><strong>$name1</strong><br>

      $desc1</td>

  </tr>

  <tr>

    <td width=\"75%\" valign=\"top\">Publisher<strong>:</strong> $publisher</td>

    <td width=\"13%\" valign=\"top\"><a href=\"$file\">Download</a></td>

  </tr>

</table><br>";

            }

        }

        closedir($dh);

    }

}

 

 

 

 

 

}

?>

 

Thanks that worked but now it displays this code like this (4 entries of each record):

 

http://www.capetownalive.co.za/patrick/display1.php

 

Not really displaying properly..

 

<?php
include("db.php");
$sql = "SELECT * FROM uploaddb";
$data = mysql_query($sql);
while($record = mysql_fetch_assoc($data)) {

$id = $record['id'];
$name1 = $record['name1'];
$desc1 = $record['desc1'];
$publisher = $record['publisher'];

$dir = "uploads/";

// Open a known directory, and proceed to read its contents

echo "Current Documents:";
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file!='.' && $file!='..') {
                echo "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#999999\">
  <tr>
    <td width=\"12%\" rowspan=\"2\" valign=\"top\"><img src=\"file.png\" width=\"94\" height=\"78\"></td>
    <td height=\"64\" colspan=\"2\" valign=\"top\"><strong>$name1</strong>

      $desc1</td>
  </tr>
  <tr>
    <td width=\"75%\" valign=\"top\">Publisher<strong>:</strong> $publisher</td>
    <td width=\"13%\" valign=\"top\"><a href=\"$file\">Download</td>
  </tr>
</table>
";
            }
        }
        closedir($dh);
    }
}





}
?>


<?php
include("db.php");
$sql = "SELECT * FROM uploaddb";
$data = mysql_query($sql);

$content = "";
while($record = mysql_fetch_assoc($data)) {
$id 		= $record['id'];
$name1 		= $record['name1'];
$desc1 		= $record['desc1'];
$publisher 	= $record['publisher'];

}

$dir = "uploads/";
$content .= "Current Documents:";

if (is_dir($dir)) {
if ($dh = opendir($dir)) {
	while (($file = readdir($dh)) !== false) {
		if ($file!='.' && $file!='..') {
			$content .= "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#999999\">";
			$content .= "<tr>";
			$content .= "<td width=\"12%\" rowspan=\"2\" valign=\"top\"><img src=\"file.png\" width=\"94\" height=\"78\"></td>";
			$content .= "<td height=\"64\" colspan=\"2\" valign=\"top\"><strong>$name1</strong>$desc1</td>";
			$content .= "</tr>";
			$content .= "<tr>";
			$content .= "<td width=\"75%\" valign=\"top\">Publisher<strong>:</strong>$publisher</td>";
			$content .= "<td width=\"13%\" valign=\"top\"><a href=\"$file\">Download</td>";
			$content .= "</tr>";
			$content .= "</table>";
		}
	}
	closedir($dh);
}
}

echo $content;
?>

Archived

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

×
×
  • Create New...

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.