I want to retrieve data from database using ajax the data is retrieving successfully but it is not showing properly on page. Maybe it is the issue of if else condition.
Here is my code:
<?php
$query = mysql_query("SELECT * FROM cart_polling WHERE country = '".$_REQUEST['id']."' ORDER BY sort_order ASC") or die(mysql_error());
$record = mysql_num_rows($query);
while($getcontry = mysql_fetch_array($query)){
?>
<div class="Question_Table">
<div class="Question_Title">Q<?php echo $getcontry['sort_order']; ?>-<?php echo $getcontry['question']; ?></div>
<!-- ****** Box1 START ****** -->
<?php
if($getcontry['img1']!=""){
?>
<div class="bg">
<?php
if(isset($_SESSION['id'])){
?>
<div class="img"><center>
<a href="javascript:void(0)" class="op">
<img src="images/pollimg/<?php echo $getcontry['img1']; ?>" width="104" height="102" class="middleimg2" onclick="getValue('<?php echo $_REQUEST['id']; ?>','<?php echo $getcontry['option1']; ?>','<?php echo $getcontry['id']; ?>','1','<?php echo $getcontry['img1'] ?>','<?php echo $getcontry['categoryname'] ?>','<?php echo $getcontry['question']; ?>')" /></a>
</center></div>
<?php } ?>
<div class="Vote_button">
<img src="images/vote_button.png" onclick="sendvar();" align="middle">
<img src="images/view_results.png" onClick="showresult(<?php echo $getcontry['id']; ?>)" align="middle">
</div>
<?php
}
</div>
<?php } ?> // here the while loops end.
I want (<div id="txtHint<?php echo $getcontry['id']; ?>"></div>) this in else condition
and the above code in if condition when I click on image viewresult.png a function call which retrieve data from database. I want the data will show in else condition and the above code including loop shows in if condition.
The txtHint($getcontray['id']) is the id of every record whose value changes dynamically with the help of while loop. And txthint is also saves the response of ajax.
If I am using if condition than while loop is not running in else condition and the id can't pass to AJAX response and the correct data will not show, so how can I do that?
in line: <img src="images/pollimg/
'<?php echo $getcontry['img1'] ?>','<?php echo $getcontry['categoryname'] ?>'
missing 2 semicolon.
'<?php echo $getcontry['img1']; ?>','<?php echo $getcontry['categoryname']; ?>'
UPDATE:
And missing ?> php end syntax at the bottom of your file:
<?php
}
//here is the missing tag:
?>
</div>
<?php } ?> // here the while loops end.
Related
When I echo my own variable to a div container it comes out as plaint text (unformatted). I don't understand why echoing a Magento variable comes out formatted but mine doesn't? Here's my code, in particular the <?php if(!isset($specialPrice)): { ?> section which I created. Here is the code:
<div class="product">
<a href="<?php echo $_item->getProductUrl() ?>"
title="<?php echo $this->escapeHtml($_item->getName()) ?>" class="product-image"><img
src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail') ?>"
alt="<?php echo $this->escapeHtml($_item->getName()) ?>"/></a>
<div class="product-details">
<p class="product-name">
<?php echo $this->escapeHtml($_item->getName()) ?>
</p>
<?php $specialPrice = $productToCheck->getData('special_price');
$orignalPrice = $productToCheck->getData('price');
?>
<?php if(!isset($specialPrice)): { ?>
<?php echo $product['price'] ?>
<?php } else: { ?>
<?php echo $specialPrice ?>
<?php } endif ?>
</div>
</div>
Echoing $product['price'] shows up with its CSS like this:
but if it enters the ELSE statement to display my variable it shows like this:
Does anyone know what could be going wrong?
$product['price'] returns you a unformatting price value.
Maybe you can call a block function, for example $block->getPrice() and in getPrice() you need to format the price by your custom preferences.
If you want to add styles to your price value then you need to use a magento tag class
When an item is chosen on my site, it opens a details page. This is the top of the details page above the html tags:
<?php require_once('dbconnection.php');
mysqli_select_db($conn, $dbname);
$recordID = $_GET['recordID'];
$query_Master_details = "
SELECT *
FROM Master_List
WHERE Master_List.Master_Id = $recordID
";
$Master_details = mysqli_query($conn, $query_Master_details) or die(mysqli_error());
$row_Master_details = mysqli_fetch_assoc($Master_details);
$totalRows_Master_details = mysqli_num_rows($Master_details);
?>
This is the code that makes the body of the page:
<div class="container2">
<div class="category"><h2><?php echo $row_Master_details['Name']; ?></h2></div>
<p><?php echo $row_Master_details['Name']; ?></p>
<p><img src="img/<?php echo $row_Master_details['Img']; ?>" /></p>
<p><?php echo $row_Master_details['Code']; ?></p>
<p><?php echo $row_Master_details['Length']; ?> Characters</p>
<?php
mysqli_free_result($Master_details);
?>
<!-- end .container2 --></div>
What I would like to do is create an if/else statement that will look at the Style_ID of the selected item and determine if the number is > 3. If it is, I want it to choose an item that has a Style_Id of 1, 2, or 3 and the same Length as the item chosen and return a random row in the layout above, skip a few lines and then display the information for the selected item in the layout above. Else if it is < or = 3, then I need it to just display as above.
I have tried using:
<?php
If (Style_ID > 3) {
echo 'Test';
}Else {
<div class="category"><h2><?php echo $row_Master_details['Name']; ?></h2></div>
<p><?php echo $row_Master_details['Name']; ?></p>
<p><img src="img/<?php echo $row_Master_details['Img']; ?>" /></p>
<p><?php echo $row_Master_details['Code']; ?></p>
<p><?php echo $row_Master_details['Length']; ?> Characters</p>
}
?>
<?php
mysqli_free_result($Master_details);
?>
But it doesn't work and has syntax errors. How can I create this if/else statement?
Note: I would appreciate being able to get one setup for all of it, but if not just fixing this part would be a big help right now.
Thanks to #Brad for his responses, I finally got this one figured out. I ended up changing some of my field names and finally figured out where to close the php tags to make this work. Here is what I ended up with:
<div class="container2">
<div class="category"><h2><?php echo $row_master_details['name']; ?></h2></div>
<?php
if ($row_master_details['type_id'] > 3) {
echo "Test";
}else { ?>
<p><?php echo $row_master_details['name']; ?></p>
<p><img src="img/<?php echo $row_master_details['img']; ?>" /></p>
<p><?php echo $row_master_details['item_code']; ?></p>
<p><?php echo $row_master_details['length']; ?> Characters</p>
<?php
mysqli_free_result($master_details);
?>
<?php } ?>
<!-- end .container2 --></div>
For starters, PHP is case-sensitive.
If (...) {
...
}Else {
You'll want to use lower-case if and else.
Next, if Style_ID is an attribute of the record, you'll need to access it like you did the others.
if ($row_Master_details['Style_ID'] > 3) {
From the image below, you can see there is a empty space in second row (red rectangular), by right it should filling up the empty space. This is happening because the first image title is longer than others.
I know by using HTML code, I can use clear: both; and put under the first row to solve it. But my info is read from database. Following is my php and mysql code, I have simplified it, please ignore the method I use to display the image.
$selectSQL="SELECT *, DATE_FORMAT(published_date,'%d %M %Y') AS eventDate FROM media";
while($rows=mysql_fetch_array($selectSQL)){
<div style="float:left">
<img src="load_image.php?id=<?php echo $rows["id"]; ?>" width="150px" height="212px">
<div><?php echo $rows["title"]; ?></div>]
<div><?php echo $rows["eventDate"]; ?></div>
</div>
}
I have one solution, which is compare the number of element = 5. Something like the following code. But I'm not sure how to check it the number of element. Please advice or please suggest me if you have another solutions. Thanks!
if($num_element==5){
echo '<div class="clear"></div>';
}
$ i = 0;
while($rows=mysql_fetch_array($selectSQL)){
<div style="float:left">
<img src="load_image.php?id=<?php echo $rows["id"]; ?>" width="150px" height="212px">
<div><?php echo $rows["title"]; ?></div>]
<div><?php echo $rows["eventDate"]; ?></div>
</div>
$i++;
if($i % 5 == 0){
echo '<div class="clear"></div>';
}
}
you can try this code to check the number of items totally displayed and after 5 elements it will print a clear div
You can use substr() to concat your title when it is very long. you can try it like this:
while($rows=mysql_fetch_array($selectSQL)){
<div style="float:left">
<img src="load_image.php?id=<?php echo $rows["id"]; ?>" width="150px" height="212px">
<div title="<?php echo $rows["title"];?>">
<?php if(strlen($rows["title"]) > 6){
echo substr($rows["title"],0, 6).'...';
}else{
echo $rows["title"];
} ?>
</div>
<div><?php echo $rows["eventDate"]; ?></div>
</div>
}
With this code you can customize the length of the words in your title.
Firstly, I am a total php newby.
Secondly, below is the php header plus corresponding recursive commands for 2 photo lightboxes that are in the same html page.
Without the lines
getRecords() as $Title_row){ ?>
The page shows shows the first picture that is held in the external db table in the lightbox correctly.
Yet when I add the line below to add all the other entries in each table
getRecords() as $Title_row){ ?>
the page goes white and the browser html return is empty.
As I do not really understand what I am doing, I am stuck. Any suggestions would be very welcome.
<?php
$Title_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title_findCriterions = array('Order_web'=>'*',);
foreach($Title_findCriterions as $key=>$value) {
$Title_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title_find,'Title',50);
$Title_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title_result = $Title_find->execute();
if(FileMaker::isError($Title_result)) fmsTrapError($Title_result,"error.php");
fmsSetLastPage($Title_result,'Title',50);
$Title_row = current($Title_result->getRecords());
?>
<?php
$Title1_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title1_findCriterions = array('Order_web'=>'*',);
foreach($Title1_findCriterions as $key=>$value) {
$Title1_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title1_find,'Title',50);
$Title1_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title1_result = $Title1_find->execute();
if(FileMaker::isError($Title1_result)) fmsTrapError($Title1_result,"error.php");
fmsSetLastPage($Title1_result,'Title',50);
$Title1_row = current($Title1_result->getRecords());
?>
<!DOCTYPE html>
<!-- Lightbox Gallery -->
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<!-- Lightbox Gallery End-->
You just missed out the closing brackets :
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
I looked over some solutions, but I coudn't figure out how to get this solved
here is my php
while($row = mysql_fetch_array($result))
{
echo"<div class='span4'>
<h2>$row[title]</h2>
<p>$row[intro]</p>
<p><a class='btn' onclick=parashow($row['contents'])>View details »</a></p>
</div>";
}
I just want to pass the contents into (a function)
and then this function display on click
on div specific id
looking on the web for several hours couldn't help
some say
add
{}
other /' '/
or
'''$row[contents]'''
stil no help
function parashow(x){
//document.getElementById('allrows').style.display = "none";
}
I don't know how to pass $row['contents']
to function argument
and then
get x
and replace it into another div by id ('something')
Try this
while($row = mysql_fetch_array($result))
{
echo"<div class='span4'>
<h2>$row[title]</h2>
<p>$row[intro]</p>
<p><a class='btn' onclick=parashow('".$row['contents']."')>View details »</a></p>
</div>";
}
It's good to generate HTML without PHP:
<?php while($row = mysql_fetch_array($result)) { ?>
<div class='span4'>
<h2><?php echo $row[title]; ?></h2>
<p><?php echo $row[intro]; ?></p>
<p><a class='btn' onclick="parashow('<?php echo $row['contents']; ?>')">View details »</a></p>
</div>
<?php } ?>
try this
<?php while($row = mysql_fetch_array($result)) : ?>
<div class='span4'>
<h2><?php echo $row[title]; ?></h2>
<p><?php echo $row[intro]; ?></p>
<p>View details »</p>
</div>
<?php endwhile; ?>