Jump to content


Displaying Database problems


11 replies to this topic

#1 iPsyko

    Young Padawan

  • Members
  • Pip
  • 53 posts

Posted 30 August 2006 - 04:53 PM

I am trying to build a script to link to images in my portfolio, but i keep on getting this error:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/fusionds/public_html/topsecret/portfolio.php on line 39

Here is my code. What am i doing wrong?

<?

mysql_pconnect("localhost","XXXXX","XXXXX");

mysql_select_db("XXXXX);

?>

<?
if(!isset($ID))
{
$result="SELECT * from folio";
while($r=mysql_fetch_array($result)) {

$thumb = $r["thumb"];

$name = $r["name"];

$type = $r["type"];

$date = $r["date"];

$status = $r["status"];

$download = $r["download"];

$deviantart = $r["deviantart"];

$item = $r["item"];


echo "

<div id=\"work\"><div class=\"thumb\"><a href=\"$item\"><img src=\"$thumb\" alt="/" /></a></div>
<div class=\"foliotype\">Name: <span class=\"folioinfo style5\">$name</span><br />
  Type: <span class=\"folioinfo\">$type</span><br />
  Date: <span class=\"folioinfo\">$date</span> <br />
  Status: <span class=\"folioinfo\">$status</span><br />
  <a href=\"$download\"><img src="images/downbutton.png" alt="Download" /></a>
<a href=\"$deviantart\"><img src="images/deviantart.png" alt="View on DeviantART" /></a>
<a href="mailto:ipsyko@egns.net"><img src="images/downbutton.png" alt="Purchase" /></a>
 </div>
</div><br /><br />

";

}
}

?>

Edited by iPsyko, 30 August 2006 - 04:54 PM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 30 August 2006 - 05:13 PM

Well, all I see is incorrect use of double quotes.
Array keys should have single quotes, and you could have saved yourself from having to escape so many double quotes by simply using single quotes to enclose your echo statement.

I'm sure Chaos King sees something while he's fviewing this topic, lol.

#3 Adαm

    Young Padawan

  • Members
  • Pip
  • 189 posts
  • Gender:Male
  • Location:United Kingdom

Posted 30 August 2006 - 05:25 PM

You havent added slashes to all the double quotes in the echo. This should work:

echo "

<div id=\"work\"><div class=\"thumb\"><a href=\"$item\"><img src=\"$thumb\" alt=\"/\" /></a></div>
<div class=\"foliotype\">Name: <span class=\"folioinfo style5\">$name</span><br />
  Type: <span class=\"folioinfo\">$type</span><br />
  Date: <span class=\"folioinfo\">$date</span> <br />
  Status: <span class=\"folioinfo\">$status</span><br />
  <a href=\"$download\"><img src=\"images/downbutton.png\" alt=\"Download\" /></a>
<a href=\"$deviantart\"><img src=\"images/deviantart.png\" alt=\"View on DeviantART\" /></a>
<a href=\"mailto:ipsyko@egns.net\"><img src=\"images/downbutton.png\" alt=\"Purchase\" /></a>
</div>
</div><br /><br />

";


#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 30 August 2006 - 05:38 PM

How stupid of me to miss that, I didn't see that that first one wasn't escaped in the 'alt' part. ;)
Again, just use single quotes, they have less workload on both you and the server instead of escaping 5 trillion other quotes. >.<

#5 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 30 August 2006 - 05:45 PM

Remember that single quotes doesnt parse variables though. You need to use:

echo 'hi, this is ' . $name . ', hello!!!';

You could just close (if thats the right word) for large html blocks (which is quicker) and use something like <?php=$var?>. (or <?php echo $var ?> as php.net reccomends).

But thats going away form the problem....

Edited by .Matt, 30 August 2006 - 05:45 PM.


#6 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 30 August 2006 - 05:51 PM

Ya, lol.
I find that easier to read when troubleshooting, ince it highlights it as syntax instead of a big red block of a string, lol.
It really helps when you've made a script that is over 1237 lines or so (which I have done...). >.<

#7 iPsyko

    Young Padawan

  • Members
  • Pip
  • 53 posts

Posted 30 August 2006 - 05:53 PM

Hey guys, thanks for the help. My problem has been fixed, but now i get this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fusionds/public_html/topsecret/portfolio.php on line 9

here is line 9:

while($r=mysql_fetch_array($result)) {

What am i doing wrong? here is my code:

<?

mysql_pconnect("localhost","XXXXX","XXXXX");

mysql_select_db("XXXXX");

{
$result="SELECT * from folio";

while($r=mysql_fetch_array($result)) {

$thumb = $r["thumb"];

$name = $r["name"];

$type = $r["type"];

$date = $r["date"];

$status = $r["status"];

$download = $r["download"];

$deviantart = $r["deviantart"];

$item = $r["item"];


echo '

<div id=\"work\"><div class=\"thumb\"><a href=\"$item\"><img src=\"$thumb\" alt=\"/\" /></a></div>
<div class=\"foliotype\">Name: <span class=\"folioinfo style5\">$name</span><br />
  Type: <span class=\"folioinfo\">$type</span><br />
  Date: <span class=\"folioinfo\">$date</span> <br />
  Status: <span class=\"folioinfo\">$status</span><br />
  <a href=\"$download\"><img src=\"images/downbutton.png\" alt=\"Download\" /></a>
<a href=\"$deviantart\"><img src=\"images/deviantart.png\" alt=\"View on DeviantART\" /></a>
<a href=\"mailto:ipsyko@egns.net\"><img src=\"images/downbutton.png\" alt=\"Purchase\" /></a>
</div>
</div><br /><br />

';
}
}

?>

Edited by iPsyko, 30 August 2006 - 05:54 PM.


#8 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 30 August 2006 - 06:00 PM

Hmm, same old question due to the same old problem. Always add error reporting to EVERY query.

------------

Just looked at the code, you dont even have a query lol. Your missing a vital function there.

<?

mysql_pconnect("localhost","XXXXX","XXXXX") or die(mysql_error());

mysql_select_db("XXXXX") or die(mysql_error());


$result = @mysql_query("SELECT * from `folio`") or die(mysql_error());

while($r=mysql_fetch_array($result)) 
{

	$thumb = $r['thumb'];
	
	$name = $r['name'];
	
	$type = $r['type'];
	
	$date = $r['date'];
	
	$status = $r['status'];
	
	$download = $r['download'];
	
	$deviantart = $r['deviantart'];
	
	$item = $r['item'];


	echo '<div id="work"><div class="thumb"><a href="' . $item . '"><img src="' . $thumb . '" alt="/" /></a></div>
	<div class="foliotype">Name: <span class="folioinfo style5">' . $name . '</span><br />
	  Type: <span class="folioinfo">' . $type . '</span><br />
	  Date: <span class="folioinfo">' .$date . '</span> <br />
	  Status: <span class="folioinfo">' . $status . '</span><br />
	  <a href="' . $download . '"><img src="images/downbutton.png" alt="Download" /></a>
	<a href="' . $deviantart . '"><img src="images/deviantart.png" alt="View on DeviantART" /></a>
	<a href="mailto:ipsyko@egns.net"><img src="images/downbutton.png" alt="Purchase" /></a>
	</div>
	</div><br /><br />';
}


?>

Notice the mysql_query. You had the query string, but you didn't actually execute it.
i also changed the duoble quotes into single quotes on the array keys (another pet peeve lol)

edit: just noticed you were escaping quotes within single quotes which is not needed and you had some random curly brackets which i have fixed :)

Edited by .Matt, 30 August 2006 - 06:20 PM.


#9 iPsyko

    Young Padawan

  • Members
  • Pip
  • 53 posts

Posted 30 August 2006 - 06:12 PM

Awesome, eveything is fixed, thanks a ton man!

#10 Koncept

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 30 August 2006 - 07:56 PM

Just to let you know you can shorten you code by alot
<?

/**
 * Connect to mySQL Database.
 */
mysql_pconnect("localhost","XXXXX","XXXXX") or die(mysql_error());
mysql_select_db("XXXXX") or die(mysql_error());

/**
 * Query Database.
 */
$results = mysql_query("SELECT * from `folio`") or die(mysql_error());
while($results = mysql_fetch_array($results))
{
	/**
	 * Sort Results /!/ If this was PHP5 We would use a basic array iterator here.
	 */
	foreach($results as $result => $data)
	{
		$$result = $data;
	}
?>

<div id="work">
	<div class="thumb">
		<a href="<?= $item; ?>"><img src="<?= $thumb; ?>" alt="/" /></a>
	</div>
	<div class="foliotype">
		Name: <span class="folioinfo style5"><?= $name; ?></span><br />
		Type: <span class="folioinfo"><?= $type; ?></span><br />
		Date: <span class="folioinfo"><?=$date; ?></span> <br />
		Status: <span class="folioinfo"><?= $status; ?></span><br />
		<a href="<?= $download; ?>"><img src="images/downbutton.png" alt="Download" /></a>
		<a href="<?= $deviantart; ?>"><img src="images/deviantart.png" alt="View on DeviantART" /></a>
		<a href="mailto:ipsyko@egns.net"><img src="images/downbutton.png" alt="Purchase" /></a>
	</div>
</div>
<br /><br />

<?php } ?>

Im not sure if that works since i was in a rush but it can greatly be reduced even more.

#11 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 30 August 2006 - 08:16 PM

Like this lol.
<?
// Connect to mySQL Database.
mysql_pconnect("localhost","XXXXX","XXXXX") or die(mysql_error());
mysql_select_db("XXXXX") or die(mysql_error());
// Query Database.
$results = mysql_query("SELECT * from `folio`") or die(mysql_error());
while($results = mysql_fetch_array($results)){
	 // Sort Results /!/ If this was PHP5 We would use a basic array iterator here.
	foreach($results as $result => $data) $result = $data;
?>
<div id="work">
	<div class="thumb">
		<a href="<?= $item; ?>"><img src="<?= $thumb; ?>" alt="/" /></a>
	</div>
	<div class="foliotype">
		Name: <span class="folioinfo style5"><?= $name; ?></span><br />
		Type: <span class="folioinfo"><?= $type; ?></span><br />
		Date: <span class="folioinfo"><?=$date; ?></span> <br />
		Status: <span class="folioinfo"><?= $status; ?></span><br />
		<a href="<?= $download; ?>"><img src="images/downbutton.png" alt="Download" /></a>
		<a href="<?= $deviantart; ?>"><img src="images/deviantart.png" alt="View on DeviantART" /></a>
		<a href="mailto:ipsyko@egns.net"><img src="images/downbutton.png" alt="Purchase" /></a>
	</div>
</div>
<br /><br />
<?php } ?>

Also, just wondering what you mean by a 'basic array iterator'? Something like array_map() or something?

#12 Koncept

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 30 August 2006 - 08:25 PM

http://en.wikipedia....terator_pattern

also in your script above
$result = $data

does not set the associative array key as a variable.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users