I have created a test page called syndication.php where mysql data is being created in an Atom feed like this:
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fishing Reports</title>
<subtitle>The latest reports from apporan.com</subtitle>
<link href="http://www.apporan.com/reports" rel="self"/>
<updated><?php echo date3339(); ?></updated>
<author>
<name>Smithers</name>
<email>smithers#fishinhole.com</email>
</author>
<id>tag:apporan.com,2015:http://www.apporan.com/syndication.php</id>
<?php
$i = 0;
while($row = mysql_fetch_array($result))
{
if ($i > 0) {
echo "</entry>";
}
$articleDate = $row['posted'];
$articleDateRfc3339 = date3339(strtotime($articleDate));
echo "<entry>";
echo "<title>";
echo $row['title'];
echo "</title>";
echo "<link type='text/html' href='http://www.apporan.com/reports/report.php?id=".$row['id']."'/>";
echo "<id>";
echo "tag:apporan.com,2015:http://www.apporan.com/reports/report.php?id=".$row['id'];
echo "</id>";
echo "<updated>";
echo $articleDateRfc3339;
echo "</updated>";
echo "<author>";
echo "<name>";
echo $row['author'];
echo "</name>";
echo "</author>";
echo "<summary>";
echo $row['subtitle'];
echo "</summary>";
$i++;
}
?>
</entry>
</feed>
Although this is doing the job. I want to parse/embed this to mye page. Can anyone help me?enter code here
Related
I'm having a hard time displaying the title and note on each row of my database. I want to display one row (with the title and note) after each
from a form in a page heading to the displaying of row datas page.
This is my code below:
//
Let's say that we have 4 rows of datas. In my code, I can only display the first row, because it keeps having the first row's data. This is because the form is in the first php file. Then after I submit the form, it's directed to this file, and it keeps getting the first row.
<?php $con=mysqli_connect("localhost","root","","task");?>
<?php $results = mysqli_query($con, "SELECT * FROM note"); ?>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<?php
$id=$row['id'];
echo ' ';
echo '<button class="call_modal" data-id="$id" style="cursor:pointer;">'. $row['title'] . '</button>';
?>
<?php
}?>
<?php $results = mysqli_query($con, "SELECT * FROM note"); ?>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<div class="note" data-id="<?= $row['id'] ?>">
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<?php
echo '<br><br>';
echo '<div class="padding">'.$row['title'].'';
echo '<br><br><br><br>';
echo ''.$row['note'].'</div>';
?>
</div>
</div>
<?php
}?>
<?php
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
} ?>
The code below is not tested but it should be correct and give you a better idea of what you are doing right/wrong. I hope it helps..
<?php
$con=mysqli_connect("localhost","root","","task");
$results = mysqli_query($con, "SELECT * FROM note");
while ($row = mysqli_fetch_array($results)) { //starting your data row loop
$id=$row['id'];// you are creating a variable here but not using it two lines down.
echo ' ';
//YOUR OLD CODE echo '<button class="call_modal" data-id="$id" style="cursor:pointer;">'. $row['title'] . '</button>';
echo '<button class="call_modal" data-id="$id" style="cursor:pointer;">'. $id . '</button>';// use the variable "$id" that you created here
// You dont need the next two lines, you already did a query and have the data loaded in the "$results" array
/* $results = mysqli_query($con, "SELECT * FROM note");
while ($row = mysqli_fetch_array($results)) */
?> // close the php tag if you are going to switch to html instead of "echoing html"
/* OLD CODE <div class="note" data-id="<?= $row['id'] ?>"> you were missing the "php" in the php tags */
<div class="note" data-id="<?php echo $id; ?>"> // corrected code
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<?php //switching back to php so create your open tag again...
echo '<br><br>';
echo '<div class="padding">'.$row['title'].'';
echo '<br><br><br><br>';
echo ''.$row['note'].'</div>';// you dont NEED the '' before .$row.... unless you want it but its just essentially a blank string
?>
</div>
</div>
<?php
} // ending your "for each data row" here
?>
<?php
// PS you're not using this function anywhere unless its in ommited code?
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
} ?>
In your loop you're using mysqli_fetch_array, which returns an array with each element in that array containing the field value.
What you want is mysqli_fetch_assoc instead, this will return a hash which you can then use the way you're using it now.
Another thing is that you don't need to have 2 loops in there querying the database. And please indent your code, it makes it really hard for you and everyone else to read it.
Here is the updated/cleaned up version of your code. This has been tested, you can find a sample code with instructions to run on my Github here.
<?php
$con = mysqli_connect("localhost", "root", "", "task");
$results = mysqli_query($con, "SELECT * FROM note");
while ($row = mysqli_fetch_assoc($results)) {
$id = $row['id'];
echo ' ';
echo '<button class="call_modal" data-id="' . $id . '" style="cursor:pointer;">'. $row['title'] . '</button>';
?>
<div class="note" data-id="<?= $row['id'] ?>">
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<?php
echo '<br /><br />';
echo '<div class="padding">' . $row['title'];
echo '<br /><br /><br /><br />';
echo $row['note'];
echo '</div>'
?>
</div>
</div>
</div>
</div>
<?php
}
?>
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
I am trying to pass hidden value from page to another page and it work fine only for first record however for other records it's showing error
Here is the code:
$sql = "SELECT id,jdes,title FROM job";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<input type="hidden" id="hidden_user_id" value="<?php echo $row["id"] ?>">
<h3><?php echo $row["title"] ?>:</h3>
<p class="lead">
<?php echo $row["jdes"] ?>
</p>
<button type="button" id="requestthis" class="btn btn-primary">
Request
</button>
<?php
}
} else {
echo "Nothing to display Yet";
}
?>
jobs-inner.php
<?php
echo $_GET['hidden_id'];
?>
Javascript:-
$(function() { //ready function
$('#requestthis').on('click', function(e){ //click event
e.preventDefault();
var hidden_id = $('#hidden_user_id').val();
var url = "jobs-inner.php?hidden_id="+hidden_id;
window.location.replace(url);
})
})
Error:-
Undefined index: hidden_id in C:\wamp64\www\project\jobs-inner.php on line 3
It might be a simple problem but I am a beginner and I can't figure it out.
Your value is unique but the id isn't. Make the id of the input unique something like below.
<input type="hidden" id="hidden_user_<?php echo $row["id"] ?>" value="<?php echo $row["id"] ?>">
but you would have to do a count on code below to make it display base on how many rows you have.
<?php
echo $_GET['hidden_id'];
?>
Without JavaScript
$sql = "SELECT id,jdes,title FROM job";
$result = $conn->query($sql);
$count = 1;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<input type="hidden" id="hidden_user_<?php echo $count ?>" value="<?php echo $row["id"] ?>">
<h3><?php echo $row["title"] ?>:</h3>
<p class="lead"><?php echo $row["jdes"] ?></p>
<form id="<?php echo $count ?>" action="jobs-inner.php?hidden_id=<?php echo $row["id"] ?>" method="post">
<input type="submit" vaule="Request">
</form>
<?php
$count++;
}
} else {
echo "Nothing to display Yet";
}
?>
I have problems with my php that generates a table, requests data from a SQL database, and stores data in the table.
The first cell of each row in the table contains a dropdown button which links to a delete.php script that deletes the row. It also links to a modif.php script used to modify the row's cells.
My problem is that i need to access the dropdown buttons with IDs to know which row to delete.
And i don't really know how to link my dropdown buttons with IDs and access them in my scripts.
Here's the code :
<?php
$con=mysqli_connect("localhost","root","icare","icare1");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM magasin");
echo "<table border='1'>
<tr>
<th>code</th>
<th>ip</th>
<th>ads</th>
<th>region</th>
<th>adress</th>
<th>name</th>
<th>email</th>
<th>number</th>
<th>gtc</th>
<th>date</th>
</tr>";
$indexB = array();
$i = 0;
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>
<div class='dropdown'>
<button id=$indexB[$i] class='dropbtn'>▶</button>
<div class='dropdown-content'>
<a href='modif.php'>Modifier</a>
<a href='delete.php'>Supprimer</a>
</div>
".$row['code']."
</div>
</td>";
echo "<td><div>" . $row['ip'] . "</div></td>";
echo "<td><div>" . $row['ads'] . "</div></td>";
echo "<td><div>" . $row['region'] . "</div></td>";
echo "<td><div>" . $row['adress'] . "</div></td>";
echo "<td><div>" . $row['name'] . "</div></td>";
echo "<td><div>" . $row['email'] . "</div></td>";
echo "<td><div>" . $row['number'] . "</div></td>";
echo "<td><div>" . $row['gtc'] . "</div></td>";
echo "<td><div>" . $row['date'] . "</td>";
echo "</tr>";
$i++;
}
echo "</table>";
mysqli_close($con);
?>
And here is the delete.php :
<?php
$connection = mysqli_connect("localhost", "root", "icare", "icare1");
if($connection === false){
die("Connection failed " . mysqli_connect_error());
};
//$id =
$sql = "DELETE FROM magasin WHERE Code=".$id;
//$result = mysqli_query($connection,$sql);
if(mysqli_query($connection, $sql)){
echo "Done !";
} else{
echo "Failed : $sql. " . mysqli_error($connection);
}
mysqli_close($connection);
?>
I started an indexB[] to store the dropdowns IDs but i'm not sure that i'm doing it right.
In the end I want to link my buttons to the code attribute and then delete the row with my sql query using the code attribute.
I'm new to this so ... sorry if i did or ask something plain stupid.
UPDATE :
To mikrafizik :
I tried your answer but it doesn't work. I only get "1">Supprimer". It seemsi have a problem with the href but i just can't find why.
I don't know what i forgot, so if you see something wrong :
<?php
$con=mysqli_connect("localhost","root","icare","icare1");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM magasin");
echo "<table border='1'>
<tr>
<th>Code</th>
<th>Adresse IP</th>
<th>Adresse ADS</th>
<th>Région</th>
<th>Adresse</th>
<th>Nom du directeur</th>
<th>Mail</th>
<th>Téléphone</th>
<th>GTC</th>
<th>Date d'installation</th>
</tr>";
$data = mysqli_fetch_array($result);
?>
<table>
<?php foreach ($data as $key => $row):?>
<tr>
<td>
<div class='dropdown-content'>
<button class='dropbtn'>▶</button>
<!-- Modifier -->
Supprimer
</div>
</td>
<td><div><?php echo $row['AdresseIP'];?></div></td>
<td><div><?php echo $row['AdresseADS'];?></div></td>
<td><div><?php echo $row['Region'];?></div></td>
<td><div><?php echo $row['Adresse'];?></div></td>
<td><div><?php echo $row['NomDirecteur'];?></div></td>
<td><div><?php echo $row['Mail'];?></div></td>
<td><div><?php echo $row['Tel'];?></div></td>
<td><div><?php echo $row['Gtc'];?></div></td>
<td><div><?php echo $row['DateInstall'];?></td>
</tr>
<?php endforeach; ?>
</table>
<?mysqli_close($con);?>
delete.php :
<?php
$connection = mysqli_connect("localhost", "root", "icare", "icare1");
if($connection === false){
die("Connexion échouée " . mysqli_connect_error());
};
$id = $_GET['id'];
$sql = "DELETE FROM magasin WHERE Code=".$id;
$result = mysqli_query($connection,$sql);
if($result){
echo "Enregistrement réussi !";
} else{
echo "Enregistrement échoué : $sql. " . mysqli_error($connection);
}
mysqli_close($connection);
?>
At first, divide query and form building like that
$data = mysqli_fetch_array($result)
then
<?php foreach ($data as $key => $row): ?>
<tr>
<td>
<div class='dropdown-content'>
<a href='modif.php?id=<?=$row['id']?>'>Modifier</a>
<a href='delete.php?id=<?=$row['id']?>'>Supprimer</a>
</div>
</td>
</tr>
<?php endforeach ?>
And in your modif.php
$id = $_GET['id'];
(Concerns Flumble_'s answer, that I can't comment because of my low rep)
Maybe the <?= ?> are the problem. Try replacing them with <?php ?>
UPDATE :
You should also never use short open tags (<? ?>) : See the answer to this question.
Also, when you write <?php $row['id'] ?>, you are not printing the value. You must write <?php echo $row['id']; ?>.
The same thing applies with short open tags (but not with the <?= syntax).
Hope this helps further. I will continue reviewing your code.
UPDATE 2 :
Alright I think I got it.
mysqli_fetch_array returns a row, not the entire result set. So you have to loop through the rows until mysqli_fetch_array returns NULL :
while($data = mysqli_fetch_array($result)) {
?>
<tr>
<!-- ... -->
</tr>
<?php
}
I am using the following code to create a form, that is paginated using java script (that someone on this forum supplied for me, I do not have a lot of experience with Java Script), my understanding is that the JavaScript simply hides\unhides tagged sections of the form.
At the moment, my buttons for the paginated form all look identical, I would like to add some CSS style formatting to highlight the chosen form 'page' number, but my experiments have been unsuccessful so far. Here is my code:
<?php
$PageID = 0;
echo ('<script src="https://code.jquery.com/jquery-1.11.2.js"></script>');
echo ("\n");
echo ('<form>');
foreach ($ListSections as $sections)
{
if ($PageID == 0)
{
echo ('<div id="Page' . $PageID . '" class="informbdy2">');echo ("\n");
}
else
{
echo ('<div id="Page' . $PageID . '" class="informbdy2" style="display:none">');echo ("\n");
}
echo ("<br>");
$PageNum = $PageID +1;
echo ('<p style="cursor:pointer; color:black; background-color: #DBB7BA; border-radius: 8px; border-color: #860A18; padding-left: 6px; padding-right: 6px; "> Section ' . $PageNum . ': ');
echo ($sections[1] . "<br>");
$QuestionNum = 0;
foreach ($ListQs as $value)
{
if ($value[1] == $sections[1])
{
echo ('<div ');
echo ('id="questionsform"');
echo ('name="questionsform"');
echo ('method="post" ');
echo ('action="admin_questions.php"');
echo ('>');
echo ("<input type='hidden' name='MyID' value='" . $value[0] . "'); />");
echo ("<table>");
echo ("<tr>");
echo ("<td>");
echo ("<label for='Question' class='logintext'>Question:</label>");
echo ("</td>");
echo ("<td>");
echo ('<textarea name="Question" rows="2" cols="25">');
echo ("$value[3]");
echo ('</textarea>');
echo ("</td>");
echo ("<td>");
echo ("</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td>");
echo ("<label for='Answer1' class='logintext'>Answer 1:</label>");
echo ("</td>");
echo ("<td>");
echo ('<textarea name="Answer1" rows="1" cols="25">');
echo ("$value[4]");
echo ('</textarea>');
echo ("</td>");
echo ("<td>");
echo ("<input type='radio' name='" . $QuestionNum . "ans1' value='1' >1");
echo ("</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td>");
echo ("<label for='Answer2' class='logintext'>Answer 2:</label>");
echo ("</td>");
echo ("<td>");
echo ('<textarea name="Answer2" rows="1" cols="25">');
echo ("$value[5]");
echo ('</textarea>');
echo ("</td>");
echo ("<td>");
echo ("<input type='radio' name='" . $QuestionNum . "ans2' value='2' >2");
echo ("</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td>");
echo ("<label for='Answer3' class='logintext'>Answer 3:</label>");
echo ("</td>");
echo ("<td>");
echo ('<textarea name="Answer3" rows="1" cols="25">');
echo ("$value[6]");
echo ('</textarea>');
echo ("</td>");
echo ("<td>");
echo ("<input type='radio' name='" . $QuestionNum . "ans3' value='3' >3");
echo ("</td>");
echo ("</tr>");
echo ("</td>");
echo ("</tr>");
echo ("</table>");
echo ('</div>');
echo ('</br>');
echo ('</br>');
}
}
$PageID++;
echo ('</div>');
}
echo ('</div>');
echo ('</form>' ."\n");
?>
<?php
// Create Page Menu's for the form
$PageID = 0;
echo ('<div id="page_menus">' ."\n");
echo ("</br>CLICK TO SELECT PAGE >> ");
foreach ($ListSections as $PageMenu)
{
$mystring = '<a id="get_';
//echo ($mystring);
$mystring = $mystring . $PageID;
//echo ($mystring);
$mystring = $mystring . '" style="cursor:pointer; color:black; background-color: #DBB7BA; border-radius: 8px; border-color: #860A18; padding-left: 6px; padding-right: 6px; ">';
//echo ($mystring);
++$PageID;
$mystring = $mystring . $PageID . '</a>' ."\n";
echo ($mystring);
}
echo ('</div>' . "\n" . '</br>'."\n");
//Script to show and hide each 'Page' of the form
echo ("\n");
$PageID = 0;
?>
<script>
<?php
foreach ($ListSections as $ShowHide)
{
$MyPage = "Page" . $PageID;
$MyGet = "get_" . $PageID;
?>
var my_get = <?php echo json_encode("#" . $MyGet); echo ("\n");
?>;
$(my_get).click(function(){
<?php $OtherPage = 0;
foreach ($ListSections as $Midsections)
{
$ThisPage = "Page" . $OtherPage;
if ($Midsections[1] <> $ShowHide[1])
{
?>
var noshow_page = <?php echo json_encode("#" . $ThisPage);
?>;
$(noshow_page).hide()
<?php
}
else
{
?>
var noshow_page = <?php echo json_encode("#" . $ThisPage);?>;
$(noshow_page).show()
<?php
}
$OtherPage++;
}
?>;
})
<?php
$PageID++;
}
?>
</script>
How would I add CSS type formatting to the page menu items (under the section commented "// Create Page Menu's for the form") to show that a certain 'page' of the form is selected? The problem is that the web-page is not re-loaded, so I cannot simply track the button presses and re-format using 'if' style logic and CSS.
Thank you,
Lee
You would need to add some JS to handle the click and then you can style using CSS.
HTML:
<div id="page_menus">
<a id="get_01">1</a>
<a id="get_02">2</a>
<a id="get_03">3</a>
<a id="get_04">4</a>
<a id="get_05">5</a>
</div>
JS:
jQuery('#page_menus a').on('click', function() {
if ($('a').hasClass('current')) {
$('a').removeClass('current');
}
$(this).addClass('current');
});
CSS:
#page_menus a {
cursor:pointer;
color:black;
background-color: #DBB7BA;
border-radius: 8px;
border-color: #860A18;
padding-left: 6px;
padding-right: 6px;
}
#page_menus a.current {
background-color: #ccc;
}
Here is a working fiddle.
I am getting following error on the browser console when I am on checkout page.
ReferenceError: payment is not defined
When I click on the credit card payment option no Form is opened to enter card details and above mentioned error is thrown.
For the Credit card authorize.net option in Magento admin is being used.I am also using the paypal express checkout
I have following code in the template\checkout\onepage\payment\methods.phtml file
<dl class="sp-methods" id="checkout-payment-method-load">
<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php echo $this->getfieldshtml(1); ?>
<?php
foreach ($methods as $_method):
$_code = $_method->getCode();
?>
<dt>
<?php if(!$oneMethod): ?>
<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<?php else: ?>
<span class="no-display"><input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" checked="checked" class="radio" /></span>
<?php $oneMethod = $_code; ?>
<?php endif; ?>
<label for="p_method_<?php echo $_code ?>"><?php echo $this->getMethodTitle($_method) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
</dt>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd>
<?php echo $html; ?>
</dd>
<?php endif; ?>
<?php endforeach; ?>
<?php echo $this->getfieldshtml(2); ?>
<?php echo $this->getfieldshtml(3); ?>
</dl>
<?php echo $this->getChildChildHtml('additional'); ?>
<script type="text/javascript">
//<![CDATA[
//function obsrv(id){
// if(id && id!=null){
// $$("#"+id+" input,#"+id+" label,#"+id+" select").each(function(onebyone){if($(onebyone.id) && $(onebyone.id)!=null){$(onebyone.id).removeAttribute("disabled");}});
// }
// }
<?php echo $this->getChildChildHtml('scripts'); ?>
$$("#co-payment-form input,#co-payment-form select").each(function(onebyone){if($(onebyone.id) && $(onebyone.id)!=null && onebyone.name.startsWith('fm_fields')){if(true){$(onebyone.id).removeAttribute("disabled");}}});
<?php if (is_string($oneMethod)): ?>
payment.switchMethod('<?php echo $oneMethod ?>');
<?php endif; ?>
//]]>
</script>
I replaced the code with following because this is there in Magento default code file also
<script type="text/javascript">
//<![CDATA[
<?php echo $this->getChildChildHtml('scripts'); ?>
payment.init();
<?php if (is_string($oneMethod)): ?>
payment.switchMethod('<?php echo $oneMethod ?>');
<?php endif; ?>
//]]>
</script>
But still no luck
replace all payment. by billing. in that file and in osc_payment.js and payment.js of ogone + add this configurable layout :
<checkout_onestep_index>
<reference name="head">
<action method="addJs"><script>netresearch/ops/osc_payment.js</script></action>
<action method="addJs"><script>netresearch/ops/payment.js</script></action>
</reference>
<reference name="head">
<action method="addCss"><stylesheet>css/ops.css</stylesheet></action>
</reference>
</checkout_onestep_index>
I had the same error, maybe for another reason, maybe not, so this is how I've solved it...
We have PHP set to use commas for type "float". But payment.phtml is echoing this :
var quoteBaseGrandTotal = <?php echo (float)$this->getQuoteBaseGrandTotal(); ?>;
When orders amount is a float as 19,83€ , result is :
var quoteBaseGrandTotal = 19,83;
This produced the javascript error.
I had not enough time to patch this properly, so I replace the line with :
var quoteBaseGrandTotal = <?php echo str_replace(',','.', (float)$this->getQuoteBaseGrandTotal() ); ?>;
And the problem disappeared.