Jump to content


Photo

Hmm...PHP Array Errors...


  • Please log in to reply
5 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 16 July 2006 - 06:28 AM

<?php
$pages = array(
		  'main'   		 => '
    include "../inc/config.php";
	$query = "SELECT * FROM `thumbs` ORDER BY id DESC";
	$result = mysql_query( $query );
	
	if ( !$result ) {
   		// replace this with your own error code -- one that doesn't display the query
   		die($query.'<br />'.mysql_error());
	}

	echo "<table border='0' width='100%' id='table1'><tr>";
		                
	// Build Table
	while( $row = mysql_fetch_assoc( $result ) ) {
	
		
		$i++;
				
   		echo '<td width="33%" valign="top" height="65">';
   		echo '<a href="?p=' . $row['tid'] . '"><img border="0" src="images/thumbs/' . $row['tid'] . '.jpg"></img><br /></a>Title: <a href="?p=' . $row['tid'] . '">'.$row['title'].'</a><br />Published: '.$row['published'];
   		echo '</td>';
   		
   		if ( $i == 2 ) {
			echo '</tr><tr>';
			$i = NULL;
		} 
	}
	
	echo '</tr></table>'; ', // main page

if (isset($_GET['p']) && isset($pages[$_GET['p']]))
               		 {
                   		   include($pages[$_GET['p']]);
// Include Main Page
                   	 } else if(($p == "main") or ($p =="")) {
                      	   include($pages['main']);

 	 } else { include($pages['error']);       
                }
?>

i get this error:
Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/xx/xx/xx/thumbs.php on line 9


#2 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 16 July 2006 - 08:23 AM

Lets disect this, shall we?

Creating an Array
$pages = array(
  'main'  => '

An array with an element 'main' that has literal code for a value
    include "../inc/config.php";
$query = "SELECT * FROM `thumbs` ORDER BY id DESC";
$result = mysql_query( $query );

if ( !$result ) {

a quote in the literal code we are settign the value of main to, breaking back into script.
  // replace this with your own error code -- one that doesn't display the query

...
further in the script, a syntax error
echo '</tr></table>'; ', // main page


I dont know what you are trying to do here, but i can say one thing: You code is a MESS.
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#3 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 16 July 2006 - 11:24 AM

In line 9 in word doesn't -> ' means end of string. Look, color is not red after.
Try
<?php
$pages = array(
		  'main'   		 => '
    include "../inc/config.php";
	$query = "SELECT * FROM `thumbs` ORDER BY id DESC";
	$result = mysql_query( $query );
	
	if ( !$result ) {
   		// replace this with your own error code -- one that does not display the query
   		die($query."<br />".mysql_error());
	}

	echo "<table border=\"0\" width=\"100%\" id=\"table1\"><tr>";
		                
	// Build Table
	while( $row = mysql_fetch_assoc( $result ) ) {
	
		
		$i++;
				
   		echo "<h2><td width=\"33%\" valign=\"top\" height=\"65\">";
   		echo "<a href=\"?p=\"" . $row["tid"] ."\"><img border=\"0\" src=\"images/thumbs/" . $row["tid"] .".jpg\"></img><br /></a>Title: <a href=\"?p=\"" . $row["tid"] . "\">".$row["title"]."</a><br />Published: ".$row["published"];
   		echo "</td>";
   		
   		if ( $i == 2 ) {
			echo "</tr><tr>";
			$i = NULL;
		} 
	}
	
	echo "</tr></table>";  // main page

if (isset($_GET["p"]) && isset($pages[$_GET["p"]]))
               		 {
                   		   include($pages[$_GET["p"]]);
// Include Main Page
                   	 } else if(($p == "main") or ($p =="")) {
                      	   include($pages["main"]);

 	 } else { include($pages["error"]);}'
);
?>


#4 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 16 July 2006 - 06:40 PM

k what im trying to do is put some php code in an array and include the code. simple as that.

#5 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 16 July 2006 - 07:10 PM

Ah, this is evaling, not including.
If there's another way to do this without using eval then it would be good to look into it, as a general programming rule and for performance reasons.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#6 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 16 July 2006 - 11:22 PM

im still confused. do i use eval instead of array? or what??? how do i write the code?? pls help.. -.- php newbie here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users