newb Posted July 16, 2006 Share Posted July 16, 2006 [code]<?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 pageif (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']); }?>[/code]i get this error:[code] Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/xx/xx/xx/thumbs.php on line 9[/code] Link to comment https://forums.phpfreaks.com/topic/14743-hmmphp-array-errors/ Share on other sites More sharing options...
Joe Haley Posted July 16, 2006 Share Posted July 16, 2006 Lets disect this, shall we?Creating an Array[b]$pages = array( 'main' => '[/b]An array with an element 'main' that has literal code for a value[b] include "../inc/config.php"; $query = "SELECT * FROM `thumbs` ORDER BY id DESC"; $result = mysql_query( $query ); if ( !$result ) {[/b]a quote in the literal code we are settign the value of main to, breaking back into script.[b] // replace this with your own error code -- one that doesn't display the query[/b]...further in the script, a syntax error[b] echo '</tr></table>'; ', // main page[/b]I dont know what you are trying to do here, but i can say one thing: You code is a MESS. Link to comment https://forums.phpfreaks.com/topic/14743-hmmphp-array-errors/#findComment-58868 Share on other sites More sharing options...
sasa Posted July 16, 2006 Share Posted July 16, 2006 In line 9 in word doesn't -> ' means end of string. Look, color is not red after.Try[code]<?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 pageif (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"]);}');?>[/code] Link to comment https://forums.phpfreaks.com/topic/14743-hmmphp-array-errors/#findComment-58924 Share on other sites More sharing options...
newb Posted July 16, 2006 Author Share Posted July 16, 2006 k what im trying to do is put some php code in an array and include the code. simple as that. Link to comment https://forums.phpfreaks.com/topic/14743-hmmphp-array-errors/#findComment-59037 Share on other sites More sharing options...
ShogunWarrior Posted July 16, 2006 Share Posted July 16, 2006 Ah, this is [b]eval[/b]ing, not including.If there's another way to do this without using [b]eval[/b] then it would be good to look into it, as a general programming rule and for performance reasons. Link to comment https://forums.phpfreaks.com/topic/14743-hmmphp-array-errors/#findComment-59044 Share on other sites More sharing options...
newb Posted July 16, 2006 Author Share Posted July 16, 2006 im still confused. do i use eval instead of array? or what??? how do i write the code?? pls help.. -.- php newbie here. Link to comment https://forums.phpfreaks.com/topic/14743-hmmphp-array-errors/#findComment-59106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.