garethhall Posted July 17, 2009 Share Posted July 17, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/ Share on other sites More sharing options...
mattal999 Posted July 17, 2009 Share Posted July 17, 2009 <?php $json = "<input ".($row['pageStatus'] == "on"? "checked" : "")." type=" .'"'. "radio" .'"'. " name=" .'"'. "status" .'"'. " onchange=" .'"'. "updatePageStatus(pageId.value, status.value=" ."'". "on" ."'". ")" .'"'. " />"; echo $json; ?> Should work. Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/#findComment-876956 Share on other sites More sharing options...
papaface Posted July 17, 2009 Share Posted July 17, 2009 Replace all " with ' and replace all ' with " ? Simple. Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/#findComment-876957 Share on other sites More sharing options...
garethhall Posted July 18, 2009 Author Share Posted July 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/#findComment-877459 Share on other sites More sharing options...
garethhall Posted July 18, 2009 Author Share Posted July 18, 2009 Replace all " with ' and replace all ' with " ? Simple. 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. Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/#findComment-877461 Share on other sites More sharing options...
garethhall Posted July 18, 2009 Author Share Posted July 18, 2009 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/#findComment-877462 Share on other sites More sharing options...
Daniel0 Posted July 18, 2009 Share Posted July 18, 2009 You shouldn't generate your JSON manually. See json_encode Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/#findComment-877494 Share on other sites More sharing options...
garethhall Posted July 18, 2009 Author Share Posted July 18, 2009 I am not to sure on how I would implement it in my code? Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/#findComment-877750 Share on other sites More sharing options...
Daniel0 Posted July 18, 2009 Share Posted July 18, 2009 Well, in your code you have like: $data = array( 'page' => $page, 'total' => $total, // etc. ); $json = json_encode($data); Essentially, json_encode() turns an array into a JSON string. Quote Link to comment https://forums.phpfreaks.com/topic/166298-get-my-syntax-right/#findComment-877759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.