Jump to content

Get my syntax right


garethhall

Recommended Posts

Hi I have a variable that I echo out. It is used on a flexigrid ie datagrid at the same time I need to have a onchange event. Now I now that all my code is working the only thing is that I have to get my syntax right in the data grid to get it to work. I need to change out the " to this ' but when I do it it fails to render out the datagrid

 

This is my code at present

<?php
$json = "<input ".($row['pageStatus'] == "on"? "checked" : "")." type=" .'"'. "radio" .'"'. " name=" .'"'. "status" .'"'. " onchange=" .'"'. "updatePageStatus(pageId.value, status.value=" .'"'. "on" .'"'. ")" .'"'. " />";
echo $json;
?>

 

so this code give me  'onchange="updatePageStatus(pageId.value, status.value="on")"'

 

But I need 'onchange="updatePageStatus(pageId.value, status.value='on')"' but when I change it from " to this it dowsn't work? any ideas?

 

 

Link to comment
Share on other sites

<?php

$json = "<input ".($row['pageStatus'] == "on"? "checked" : "")." type=" .'"'. "radio" .'"'. " name=" .'"'. "status" .'"'. " onchange=" .'"'. "updatePageStatus(pageId.value, status.value=" ."'". "on" ."'". ")" .'"'. " />";
echo $json;

?>

 

Should work.

Link to comment
Share on other sites

Replace all " with ' and replace all ' with " ?

Simple.

<?php

$json = "<input ".($row['pageStatus'] == "on"? "checked" : "")." type=" .'"'. "radio" .'"'. " name=" .'"'. "status" .'"'. " onchange=" .'"'. "updatePageStatus(pageId.value, status.value=" ."'". "on" ."'". ")" .'"'. " />";
echo $json;

?>

 

Should work.

 

Thank you for you reply tried but it doesn't seem to work I get an syntax errror I will post the complete document code then you will se way.

Link to comment
Share on other sites

Here is all the code

<?php require_once('../../Connections/admin.php'); ?>
<?php
function runSQL($rsql) {

$db['default']['hostname'] = "localHost";
$db['default']['username'] = 'admin';
$db['default']['password'] = "9ksknv3z";
$db['default']['database'] = "smartPhotoCMS";

$active_group = 'default';

$connect = mysql_connect($db[$active_group]['hostname'],$db[$active_group]['username'],$db[$active_group]['password']) or die ("Error: could not connect to database");
$db = mysql_select_db($db[$active_group]['database']);

$result = mysql_query($rsql) or die ($rsql);
return $result;
mysql_close($connect);
}

function countRec($fname,$tname) {
$sql = "SELECT count($fname) FROM $tname ";
$result = runSQL($sql);
while ($row = mysql_fetch_array($result)) {
	return $row[0];
}	
}

$page = $_POST['page'];
$rp = $_POST['rp'];
$sortname = $_POST['sortname'];
$sortorder = $_POST['sortorder'];

if (!$sortname) $sortname = 'pageId';
if (!$sortorder) $sortorder = 'desc';

$sort = "ORDER BY $sortname $sortorder";

if (!$page) $page = 1;
if (!$rp) $rp = 10;

$start = (($page-1) * $rp);

$limit = "LIMIT $start, $rp";

$query = $_POST['query'];
$qtype = $_POST['qtype'];

$where = "";
if ($query) $where = " WHERE $qtype LIKE '%$query%' ";

$sql = "SELECT * FROM pages $where $sort $limit";
$result = runSQL($sql);

$total = countRec("pageId","pages $where");

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); 
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); 
header("Cache-Control: no-cache, must-revalidate" ); 
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $total,\n";
$json .= "rows: [";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "\n{";
$json .= "id:'".$row['pageId']."',";
$json .= "cell:[";
$json .= "'".$row['pageId']."'";
$json .= ",'".$row['pageMetaTitle']."'";
$json .= ",'".$row['pageMetaDescription']."'";
$json .= ",'".$row['pageDate']."'";

$json .= ",";
$json .= "'";
$json .= "<a href=" .'"'. "cmsEditPage.php?pageId=".$row['pageId']."" .'"'. ">";
$json .= "<img src=".'"'."cmsImages/btnEdit.png".'"'." width=".'"'."56".'"'." height=".'"'."16".'"'."/>";
$json .= "</a>";
$json .= " ";
$json .= "<a href=" .'"'.$row['pagePath'].'"'. " target=" .'"'. "_blank" .'"'. ">";
$json .= "<img src=".'"'."cmsImages/btnView.png".'"'." width=".'"'."56".'"'." height=".'"'."16".'"'."/>";
$json .= "</a>";
$json .= "<form name=" .'"'. "formId".$row['pageId']." " .'"'. " method=" .'"'. "post" .'"'. " >";
$json .= "<input name=" .'"'. "pageId" .'"'. " type=" .'"'. "hidden" .'"'. " id=" .'"'. "pageId" .'"'. " value=" .'"'. " ".$row['pageId']." " .'"'. " />";
$json .= "On";
$json .= "<input ".($row['pageStatus'] == "on"? "checked" : "")." type=" .'"'. "radio" .'"'. " name=" .'"'. "status" .'"'. " onchange=" .'"'. "updatePageStatus(pageId.value, status.value=" .'"'. "on" .'"'. ")" .'"'. " />";
$json .= "Off";
$json .= "<input ".($row['pageStatus'] == "off"? "checked" : "")." type=" .'"'. "radio" .'"'. " name=" .'"'. "status" .'"'. " onchange=" .'"'. "updatePageStatus(pageId.value, status.value=" .'"'. "off" .'"'. ")" .'"'. " />";
$json .= "</form>";
$json .= "";
$json .= "";
$json .= "'";
$json .= "]";

$json .= "}";
$rc = true;		
}
$json .= "]\n";
$json .= "}";
echo $json;

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.