echo "<td> + manuf + </td>";
Is this above ever going to work??
I'm pulling results from a mysql db to edit the contents but need the jQuery functionality to edit it, hence the embedded javascript variable...
EDIT:
Sorry for the lack of context, its related to another question i've asked on here Mysql edit users orders they have placed this is the end goal. To edit the order i place, i need to pull the results into an environment similar to how the user placed the order. So my thinking was to include the jQuery functionality to add items to a cart etc, then they could press submit and in the same way i used .Ajax to post the data to an insert php script i would post the values to an update php script! Is this backwards thinking, any advice weled!
echo "<td> + manuf + </td>";
Is this above ever going to work??
I'm pulling results from a mysql db to edit the contents but need the jQuery functionality to edit it, hence the embedded javascript variable...
EDIT:
Sorry for the lack of context, its related to another question i've asked on here Mysql edit users orders they have placed this is the end goal. To edit the order i place, i need to pull the results into an environment similar to how the user placed the order. So my thinking was to include the jQuery functionality to add items to a cart etc, then they could press submit and in the same way i used .Ajax to post the data to an insert php script i would post the values to an update php script! Is this backwards thinking, any advice weled!
Share Improve this question edited May 23, 2017 at 11:43 CommunityBot 11 silver badge asked Nov 8, 2010 at 11:29 benhowdle89benhowdle89 37.5k74 gold badges207 silver badges340 bronze badges 2- 6 Your question lacks context. It will work, if you want + manuf + to appear on the page. – Emyr Commented Nov 8, 2010 at 11:32
-
Even in HTML,
<td> + manuf + </td>
won't do anything but write " + manuf + " in a table cell. Anyway, if you pull result from a database, you shouldn't have to edit it client-side afterwards. You need to be more specific about the code you use if you want help. – Shikiryu Commented Nov 8, 2010 at 11:34
7 Answers
Reset to default 2I suggest you take a look at the follwing.
- json_encode
- Ajax
- JSONP
Now your simplest solution under you circumstances is to do go for the json_encode method. Let me show you an example:
$json_data = array(
'manuf' => $some_munaf_data
);
echo "<script type=\"text/javascript\">";
echo "var Data = " . json_encode(json_data);
echo "</script>";
This will produce an object called Data
, and would look like so:
<script type="text/javascript">
var Data = {
munaf : "You value of $some_munaf_data"
}
</script>
Then when you need the data just use Data.munaf
and it will hold the value from the PHP Side.
Would you not echo out the jQuery within a Javascript code island? You need the client-based code (jQuery) to be able to execute after the server-side code (PHP).
echo '<td><script language = "JavaScript" type = "text/JavaScript">document.write("");</script></td>';
Is this above ever going to work??
Nope. You'd need to output valid JavaScript for the browser to interpret:
echo "<script>document.write('<td>'+manuf+'</td>')</script>";
But that is a dreadful construct, and I can't really see why you would need this, seeing as the td
's contents are likely to be static at first.
Try just emitting the MySQL content with PHP:
echo "<td id='manuf'>".$manuf."</td>"
Then get the contents with jQuery like this:
var manuf = $('#manuf').text();
Consume you have the table echoed with php:
<table id="sometab">
<tr>
<td>
</td>
<tr>
</table>
The jquery for printing resuls in any td is :nth-child(2) takes 2 table td object :
<script type="text/javascript">
$(function(){
$("#sometab tr td:nth-child(2)").html("bla");
})
</script>
Is "manuf" a JS variable or part of a PHP output e.g. part of generated ?
Basically this can easily be done by: mysql thru PHP(*I can't put table tag..sorry.):
while($row = mysql_fetch_object($result)) { echo 'tr'; echo 'td a href="#" class="myres"'.$row->manuf.'/a /td'; echo '/tr'; }
then on your JS just attach a "click" handler
$(function() { $(".myres").click(function() { //my update handler... }); });
i think you cant embed the jquery variable in the php like this . you just give the class name here from here when edit will be click you will get the variable as in submit click in other questions .