Jump to content

Archived

This topic is now archived and is closed to further replies.

newb

Hmm...PHP Array Errors...

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]

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
k what im trying to do is put some php code in an array and include the code. simple as that.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
im still confused. do i use eval instead of array? or what??? how do i write the code?? pls help.. -.- php newbie here.

Share this post


Link to post
Share on other sites

×

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.