Forum Moderators: coopster
I have created a table in MySQL and I am reading rows from MySQL db and creating a listing for each row read. This used to be hard coded in HTML with each listing element having a block of code (no db used) and each block of code had a separate call to javascript for currency translation.
I am now attempting to move this to PHP (which I do not know well). When I execute this in PHP, the converted currency is shown only on the first listing which is created from the first record read, but taking the price of the last record read. All other listings have no converted currency info.
What I need to achieve is that the conversion happens for every record read from the file and then display it within the same listing.
Is there any specific way the js is called to ensure js is executed every time within "while" loop for each record and not (what appears to be) executed only once taking the last row's data and displaying it when the first row is shown on the screen?
Below is the code extract, the js call is in the second block of PROPERTY LISTING section.
Many thanks.
$result = mysql_query("SELECT * FROM tbl_property");
while($row = mysql_fetch_array($result))
{
$property_currency = $row['property_currency'];
$property_price= $row['property_price'];
$property_short_title = $row['property_short_title'];
$property_location = $row['property_location'];
$property_price_plus = $row['property_price_plus'];
$property_page_URL = $row['property_page_URL'];
$property_thumb = $row['property_thumb'];
$property_thumb_alt_text = $row['property_thumb_alt_text'];
$property_ref = $row['property_ref'];
$property_list_desc = $row['property_list_desc'];
$property_price_formated = number_format($property_price);
$spacechar = " ";
// <!-- PROPERTY LISTING -->
echo "<div style=\"margin-bottom:18px;\">";
echo "<div class=\"pListingHeadline\">";
echo "<p class=\"fltL\" style=\"width:78px;margin-right:0;\"> $property_currency $spacechar $property_price_formated $property_price_plus</p>";
echo "<script type=\"text/javascript\">var eurprice_01 = $property_price;</script>";
echo "<p class=\"fltL\" style=\"font-weight:normal;width:42px;margin-right:0;\">approx</p>";
echo "<p id=\"curr_type_01\" class=\"fltL\" style=\"margin-right:0;width:24px;\"></p>";
echo "<p id=\"conv_price_01\" class=\"fltL\" style=\"margin-right:0;width:72px;\"></p>";
echo "<p class=\"fltL\" style=\"margin-right:0;\">$property_short_title </p>";
echo "<p class=\"fltR\" style:\"margin-left:0;\">$property_location </p>";
echo "<br class=\"fltClear\" />";
echo "</div>";
echo "<a href=\"$property_page_URL\"><img src=\"$property_thumb\" width=\"160\" height=\"120\" style=\"float:left; margin-right: 12px;\" /></a>";
echo "<p class=\"button fltR\"><a href=\"$property_page_URL\">View Details >></a></p>";
echo "<p style=\"font-size:11px;margin:10px 0 4px 0;\">$property_ref</p>";
echo "<p style=\"font-size:11px;\">$property_list_desc</p>";
echo "<br class=\"fltClear\" />";
echo "</div>";
}
mysql_close($con);
?>
echo <<<THIS
<div style="margin-bottom:18px;">
<div class="pListingHeadline">
<p class="fltL" style="width:78px;margin-right:0;"> $property_currency $spacechar $property_price_formated $property_price_plus</p>
[b]<script type="text/javascript">var eurprice_01 = $property_price;</script>[/b]
<p class="fltL" style="font-weight:normal;width:42px;margin-right:0;">approx</p>
<p id="curr_type_01" class="fltL" style="margin-right:0;width:24px;"></p>
<p id="conv_price_01" class="fltL" style="margin-right:0;width:72px;"></p>
<p class="fltL" style="margin-right:0;">$property_short_title </p>
<p class="fltR" style:"margin-left:0;">$property_location </p>
<br class="fltClear" />
</div>
<a href="$property_page_URL"><img src="$property_thumb" width="160" height="120" style="float:left; margin-right: 12px;" /></a>
<p class="button fltR"><a href="$property_page_URL">View Details >></a></p>
<p style="font-size:11px;margin:10px 0 4px 0;">$property_ref</p>
<p style="font-size:11px;">$property_list_desc</p>
<br class="fltClear" />
</div>
THIS;
What javascript function are you trying to call? As you may well be able to put that into php as well.
thank you, knowing about heredoc function is useful. I do not know much on PHP nor javascript and am spending my time looking for command references on the web and use the first one that works so the code is not really elegant.
I managed to sort javascript call, the javascript function is in css stylesheet and the hard coded variable names were used for each of hard coded listing which explains the strange results I got.
Many thanks for replying.