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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.