Merdok Posted January 18, 2007 Share Posted January 18, 2007 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? Link to comment https://forums.phpfreaks.com/topic/34658-problem-using-echo-to-display-search-results-in-tables/ Share on other sites More sharing options...
whare Posted January 18, 2007 Share Posted January 18, 2007 Your saying the error is in line 54 but I only count 40 so we are missing 14 + lines So if there is some more to the file could we see it as it is hard to help if we dont have everything to work fromThanxWill Link to comment https://forums.phpfreaks.com/topic/34658-problem-using-echo-to-display-search-results-in-tables/#findComment-163333 Share on other sites More sharing options...
Merdok Posted January 18, 2007 Author Share Posted January 18, 2007 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] Link to comment https://forums.phpfreaks.com/topic/34658-problem-using-echo-to-display-search-results-in-tables/#findComment-163348 Share on other sites More sharing options...
fiat Posted January 18, 2007 Share Posted January 18, 2007 you should be terminating the end of each echo statement with ;ieecho ""; Link to comment https://forums.phpfreaks.com/topic/34658-problem-using-echo-to-display-search-results-in-tables/#findComment-163418 Share on other sites More sharing options...
dgiberson Posted January 18, 2007 Share Posted January 18, 2007 or you can change where you are using echo " <whatever > "; to echo ' <whatever here ><whatever on a new line in the editor><something else>'; Link to comment https://forums.phpfreaks.com/topic/34658-problem-using-echo-to-display-search-results-in-tables/#findComment-163448 Share on other sites More sharing options...
fiat Posted January 18, 2007 Share Posted January 18, 2007 also,where you have a lot of html you want to output consider closing out of php and outputing in pure htmlie.[code]<?phpecho "$test";?><tr><td>html here</td></tr><tr><td>html here</td></tr><tr><td>html here</td></tr><?phpecho "continue on here.";?>[/code] Link to comment https://forums.phpfreaks.com/topic/34658-problem-using-echo-to-display-search-results-in-tables/#findComment-163451 Share on other sites More sharing options...
Merdok Posted January 18, 2007 Author Share Posted January 18, 2007 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 informationinclude('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 informationinclude('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! Link to comment https://forums.phpfreaks.com/topic/34658-problem-using-echo-to-display-search-results-in-tables/#findComment-164012 Share on other sites More sharing options...
Merdok Posted January 20, 2007 Author Share Posted January 20, 2007 Could anyone help with this? Its due in Tuesday and i'm starting to panic!! Link to comment https://forums.phpfreaks.com/topic/34658-problem-using-echo-to-display-search-results-in-tables/#findComment-164951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.