editing with AJAX and PHP\mysql - php

with plenty of visits i found helpful answers from all of you and hope this also give me some idea about my problem.
Basically i'm trying to edit mysql data with ajax. i have done with following code.
Step 1- i loaded data from server with following script
$("#editselected,#addselected").live("click", function(){
var whatto=$(this).attr('id');var edit_ids = new Array();
$(".selectable:checked").each(function() {
edit_ids.push($(this).attr('name'));
});
$("#editadd").load("ajaxloads/addedit.php?idarray="+edit_ids+"&action="+whatto,Hide_Load());
//centerPopup();//loadPopup();
});
AND ITs Server DATA is
if($selectall_action=='editselected'){ ?>
<table id="main" class="editallmainwidth">
<thead>
<tr>
<th scope="col" >Vendor</th>
<th scope="col" >ItemType</th>
<th scope="col" >ItemCode</th>
<th scope="col" >ItemName</th>
<th scope="col" >SerialNo</th>
<th scope="col" >AssetCode</th>
<th scope="col" >Ownership</th>
<th scope="col" >PO</th>
</tr>
</thead>
<tbody>
<?php
$ids= split(",",$selectall_id_array);
foreach($ids as $sid)
{
$stock=mysql_query("select * FROM $region where id='$sid'");
while($q=mysql_fetch_array($stock))
{
echo "<tr>";
echo "<td width=\"5%\"><input type='hidden' name='id_all' value='{$q[8]}' /><input type='text' name='vend_all' value='$q[0]' /></td>";
echo "<td width=\"5%\"><input type='text' name='type_all' value='$q[1]' /></td>";
echo "<td width=\"8%\"><input type='text' name='code_all' value='$q[2]' /></td>";
echo "<td width=\"20%\"><input type='text' name='desc_all' value='$q[3]' /></td>";
echo "<td width=\"10%\"><input type='text' name='seno_all' value='$q[4]' /></td>";
echo "<td width=\"5%\"><input type='text' name='acode_all' value='$q[5]' /></td>";
echo "<td width=\"2%\"><input type='text' name='os_all' value='$q[9]' /></td>";
echo "<td width=\"5%\"><input type='text' name='porder_all' value='$q[12]' /> </td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
<fieldset id="add">
<input type="submit" id='editall' name="Modify" value="EditAll" /> </fieldset>
Step-2 Then I edited The loaded text boxes filled with server data and send back ajax request to server
$("#editall").live("click", function(){
var id_alledit = new Array();
var vendor_alledit = new Array();
var type_alledit = new Array();
var code_alledit = new Array();
var desc_alledit = new Array();
var seno_alledit = new Array();
var acode_alledit = new Array();
var os_alledit = new Array();
var po_alledit = new Array();
var isedited=$("#editall").val();
$("input[name='id_all']").map(function(index) {
id_alledit.push($(this).attr('value'));
});
var tcount=$("input[name='id_all']").length;
$("input[name='vend_all']").map(function(index) {
vendor_alledit.push($(this).attr('value'));
});
$("input[name='type_all']").map(function(index) {
type_alledit.push($(this).attr('value'));
});
$("input[name='code_all']").map(function(index) {
code_alledit.push($(this).attr('value'));
});
$("input[name='desc_all']").map(function(index) {
desc_alledit.push($(this).attr('value'));
});
$("input[name='seno_all']").map(function(index) {
seno_alledit.push($(this).attr('value'));
});
$("input[name='acode_all']").map(function(index) {
acode_alledit.push($(this).attr('value'));
});
$("input[name='os_all']").map(function(index) {
os_alledit.push($(this).attr('value'));
});
$("input[name='porder_all']").map(function(index) {
po_alledit.push($(this).attr('value'));
});
jQuery.ajax({
type:"POST",url:"ajaxloads/addedit.php",
data:"&id_arrays=" + id_alledit + "&vend_arrays=" + vendor_alledit + "&type_arrays=" + type_alledit + "&code_arrays=" + code_alledit + "&desc_arrays=" + desc_alledit + "&seno_arrays=" + seno_alledit + "&os_arrays=" + os_alledit + "&acode_arrays=" + acode_alledit + "&po_arrays=" + po_alledit + "&ifedited=" + isedited + "&tcount=" + tcount ,
complete:function(data){
//$("#main").load("ajaxloads/addedit.php",null,function(responseText){
//$("#main").html(responseText);
//$('tr:even',this).addClass("odd");
alert(data.responseText);
//});
}
});
//disablePopup();
return false;
});
AND Updation was done with the following server side code
if(isset($_POST[ifedited])=='EditAll')
{
$id_count= $_POST[tcount];
$idarray=split(",",$_POST[id_arrays]);
$vendarray=split(",",$_POST[vend_arrays]);
$typearray=split(",",$_POST[type_arrays]);
$codearray=split(",",$_POST[code_arrays]);
$descarray=split(",",$_POST[desc_arrays]);
$senoarray=split(",",$_POST[seno_arrays]);
$acodearray=split(",",$_POST[acode_arrays]);
$osarray=split(",",$_POST[os_arrays]);
$poarray=split(",",$_POST[po_arrays]);
//print_r($idarray);
for($i=0;$i<=$id_count;$i++)
{
//echo $id_count;
echo $idarray[$i];
echo $typearray[$i];
echo $vendarray[$i];
echo $codearray[$i];
echo $descarray[$i];
echo $senoarray[$i];
echo $acodearray[$i];
echo $osarray[$i];
echo $poarray[$i];
mysql_query("update Query");
}
}
*Every thing working fine but it seems like steps for this are being used are
quite lengthy and may cause a performance issue.
i Need if some can suggest me a better way of doing all this. Or if JSON is better option? and if it is then how i can Creat A JSON with associative arrays.
Thanks*

I reccomend you use JSON to do it. If you have a JSON returned like this
{
"foo": "The quick brown fox jumps over the lazy dog.",
"bar": "ABCDEFG",
"baz": [52, 97]
}
Use jQuery to grab it like this
$.getJSON('ajax-mysql/json.php', function(data) {
$('.result').html('<p>' + data.foo + '</p>'
+ '<p>' + data.baz[1] + '</p>');
});
Update: Sending the data back to mysql. Javascript
var data = new Array();
data[0] = $("input1").val();
data[1] = $("input2").val();
data[2] = $("input3").val();
etc...
var mysql_field=new Array();
mysql_field[0] = 'field1';
mysql_field[1] = 'field2';
mysql_field[2] = 'field3';
var jq = new Array();
for(i=0;i<data.length;i++){jq[i] = mysql_field[i]+'=\''+data[i]+'\'';}
jq=jq.join('&');
you can replace data and mysql_field with the current variables you have. Now here's how you would update it with jQuery..
$(".submit").click(function(){
$.post("/ajax-update.php",'"'+jq+'"',function (output){
$("somediv").html(output); // the output on /ajax-update.php after data is submitted
});
});
and on the ajax-update.php file you could use something like
$field[0] = $_POST['field1'];
$field[1] = $_POST['field2'];
$field[2] = $_POST['field2'];
$db->query_update("table",$field,"id=1"); //update where id=1
That query is how you would do it, using this great mysql wrapper class at http://www.ricocheting.com/code/php/mysql-database-class-wrapper. Check it out it'll make your life really easy. All you do is put this at the top of your php file
require("Database.class.php");
$db = new Database("server_name", "mysql_user", "mysql_pass", "mysql_database");

for this question : "how i can Creat A JSON with associative arrays.". Try using the json_encode function.
You could also :
stop using the [deprecated] split function that uses regex and use the explode function.
use quotes on your array's call like here : $_POST[tcount] : $_POST['tcount']
while isset returns boolean, this test is quite weird : if(isset($_POST[ifedited])=='EditAll'){
stop using SELECT * FROM ... but write SELECT field1, field2 FROM ....
add a third parameter to this call : mysql_fetch_array($stock, MYSQL_NUM)
here :
foreach($ids as $sid)
{
$stock=mysql_query("select * FROM $region where id='$sid'");
try using the IN operator of the WHERE clause to avoid multi-queries.
Your code is very difficult to read because not well parsed but still, there are lots of improvements that should affect performances ...

Related

Issue with accessing a value from a table with jquery

Hey guys I am trying to get a specific name from a table. Here is my code:
$(document).ready(function () {
$("#NotesAccessor").click(function () {
var notes_name = $(this).document.getElementById("#user_table");
alert(notes_name);
run();
});
});
Here is the above this is where I am trying to access the associated username with which table row was click with the #notesAccessor
Table:
.........
<td>
$csvusername
</td>
.........
<td>
";
if ($checkNotes[1] == 'No')
{
echo "None";
}
if ($checkNotes[1] == 'Yes')
{
echo "<a href='#' id='NotesAccessor'>Click to access</a>";
}
echo "
</td>
........
My question is - how do I get the $csvusername of the associated NotesAccessor so I can then send this to a dialog in Jquery and open of the notes of that one person I need to get.
Hope this makes sense.
update:
here is full table:
<table class='results'>
<tr class='firsttr' style='background:gray;'>
<td>First Name</td>
<td>Last Name</td>
<td>Email</td>
<td>Phone</td>
<td>Username</td>
<td>Password</td>
<td>Status</td>
<td>Combined Single Limit</td>
<td>Bodily Injury Each Person</td>
<td>Bodily Injury Each Accident</td>
<td>Property Damage</td>
<td>Address</td>
<td>Notes</td>
<td>#</td>
</tr>"; $j = 0; while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $val = 1; $csvfirst
= $row; $csvfirstname = $csvfirst['firstname']; $csvlastname = $csvfirst['lastname'];
$csvemail = $csvfirst['email']; $csvphone = $csvfirst['phone']; $csvusername
= $csvfirst['username']; $csvpassword= $csvfirst['password']; $csvstatus
= $csvfirst['status']; $csvnotes = $csvfirst['notes']; $csl = $csvfirst['Combinedlimit'];
$bodyinj = $csvfirst['bodyinjur']; $eachacc = $csvfirst['bodyinjureachacc'];
$propertydmg = $csvfirst['propertydmg']; // Select the current employees
address $psql = "SELECT MailingAdrs FROM insuranceverificationdisclaimer
WHERE TraineeUsername =:user"; $psth= $DBH->prepare($psql); $psth->execute(array(':user'
=> $csvusername )); while ($prow = $psth->fetch(PDO::FETCH_ASSOC)) { $pcheck
= $prow; $address = $pcheck['MailingAdrs']; } if ($csvstatus != "No Longer
Work Here" && $csvstatus == "Confirmed"){ //check to see if notes exist
if (empty($csvnotes)) { $checkNotes = 0; } else { $checkNotes = 1; } $memberfirstnamearray[$j]
= $csvfirstname; $memberlastnamearray[$j] = $csvlastname; $memberemailarray[$j]
= $csvemail; $memberphonearray[$j] = $csvphone; $membercsl[$j] = $csl;
$memberbodyinj[$j] = $bodyinj; $membereachacc[$j] = $eachacc; $memberpropertydmg[$j]
= $propertydmg; $memberstatus[$j] = $csvstatus; $memberaddress[$j] = $address;
$j++; $i++; echo "
<tr>
<td>$csvfirstname</td>
<td>$csvlastname</td>
<td>$csvemail</td>
<td>$csvphone</td>
<td class='user_table'>$csvusername</td>
<td>$csvpassword</td>
<td>$csvstatus</td>
<td>$csl</td>
<td>$bodyinj</td>
<td>$eachacc</td>
<td>$propertydmg</td>
<td>$address</td>
<td>"; if ($checkNotes == 0) { echo "None"; } if ($checkNotes == 1) { echo
"<a href='#' id='NotesAccessor'>Click to access</a>"; } echo "</td>
<td>$i</td>
</tr>"; } }
</table>
You are mixing pure JavaScript with jQuery, you can solve it as follows.
First of all, you can put a class to identify the <td> with $csvusername, like class='td_with_csvusername' and then do this:
$(document).ready(function () {
$(".NotesAccessor").on("click", function () {
var td = $(this).parent().parent().find(".td_with_csvusername");
alert(td.html());
});
});
Posting the output HTML is better than the PhP version but I assume you have HTML similar to this:
<table>
<tbody>
<tr>
<td>UserName</td>
<td><a href='#' id='NotesAccessor'>Click to access</a>"</td>
</tr>
</tbody>
</table>
Then you can look for the previous sibling of the parent of the anchor by using jQuery's parent() and prev(), similar to this:
$(document).ready(function () {
$("#NotesAccessor").click(function () {
var notes_name = $(this).parent().prev().html();
alert(notes_name);
//run();
});
});
DEMO - Looking to the matching username column
If the above HTML is not like that then please post the exact output as it is important for knowing how to traverse to the matching td in the same tr when you click the anchor. Assuming that is what you are trying to achieve.
Edit
Only seen your update now. I know you already have a solution but for completeness I have added to this answer anyway in case it is useful to future users.
In your sample code you already have class on the user-name cell user_table. You can use that to target instead then. Also, given you said you will have several rows with the #NoteAccessor, you should change the id="NoteAccessor" to class="NoteAccessor" as ids have to be unique or it is invalid HTML. In addition jQuery only returns the first element with a matched id.
The script which you end up with is straight forward then using parent() as before but now you can also use prevAll() specifying the class selector:
$(document).ready(function () {
// using class ".NotesAccessor" instead of id "#NotesAccessor"
// as element is repeated in each tr
$(".NotesAccessor").click(function () {
var notes_name = $(this).parent().prevAll('.user_table').html();
alert(notes_name);
});
});
DEMO - Using parent() and prevAll('.user_table')

Issue with Checkboxes and Javascript, PHP

I am struggling with the following PHP and JavaScript codes to have 2 sets of check-boxes filtering a range of data obtained from a MySQL database.
Here is the code:
<script type="text/javascript">
//http://jsbin.com/ujuse/1/edit
$(function() {
$("input[type='checkbox']").on('change', function() {
var boxes = [];
// You could save a little time and space by doing this:
var name = this.name;
// critical change on next line
$("input[type='checkbox'][name='"+this.name+"']:checked").each(function() {
boxes.push(this.value);
});
if (boxes.length) {
$(".loadingItems").fadeIn(300);
// Change the name here as well
$(".indexMain").load('indexMain.php?'+this.name+'=' + boxes.join("+"),
function() {
$(".indexMain").fadeIn('slow');
$(".loadingItems").fadeOut(300);
});
} else {
$(".loadingItems").fadeIn(300);
$(".indexMain").load('indexMain.php', function() {
$(".indexMain").fadeIn('slow');
$(".loadingItems").fadeOut(300);
});
}
});
});
</script>
<?php
function echoCheckboxSet($header, $divClass, $columnName, $setName) {
include ("connection.php");
$checkboxes = $con -> prepare("SELECT DISTINCT $columnName FROM item_descr ORDER BY $columnName ASC");
$checkboxes->execute();
?>
<div class="bgFilterTitles">
<h1 class="filterTitles"><?php echo $header;?></h1>
</div>
<div class="<?php echo $divClass; ?>">
<?php
while ($box = $checkboxes->fetch(PDO::FETCH_ASSOC)):
$boxColumnName = str_replace('_',' ',$box[$columnName]);
?>
<input type='checkbox' class='regularCheckbox' name='<?php echo $setName; ?>' value='<?php echo $box[$columnName]; ?>' />
<font class='similarItemsText'><?php echo $boxColumnName; ?></font>
<br />
<?php
endwhile;
?>
</div>
<?php
} // end of echoCheckboxSet
// Call our method twice, once for colors and once for prices
echoCheckBoxSet("COLOR", "colors", "color_base1", "color[]");
echoCheckBoxSet("PRICE", "prices", "price", "price[]");
?>
Then I am perfectly getting my check-boxes but when clicking on any of them they don't do anything.
My indexMain.php retrieves the values like this:
$colors = $_GET['color[]'];
echo "TEST".$colors[1];
$colors = explode(' ', $colors);
$parameters = join(', ', array_fill(0, count($colors), '?'));
$items = $con -> prepare("SELECT * FROM item_descr WHERE color_base1 IN ({$parameters})");
$items ->execute($colors);
$count = $items -> rowCount();
----------------- Adding the echo:
echo "<div>Showing ".$count."items</div>";
while($info = $items->fetch(PDO::FETCH_ASSOC))
{
echo "<div name='item' id='".$info['color_base1']."' class='itemBox'><div class='showItem'><a href='items_descr.php?itemId=".$info[id_item]."'><img class='itemImage' alt='' src='images/$info[imageMid].jpg'></img></div><br />";
echo "<div class='indexItemText'><font class='similarItemsText'><a href='items_descr.php?itemId=".$info[id_item]."'>".$info[name]."</a><font class='price'> - $".$info[price]."</div></div>";
$row_count++;
if ($row_count % 2 == 0)
{
echo "<br />"; // close the row if we're on an even record
}
}
Any idea of what could be going on?
The problem is when you build the query in your JS function:
'indexMain.php?'+this.name+'=' + boxes.join("+")
This sends color[]=Brown+Grey instead of color[]=Brown&color[]=Grey. A correct (but dirty) way to this is:
'indexMain.php?'+this.name+'=' + boxes.join('&' + this.name + '=')
You could try to use jQuery.param() ( http://api.jquery.com/jQuery.param/ ) to get a nicer code.
Also, in PHP, the checkbox values are available in the array $_GET['color'] (not $_GET['color[]']).
Edit: Sorry, read too quickly.
Answer: As you expect everywhere to use strings, use color instead of color[] in your JS and PHP code.

jQuery Sortable PHP

I am using jQuery sortable to manipulate image order and write to a DB. That functionality works well.
PHP
echo "<div class='revisionNum'>";
echo "<ul id='sortable_" . $count ."'>";
while($row = mysql_fetch_array($result)) {
$sortImageName = $row['OrgImageName'];
$sortPath = "../data/gallery/" . $galleryID . "/images/album/" . $sortImageName;
echo "<li class='sortPhotos' id='item_{$row['id']}' >";
echo '<img class="sortImage" src="'. $sortPath .'"/>';
echo "<p>" . $sortImageName . "</p>";
echo "</li>";
}
echo "</ul>";
echo "</div>";
jQuery
//make sortable
$(".revisionNum").each(
function(e) {
num = e + 1;
$("#sortable_" + num).sortable(
{stop:function(i) {
serial = $("#sortable_" + num).sortable("serialize");
$.ajax({
type: "GET",
url: "../albumUploader/queries/sort.php",
data: serial
});
},
opacity:1.0,
//cursor: move
});
});
MYSQL
foreach($_GET['item'] as $key=>$value) {
mysql_query(" UPDATE galleryimage
SET sort = '{$key}'
WHERE id = '{$value}'
");
}
The issue is when I have multiple <div class=''revisionNum> i am only grabbing the serial = $("#sortable_" + num) of the last UL if the [.revisionNum], not the actual UL that I am sorting. Thanks for the help on this. Let me know if further clarification is needed.
I am not sure I fully understand your question, but I think you are looking for the following:
The variable num will change every loop you make in the each-loop. But at the end it will have the value of the last loop. Because num seems to be a global variable you can't call it in the stop function. Then it will just use the last value it had. The value of the last loop. (Explains your problem)
To solve this I recommend to change your code to:
$(".revisionNum").each(
function(e) {
$(this).children("ul").sortable(
{stop:function(i) {
num = $(this).children("ul").attr("id").replace("sortable_", "");
serial = $(this).children("ul").sortable("serialize");
...
$(this) refers to the $(".revisionNum") you are looping through and it will be remembered, also in the stop function.

can getJSON be used to get a value from an html tag id already rendered by a page?? json_decode?

what i mean by this is after an html page is rendered, how can i get the value by using the html tag id??
ex: get the value of date by using td_date in my JS function??
below the code that puts the data on the page: listSuccess.php
foreach ($pager->getResults() as $msg)
{
echo "<tr id='td_id' value='$msgId'</tr>";
$date = add_date($msg->getCreatedAt(),$hr=2);
echo "<td class='td_show_contact_item' align='left' id='td_date'>".$date."</td>";
<td align='left' id='td_subject'>
<a href="<?php echo url_for('messagebox/read?cursor=').$cursor ?>" style='color:#ff0000 !important' class='spn_small_red_rbc'><?php echo $msg->getSubject();?></a>
</td>
echo "<td class='td_show_contact_item' align='left' id='td_from'>".$unique_code_from."</td>";
echo "<td id='block_url'>( ".$block_url." )</td>";
echo "</tr>";
++$cursor;
}
so in my JS:
function ax_get_new_msg_details()
{
var mTimer;
$.getJSON('/apps_dev.php/messagebox/newMessageDetails', function(data)
{
var messageExists = $('#' + data.td_id).length > 0;
if (!messageExists)
{
mTimer = setTimeout('ax_get_new_msg_details()',30000);
var str='<tr id="' + data.td_id + '">';
str += "<td class='td_show_contact_item' align='left' id='td_date'>"+data.td_date+'</td>';
str += "<td align='left' id='td_subject'><a href='#' style='color:#ff0000 !important' class='spn_small_red_rbc'>"+data.td_subject+"</a></td>";
str += "<td class='td_show_contact_item' align='left' id='td_from'>"+data.td_from +"</td>";
//str += "<td id='block_url'>"+data.block_url+"</td>";
str +='<tr>';
var tbl = $('#td_date').parents('table');
$(tbl).append(str);
}
});
}
then newMessageDetails.php in my actions.class.php
public function executeNewMessageDetails(sfWebRequest $request)
{
$profile_id = $this->getUser()->getAttribute('profile_id','zero');
$new_msgs = RcMessageBoxTablePeer::getNewMessages($profile_id);
if (count($new_msgs) >= 1)
{
foreach ($new_msgs as $row)
{
$date = $row->getCreatedAt();
$subject = $row->getSubject();
$from = $row->getProfileIdFrom();
$id = $row->getId();
$uc_record = RcProfileTablePeer::getById($from);
$uc_from = $uc_record->getUniqueCode();
//$block_url = 'Block User',"blocklist/block?unqiue_code=$uc_from",'class=link_medium_blue');
}
$output = array("td_date" => $date, "td_subject" => $subject, "td_from" => $uc_from, "td_id" => $id);
}
else
$output = "";
return $this->renderText(json_encode($output));
}
the data that i get from the JS function is correct but i need to somehow know that what is actually already on my page ie what was rendered already differs from what json returns and if data differs...update the page with the new json data
any advice?
Why not include your td_id in your tr tag and just compare the incoming id with the existing id?
var str='<tr id="' + data.td_id + '">';
Then in your update put this if condition around your code:
var messageExists = $('#' + data.td_id).length > 0;
if (!messageExists) {
// your existing code
}
Personally I use firefox and the web developer tool bar it not only allows you to see the source code but also allows you to view the generated source code, plus lots of other very useful tools hope this helps you.

Multiple countdown timers using a PHP loop

What I'm trying to do is output data from my database using PHP. Alongside this data I'd like to include a countdown timer using the data from my database. Naturally, the timer is done using JavaScript but I'm struggling to work out how to include the PHP variable in the JavaScript code and then loop through all my results, including an instance of the timer on each row.
I'm testing over here: http://www.lineswritten.co.uk/Countdown/ - The red 'timer here' is where I'd want the top 4 instances of 'waiting...' to be. These four instances aren't included in my loop.
I presume this would be done with $count++ but I'm not sure how to code this all up.
My JavaScript timer has been grabbed from here: http://jsfiddle.net/HSx9U/
The code is the following:
JavaScript
var count1 = new countDown(new Date('2010/12/11 10:44:59'),'counter1', 'tomorrow 10:45')
,count2 = new countDown(new Date('2010/12/25'),'counter2', 'first christmas day 2010')
,count3 = setTimeout(function(){
return new countDown(new Date('2011/12/25'),'counter3', 'first christmas day 2011');
},2000)
,count4 = setTimeout(function(){
return new countDown(new Date('2100/01/01'),'counter4', 'a new era starts');
},4000);
function countDown(startTime, divid, the_event){
var tdiv = document.getElementById(divid)
,start = parseInt(startTime.getTime(),10)
,the_event = the_event || startTime.toLocaleString()
,to;
this.rewriteCounter = function(){
var now = new Date().getTime()
,diff = Math.round((start - now)/1000);
if (startTime > now)
{
tdiv.innerHTML = diff +' seconds untill ' + the_event;
}
else {clearInterval(to);}
};
this.rewriteCounter();
to = setInterval(this.rewriteCounter,1000);
}
HTML
<div id="counter1">waiting...</div>
<div id="counter2">waiting...</div>
<div id="counter3">waiting...</div>
<div id="counter4">waiting...</div>
HTML Table/PHP loop
<table>
<tr>
<th id="logo">Logo</th>
<th id="name">Name</th>
<th id="discount">Discount</th>
<th id="length">Sale Length</th>
<th id="time">Time Remaining</th>
<th id="what">On What</th>
<th id="small-print">Small Print</th>
<th id="link">Link to Sale</th>
</tr>
while ($row = mysql_fetch_array($result)) {
$discount = $row['discount'];
$product = $row['product'];
$terms = utf8_decode($row['terms']);
$brand_name = $row['brand_name'];
$code = $row['code'];
$link = $row['link'];
$logo = $row['logo'];
$length = $row['length'];
<tr>
<td headers="logo"><?php echo $logo;?></td>
<td headers="name"><p><?php echo $brand_name;?></p></td>
<td headers="discount"><p><?php echo $discount;?></p></td>
<td headers="length"><p><?php echo $length;?></p></td>
<td headers="time"><p style="color:#F00;">timer here</p></td>
<td headers="what"><p><?php echo $product;?></p></td>
<td headers="small-print"><p><?php echo $terms;?></p></td>
<td headers="link"><p>Redeem</p></td>
}
</table>
I presumed I could change the new Date('2010/12/11 10:44:59') to new Date('$newDate') but it didn't work.
Geting stuff from PHP to javascript is best done using PHP's json_encode() function. You can feed it an array like this:
$array = ('item1', 'item2');
echo '<script type="text/javascript">';
echo 'var myarray = '.json_encode($array).';';
// iterate etc here
echo '</script>';

Categories