HalRau Posted November 2, 2011 Share Posted November 2, 2011 I am using the code below to attempt to show stored value only when data is present in the record set. $results[] = " if ({$row['MapLocation']} != NULL ){ echo <a href=\"{$row['MapLocation']}\" target=_blank>Map</a>} "; $i++; What I see on the page is: if ( != NULL ){ echo Map} with Map being a link. I know there is a syntax error somewhere but can't find it. Open to suggestions. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/ Share on other sites More sharing options...
AyKay47 Posted November 2, 2011 Share Posted November 2, 2011 besides the fact that $row['MapLocation'] is not outputing? Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284235 Share on other sites More sharing options...
jotorres1 Posted November 2, 2011 Share Posted November 2, 2011 How about you try this: <?php if ({$row['MapLocation']} != NULL ){ $results[] = '<a href="'.$row['MapLocation'].'" target=_blank>Map</a>'; } $i++; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284242 Share on other sites More sharing options...
HalRau Posted November 2, 2011 Author Share Posted November 2, 2011 Thanks for your help. It is responding, just not correctly. For instance, if the MapLocation field is populated the results page shows "if (http://maps.google.com/maps?q=16303+Truman+RD+Ellisville,+MO+63011-4731&hl=en&sll=37.0625,-95.677068&sspn=60.116586,135.263672&t=h&z=17 != NULL ){ echo Map} " which is the MapLocation data AND the hyper link is correctly populated. The if statement is already inside a php "result" from a search. Bottom line, if the MapLocation field is null I want the result page to show nothing, no "Map" hyper link text or anything. If the MapLocation field is populated then show the word "Map" with the hyperlink embedded. The full $results looks like this $results[] = "<strong>{$row['BusinessName']}</strong><br /> {$row['BusinessDescription']}<br /> {$row['BusinessStreet']} {$row['BusinessCity']} MO, {$row['BusinessPostalCode']} if ({$row['MapLocation']} != NULL ){ echo <a href=\"{$row['MapLocation']}\" target=_blank>Map</a>} <br /> {$row['BusinessPhone']}<br /> <a href=\"{$row['WebAddress']}\" target=_blank>Visit our website</a><br /><br />"; $i++; Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284246 Share on other sites More sharing options...
jotorres1 Posted November 2, 2011 Share Posted November 2, 2011 Try taking out the curly brace in the if condition: This <?php if ({$row['MapLocation']} != NULL ) ?> to this: <?php if ($row['MapLocation'] != NULL ) ?> Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284248 Share on other sites More sharing options...
HalRau Posted November 2, 2011 Author Share Posted November 2, 2011 jotorres1 If I take out the curly brackets I get a syntax error "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/85/6282385/html/search.php on line 54" So it seems they are needed. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284253 Share on other sites More sharing options...
jotorres1 Posted November 2, 2011 Share Posted November 2, 2011 Oh wait, I have a better suggestion. This should do the trick: <?php $results[] = "<strong>{$row['BusinessName']}</strong><br /> {$row['BusinessDescription']}<br /> {$row['BusinessStreet']} {$row['BusinessCity']} MO, {$row['BusinessPostalCode']}"; if ({$row['MapLocation']} != NULL ){ $result[] .= '<a href="'.{$row['MapLocation']}.'" target=_blank>Map</a>'; } $result[] .="<br /> {$row['BusinessPhone']}<br /> <a href=\"{$row['WebAddress']}\" target=_blank>Visit our website</a><br /><br />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284256 Share on other sites More sharing options...
HalRau Posted November 2, 2011 Author Share Posted November 2, 2011 Getting closer but still getting a syntax error. Error: Parse error: syntax error, unexpected '{' in /home/content/85/6282385/html/search.php on line 55 Line 55: if ({$row['MapLocation']} != NULL ){ thanks for your help jotorres1 Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284266 Share on other sites More sharing options...
Xdega Posted November 2, 2011 Share Posted November 2, 2011 that is a pretty explicit parse error you are getting. What happens when you re-move the curly braces as the error suggests? Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284272 Share on other sites More sharing options...
jotorres1 Posted November 2, 2011 Share Posted November 2, 2011 Yea, in this case, you can remove the curly brace, as it is not needed in the if statement. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284274 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 2, 2011 Share Posted November 2, 2011 can you post your query code? cause it might be related to the while loop or etc. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284277 Share on other sites More sharing options...
HalRau Posted November 2, 2011 Author Share Posted November 2, 2011 Here is the entire query and result code. Right now it throws this error Parse error: syntax error, unexpected '{' in /home/content/85/6282385/html/search.php on line 55 Line 55 is $result[] .= '<a href="'.{$row['MapLocation']}.'" target=_blank>Map</a>'; $searchSQL = "SELECT * FROM members WHERE LiveOnWeb ='1' AND BusinessName LIKE '%{$searchTermDB}%' OR BusinessDescription LIKE '%{$searchTermDB}%' OR SearchKeyWords LIKE '%{$searchTermDB}%' ORDER BY BusinessName"; $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "<strong>Sorry, the search term "{$searchTerms}" yielded no results.</strong>"; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "<strong>{$row['BusinessName']}</strong><br /> {$row['BusinessDescription']}<br /> {$row['BusinessStreet']} {$row['BusinessCity']} MO, {$row['BusinessPostalCode']}<br />"; if ($row['MapLocation'] != NULL ) $result[] .= '<a href="'.{$row['MapLocation']}.'" target=_blank>Map</a>'; $result[] .="<br /> {$row['BusinessPhone']}<br /> <a href=\"{$row['WebAddress']}\" target=_blank>Visit our website</a><br /><br />"; $i++; } } } Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284301 Share on other sites More sharing options...
jotorres1 Posted November 2, 2011 Share Posted November 2, 2011 Take away the curly braces from that line as well. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284313 Share on other sites More sharing options...
Pikachu2000 Posted November 2, 2011 Share Posted November 2, 2011 These are the kinds of errors that inconsistency ultimately leads to. You're using different methods of quoting from line to line, and getting confused. Why are you trying to push the strings into an array (the name of which changes from $results to $result halfway through, BTW) then using a concatenation operator to do so? That code is all over the place, and you should really take a few minutes and figure out what you're trying to do with it. If you want to store the results to display later, just push them into a new array and add the html for formatting as the code is echoed. That would probably be quite easy to do in a foreach() loop later in the code. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284319 Share on other sites More sharing options...
HalRau Posted November 2, 2011 Author Share Posted November 2, 2011 To jotorres1, I took out the {} and it allowed the page to load the results but the displayed results ends after the "; and jumps to the next result. The map link doesn't show nor does the link to the website. Here is the code as it stands right now. $results[] = "<strong>{$row['BusinessName']}</strong><br /> {$row['BusinessDescription']}<br /> {$row['BusinessStreet']} {$row['BusinessCity']} MO, {$row['BusinessPostalCode']}<br />"; if ($row['MapLocation'] != NULL ) $result[] .= '<a href="'.$row['MapLocation'].'" target=_blank>Map</a>'; $result[] .="<br /> {$row['BusinessPhone']}<br /> <a href=\"{$row['WebAddress']}\" target=_blank>Visit our website</a><br /><br />"; $i++; I noticed that you are using " $result[] .=" inside the "$results[] =" tag. Could you explain this to the newbie? Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284329 Share on other sites More sharing options...
jotorres1 Posted November 3, 2011 Share Posted November 3, 2011 The .= means: concatenate the string. I notice that you do not close <strong> tag. That might be the problem right there. <strong> Try closing the tag. Also, if that doesn't work, then try doing this last attempt. Add another variable in that loop and make it look like this. $my_string = ""; $my_string .= "<strong>{$row['BusinessName']}</strong><br /> {$row['BusinessDescription']}<br /> {$row['BusinessStreet']} {$row['BusinessCity']} MO, {$row['BusinessPostalCode']}<br />"; if ($row['MapLocation'] != NULL ) $my_string .= '<a href="'.$row['MapLocation'].'" target=_blank>Map</a>'; $my-string .="<br /> {$row['BusinessPhone']}<br /> <a href=\"{$row['WebAddress']}\" target=_blank>Visit our website</a><br /><br />"; $results [] = $my_string; $i++; Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284468 Share on other sites More sharing options...
HalRau Posted November 3, 2011 Author Share Posted November 3, 2011 jotorres1, Your code works!!! Thank you very much. Now I have one last addition that I am trying to get to work. I want the business address, city, state and zipcode to show only if a stored value (ShowAddress) equals 1 or True. Here is the code I have tried: $my_string = ""; $my_string .= "<strong>{$row['BusinessName']}</strong><br /> {$row['BusinessDescription']}<br />"; if ($row['ShowAddress'] == 1 ) $my_string .= "Location: "'.$row['BusinessStreet'].' '.$row['BusinessCity'].'" MO, "'.$row['BusinessPostalCode'].'; if ($row['MapLocation'] != NULL) AND ($row['ShowAddress'] == 1 ) $my_string .= '<a href="'.$row['MapLocation'].'" target=_blank>Map</a>'; $my_string .="<br /> {$row['BusinessPhone']}<br />"; if ($row['WebAddress'] != NULL ) $my_string .= '<a href="'.$row['WebAddress'].'" target=_blank>Visit our website</a>'; $my_string .="<br /><br />"; $results [] = $my_string; $i++; I get this error message: "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/85/6282385/html/search.php on line 54" Line 54 being, $my_string .= "Location: "'.$row['BusinessStreet'].' '.$row['BusinessCity'].'" MO, "'.$row['BusinessPostalCode'].'; I'm sure the problem is in the single or double quotes somewhere. Also, am I doing the if statement for the map correctly now? if ($row['MapLocation'] != NULL) AND ($row['ShowAddress'] == 1 ) Thank you so much for your time and helping this php newbie learn. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284576 Share on other sites More sharing options...
HalRau Posted November 3, 2011 Author Share Posted November 3, 2011 jotorres1, I fixed the problem!! Yeah, this old asp coder is learning PHP!! Thanks everyone for your help. Much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284594 Share on other sites More sharing options...
jotorres1 Posted November 4, 2011 Share Posted November 4, 2011 Glad to hear it works for ya! Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1284978 Share on other sites More sharing options...
HalRau Posted November 4, 2011 Author Share Posted November 4, 2011 Thanks again for all your helpjotorres1 Have another coding project coming up. I am searching for a script that sends an e-mail notification after form data has been stored in a database. Know of anything like that? Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1285008 Share on other sites More sharing options...
jotorres1 Posted November 4, 2011 Share Posted November 4, 2011 Yup. Take a look at my post regarding a simple send mail script. It is very generic, and very easy to understand. Since you already have basic knowledge, and know what to do regarding the database insertion, then all you have to do is modify the code to fit your needs. Here's the link: http://www.jotorres.com/en/2011/10/simple-php-send-mail/ If you have any questions, feel free to ask. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1285009 Share on other sites More sharing options...
HalRau Posted November 4, 2011 Author Share Posted November 4, 2011 Looks interesting. Will check it out. Do you know if it will work on a GoDaddy Linux server? Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1285026 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 4, 2011 Share Posted November 4, 2011 Looks interesting. Will check it out. Do you know if it will work on a GoDaddy Linux server? Shared, VPS or Dedicated? Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1285030 Share on other sites More sharing options...
jotorres1 Posted November 4, 2011 Share Posted November 4, 2011 On a normal basis, it should work. I have a godaddy account on one of my projects, and works just fine. Quote Link to comment https://forums.phpfreaks.com/topic/250287-syntax-problem/#findComment-1285042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.