Jump to content

Problem using 'echo' to display search results in tables


Merdok

Recommended Posts

Hi Guys,

I'm trying to add a search function to my website, there is a specific script I have to use as it is for a uni project, however I wanted to alter the layout of the table used to display the search results. The current version uses only 1 column and x amount of rows, however I wanted the table to look like this:
_________________________________________________
|                  |___________________________________|
|                  |___________________________________|
|                  |___________________________________|
|                  |___________________________________|
|____________|___________________________________|

With each instance of this being one result from the search engine, this is the code from the original layout:

[code]echo "\n<tr>\n\t<td bgcolor=\"blue\">" .
"<b><font color=\"white\">"
. "ARTIST : ". $row["artist"]
        . " " .
"</font></b></td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>TITLE :</b>" ." ". $row["title"]
. " " .
        "</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>YEAR :</b>" . " " . $row["year"]
. " " .
"</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>LABEL :</b>" ." ". $row["label"]
. " " .
"</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>BOUGHT :</b>" . " " . $row["bought"]
. " " .
"</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>PRICE :</b>" ." ". "£".$row["price"]
. " " .
"</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"white\">" .
"<b>INFORMATION :</b>" . " " . $row["information"]
. " " .
"</td>\n</tr>";

    }

echo "\n</table>\n";
[/code]

And this is my version of it:

[code]echo "\n<tr>\n\t<td bgcolor=\"blue\">" .
"<b><font color=\"white\">"
. "ARTIST : ". $row["artist"]
        . " " .
"</font></b></td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>TITLE :</b>" ." ". $row["title"]
. " " .
        "</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>YEAR :</b>" . " " . $row["year"]
. " " .
"</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>LABEL :</b>" ." ". $row["label"]
. " " .
"</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>BOUGHT :</b>" . " " . $row["bought"]
. " " .
"</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"silver\">" .
"<b>PRICE :</b>" ." ". "£".$row["price"]
. " " .
"</td>\n</tr>";

echo "\n<tr>\n\t<td bgcolor=\"white\">" .
"<b>INFORMATION :</b>" . " " . $row["information"]
. " " .
"</td>\n</tr>";

    }

echo "\n</table>\n";
[/code]

Now I'm pretty sure I've butchered it, I'm still very much a beginner at PHP but I cannot for the life of my figure out what i've done wrong... the error I am getting is this:

[b]Parse error: parse error, unexpected T_ECHO, expecting ',' or ';' in /home/hullweb/public_html/award/search.php on line 54[/b]

Does anyone have and idea on how to fix this?
Sorry! :)

heres the full file [code]<?php

//--------------------- ---------------------------- CONNECT TO DATABASE --------------------------------------------------
require_once('/includes/conn_AWARD.php');



switch($select)

{

case Artist : $QuerySelect = "SELECT*FROM comics WHERE(comics.group = '$search')"; break;

case Title : $QuerySelect = "SELECT*FROM comics WHERE(comics.series = '$search')"; break;

case Label : $QuerySelect = "SELECT*FROM comics WHERE(comics.title = '$search')"; break;

case Label : $QuerySelect = "SELECT*FROM comics WHERE(comics.issue = '$search')"; break;

}

switch($selectall)

{

case ALL : $QuerySelect = "SELECT*FROM comics WHERE 1"; break;

}

$result = mysql_query($QuerySelect);


//------------------------------------------- SEARCH THE ROWS IN THE cds TABLE -----------------------------------

$numrows = mysql_num_rows($result);

if($numrows != 0)

{

echo "\n<table border=\"0\" width=\"100%\">";

while($row = @mysql_fetch_array($result))

{





//-------------------------------------- DISPLAY THE RESULTS IN A TABLE LAYOUT -------------------------------

echo "    \n\t <tr>"
echo      "<td>"
. $row["cover"]
echo " </td>"
echo "      <td>"
echo " <tr>"
echo "      <td>"
. $row["group"]
echo " </td>"
echo "      </tr>"
echo "      <tr>"
echo "      <td>2
. $row["series"] . $row["issue"]
</td>"
echo "      </tr>"
echo "      <tr>"
echo "      <td>"
. $row["title"]
echo " </td>"
echo "      </tr>"
echo "      <tr>"
echo "      <td>Printed Year:"
. $row["year"]
echo " </td>"
echo "      </tr>"
echo "      <tr>"
echo "      <td>"
. $row["publisher"]
echo " </td></tr>;\n"

    }

echo "</table>\n";

}

else

{

echo "Can't find a record for $search in the $select field $selectall";

}
 
?>
</body>
</html>
[/code]
also,

where you have a lot of html you want to output consider closing out of php and outputing in pure html

ie.

[code]
<?php

echo "$test";

?>

<tr><td>html here</td></tr>
<tr><td>html here</td></tr>
<tr><td>html here</td></tr>

<?php

echo "continue on here.";

?>

[/code]
Thank you! That seems to have removed all of the errors, however it now seems to be bypassing the tables alltogether and going right to the 'else' at the end.

here is the updated code:

[code]<?php

//--------------------- ---------------------------- CONNECT TO DATABASE --------------------------------------------------
require_once('includes/conn_AWARD.php');
// Include the header information
include('template/header.php');

//Search srings are posted to these variables

switch($select)

{

case Series : $QuerySelect = "SELECT*FROM comics WHERE(comics.series = '$search')"; break;

case Title : $QuerySelect = "SELECT*FROM comics WHERE(comics.title = '$search')"; break;

}

switch($selectall)

{

case ALL : $QuerySelect = "SELECT*FROM comics WHERE 1"; break;

}

$result = mysql_query($QuerySelect);


//------------------------------------------- SEARCH THE ROWS IN THE TABLE -----------------------------------

$numrows = mysql_num_rows($result);

if($numrows != 0)

{

echo "\n<table border=\"0\" width=\"100%\">";

while($row = @mysql_fetch_array($result))

{

//-------------------------------------- DISPLAY THE RESULTS IN A TABLE LAYOUT -------------------------------

echo "    \n\n\t <tr>";
echo      "<td>"
. $row["cover"];
echo " </td>";
echo "      <td>";
echo " <tr>";
echo "      <td>"
. $row["groups"];
echo " </td>";
echo "      </tr>";
echo "      <tr>";
echo "      <td>"
. $row["series"] . $row["issue"];
echo " </td>";
echo "      </tr>";
echo "      <tr>";
echo "      <td>"
. $row["title"];
echo " </td>";
echo "      </tr>";
echo "      <tr>";
echo "      <td>Printed Year:"
. $row["year"];
echo " </td>";
echo "      </tr>";
echo "      <tr>";
echo "      <td>"
. $row["publisher"];
echo " </td></tr>\n";

    }

echo "</table>\n";

}

else

{

echo "Can't find a record for $search in the $select field $selectall";

}
//Include the footer information
include('template/footer.php');
?>
[/code]

Would it be easier to do this in CSS? If so then how do I insert the values into the divs as I dont fully understand the variables on this script, they seem to have '.''s everywhere and I dont know what they mean!

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.