phpkanada Posted October 19, 2009 Share Posted October 19, 2009 Hi, I'm working on a php-based package: openrealty. It has a number of tags available to pull different variables from the database. Now using the tag {listingid} as echo '{listingid}'; works and pulls the correct listing ID from the database. My problem is that I want to use this value for something else. However, I can't store this value in a variable as: $listing_id = (string)'{listingid}'; or $listing_id = '{listingid}'; or $listing_id = "{listingid}"; stores the tag itself in $listing_id and not its value (that is, not the ID itself). What I want is the actual value of the ID for some other operation. Any suggestions? Thx. Link to comment https://forums.phpfreaks.com/topic/178243-listing-id-problem/ Share on other sites More sharing options...
simshaun Posted October 19, 2009 Share Posted October 19, 2009 Just perform whatever operation you used to replace it within an echo context on the variable. Link to comment https://forums.phpfreaks.com/topic/178243-listing-id-problem/#findComment-939767 Share on other sites More sharing options...
phpkanada Posted October 19, 2009 Author Share Posted October 19, 2009 Not quite following. Could you please be a bit more specific? Thanks a bunch. Link to comment https://forums.phpfreaks.com/topic/178243-listing-id-problem/#findComment-939771 Share on other sites More sharing options...
simshaun Posted October 19, 2009 Share Posted October 19, 2009 Well, without knowing exactly how you are converting the tokens into actual values, I can't be more specific. After thinking a bit more, you already have the data that the tokens are replaced with available, so instead of assigning the token value to the variable, just assign the source data to it. For the sake of simplicity, here is an example: <?php /** * Replaces {...} occurrences within the string with their respective values. * * @access public * @param string * @param integer */ function replaceTokens($string, $listId) { $string = _replaceIdToken($string, $listId); return $string; } /** * Replaces {listingid} occurrences with $listId. * * @access private * @param string * @param integer */ function _replaceIdToken($string, $listId) { $string = str_replace('{listingid}', $listId, $string); return $string; } ////////////////////////////////////////////// // Test the token replacement functions ////////////////////////////////////////////// // Test with a fixed value. echo replaceTokens('The listing id is {listingid}.', 10); // Test using values from a database. $result = mysql_query(" SELECT id ,some ,other ,fields FROM someTable ") or die(mysql_error()); if (mysql_num_rows($result) > 0) { echo "<pre>"; while ($row = mysql_fetch_assoc($result)) { echo replaceTokens('The listing id is {listingid}.', $row['id']); $listId = $row['id']; // not $listId = '{listingid}'; } echo "</pre>"; } Link to comment https://forums.phpfreaks.com/topic/178243-listing-id-problem/#findComment-939796 Share on other sites More sharing options...
phpkanada Posted October 19, 2009 Author Share Posted October 19, 2009 Thanks Simshaun. Here is the issue: I want to use the {listingid} value and another variable to search the database for matches and then retrieve some other values from the rows. Something along the line... $fetchit = mysql_query("Select * FROM some_table WHERE somedb_id = '$listing_id' AND some_field_name = 'something'") or die (mysql_error()); Here $listing_id corresponds to the value of {listingid}. However, a simple assignment does not work as I mentioned before. Thx. Link to comment https://forums.phpfreaks.com/topic/178243-listing-id-problem/#findComment-939835 Share on other sites More sharing options...
phpkanada Posted October 19, 2009 Author Share Posted October 19, 2009 One of the openrealty experts advised for using _GET. Works perfect now. Thanks Link to comment https://forums.phpfreaks.com/topic/178243-listing-id-problem/#findComment-939863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.