Jump to content

Hmm...PHP Array Errors...


newb

Recommended Posts

[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 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']);     
                }
?>[/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

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

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 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"]);}'
);
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/14743-hmmphp-array-errors/#findComment-58924
Share on other sites

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.