Jump to content

watagal

Members
  • Posts

    120
  • Joined

  • Last visited

Everything posted by watagal

  1. watagal

    INNER JOIN

    Ok, it looks like there is only one "id" which is overwritten by the 2nd table's value (9). How do I gain access to the 1st table's "id"? Do I need to rename all my pkeys to a unique name or is there a better way? Thanks, Galprint_r($record) = [0] => 5 [id] => 9 [1] => 1 [countryId] => 1 [2] => 3 [areaCodeId] => 3 [3] => 555-5555 [phoneNumber] => 555-5555 [4] => 1 [origMemberId] => 1 [5] => 1 [isActive] => 1 [6] => 2008-06-23 17:13:23 [date] => 2008-06-23 17:13:23 [7] => Family [share] => Family [8] => 3 [9] => 555 [areaCode] => 555 [10] => 9 [cityId] => 9 [11] => 9 [12] => 4 [stateId] => 4 [13] => San Jose [name] => San Jose
  2. watagal

    INNER JOIN

    Greetings-When I do an INNER JOIN on 2 tables with the "id" field or column existing in both tables - I get 2 IDs in the fetched record set. How do I distinguish between the 2 while looping thru while($record = mysql_fetch_array($result)) { echo $record['tableA.id']; echo $record['tableB.id'];} I know the above does not work, what is the correct syntax?TiA, Gal
  3. -- Never mind, I found some more info on this - I'll give it a try! Sorry for the post.
  4. Greetings-I can create a SELECT statement with one INNER JOIN, but How do I create a statement with 2?TiA, Gal-- Never mind, I found some text - I'll give it a try!
  5. watagal

    INSERT

    Found the answer to the first question:$sql = "INSERT INTO person VALUES ('Børge','Refsnes','Sandnes','17')";$result = mysql_query($sql,$con);echo "ID of last inserted record is: " . mysql_insert_id(); Still looking for the answer to #2.
  6. watagal

    INSERT

    Greetings-I have some very basic questions concerning the INSERT command in MySQL (v5):1) When inserting a new record, how can I get the record key ('id', primary_key, auto_increment) number?2) How can I determine if the insertion failed based on a unique field ('email', unique) already exists?I realize I can execute a SELECT command just before or after the INSERT to get what I want, but I thought I might get clever here. Tia, Gal
  7. aspnetguy writes: What about using $_SESSION[] ? Is this more secure or less secure?
  8. Thankyou!! That's it!!my reponse PHP file includes the header() AND IT WORKS!! -- Thanks sooo much! header('Content-type: text/xml');echo '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n";
  9. Thanks again jesh -It appears (to me) that I am requesting a "text/xml" content type, but recieving "text/html" type (via firebug):So my XML response must be malformed, but I don't know how or where? Here it is: <?xml version="1.0" encoding="ISO-8859-1"?><root> <node> <target></target> <id>1</id> <label>Administrator</label> <email>admin@abc.com</email> <isPrimary>1</isPrimary> <share>All</share> </node> <node> <target></target> <id>3</id> <label>Family</label> <email>gal@abc.com</email> <isPrimary>0</isPrimary> <share>Family</share> </node></root> Where can I get the rules for writing XML responses? Or is there a setting in Apache?Thanks so much for the time you're putting into this, Gal
  10. Thanks again jesh- in either case - i get nullI think the problem is either my XmlHttpRequest or my PHP script generating the XML response - because my response is returning via the "responseText", not the "responseXML".Here's my 'responseXML':Here's my 'responseText':So where might I be going wrong?Gal
  11. Thanks jesh-I tried the alert() and it came up null - but according to Firebug, the response has XML data:I'm looking at w3schools example: http://www.w3schools.com/ajax/tryit.asp?fi...httprequest_js4Here's my ajaxCall() function: // create AJAX objectvar xmlHttp = null;function createAjaxObject() { try { xmlHttp=new XMLHttpRequest();} // Firefox, Opera 8.0+, Safari catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");} // Internet Explorer catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");} } return xmlHttp;}// AJAX callfunction ajaxCall(dataSource, method, encode, async, callback, response) { xmlHttp = createAjaxObject(); if (xmlHttp != null) { xmlHttp.onreadystatechange = function() { if ((xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" ) && xmlHttp.status == 200) { if (response == 'text' && callback) { callback(xmlHttp.responseText); } if (response == 'xml' && callback) { callback(xmlHttp.responseXML); } } } if (method == "POST") { xmlHttp.open("POST", dataSource, async); xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); xmlHttp.send(encode+"&sid="+Math.random()); } else { xmlHttp.open("GET", dataSource+"&sid="+Math.random(), async); xmlHttp.send(null); } } else alert ("Browser does not support HTTP Request");} Here's the trigger: function getEmailData(id,el) { // Select item from leftside list & get data ajaxCall(PHPDIR+'form_MyPage_getEmailData.php', "POST", 'id='+id+'&el='+el, async, getEmailData_Callback, 'xml');} Here's the response code: - responseXML still comes in null. function getEmailData_Callback() {alert(xmlHttp.responseXML);// var xmlDoc = newXmlDoc(responseXML); // (forms+ajax.js) var arr = xmlHttp.responseXML.documentElement.getElementsByTagName("node"); var target = arr[0].getElementsByTagName("target")[0].childNodes[0].nodeValue; if (target == '') { // setValue('id',"txtEmailLabel", responseXML.getElementsByTagName("label")[0].childNodes[0].nodeValue); var email = responseXML.getElementsByTagName("email")[0].childNodes[0].nodeValue.split("@"); setValue('id',"txtEmailAddress1", email[0]); setValue('id',"txtEmailAddress2", email[1]); setChecked('id',"chkEmailIsPrimary",responseXML.getElementsByTagName("isPrimary")[0].childNodes[0].nodeValue); setChecked('id','radEmailShare'+ responseXML.getElementsByTagName("share")[0].childNodes[0].nodeValue,true); } else { // List Email Addresses on leftside list (accordion menu) var html = '<table>'; for (var i=0; (i < arr.length); i++){ html += '<tr><td><div class="contactInfo" onclick="java script:getEmailData('; html += arr[i].getElementsByTagName("id")[0].childNodes[0].nodeValue+',\'\');">'; html += '<b>'+arr[i].getElementsByTagName("label")[0].childNodes[0].nodeValue+'</b><br />'; html += space(4); html += arr[i].getElementsByTagName("email")[0].childNodes[0].nodeValue; html += '<br /><br /></div></td></tr>'; } html += '</table>'; setInnerHTML('id',target,html); }}
  12. This JS routine is called from an HTML control using the 'onclick' event: all good here function getEmailData(id,el) { ajaxCall(PHPDIR+'form_MyPage_getEmailData.php', "POST", 'id='+id+'&el='+el, async, getEmailData_Callback, 'xml');} The PHP (form_MyPage_getEmailData.php) produces the following XML (responseXML) code: all good here <?xml version="1.0" encoding="ISO-8859-1"?><root> <node> <target>divContent</target> <id>1</id> <label>Administrator</label> <email>admin@************.com</email> <isPrimary>1</isPrimary> <share>All</share> </node></root> This is the 'stateChanged' or callback routine from the ajax call above: The error I get is "arr[0]" has no properties (var target = 3rd line down) - so my "newXmlDoc() function (way below) receives an xml file (per W3school) as an argument.Here I'm not specifying a file, but the 'responseXML' (in memory) - which is why 'arr[]' is empty. How do I fix this? thanks, Gal function getEmailData_Callback(responseXML) { var xmlDoc= newXmlDoc(responseXML); // (forms+ajax.js) var arr = xmlDoc.getElementsByTagName("node"); var target = arr[0].getElementsByTagName("target")[0].childNodes[0].nodeValue; if (target == '') { // setValue('id',"txtEmailLabel", responseXML.getElementsByTagName("label")[0].childNodes[0].nodeValue); var email = responseXML.getElementsByTagName("email")[0].childNodes[0].nodeValue.split("@"); setValue('id',"txtEmailAddress1", email[0]); setValue('id',"txtEmailAddress2", email[1]); setChecked('id',"chkEmailIsPrimary",responseXML.getElementsByTagName("isPrimary")[0].childNodes[0].nodeValue); setChecked('id','radEmailShare'+ responseXML.getElementsByTagName("share")[0].childNodes[0].nodeValue,true); } else { // List Email Addresses on leftside list (accordion menu) var html = '<table>'; for (var i=0; (i < arr.length); i++){ html += '<tr><td><div class="contactInfo" onclick="java script:getEmailData('; html += arr[i].getElementsByTagName("id")[0].childNodes[0].nodeValue+',\'\');">'; html += '<b>'+arr[i].getElementsByTagName("label")[0].childNodes[0].nodeValue+'</b><br />'; html += space(4); html += arr[i].getElementsByTagName("email")[0].childNodes[0].nodeValue; html += '<br /><br /></div></td></tr>'; } html += '</table>'; setInnerHTML('id',target,html); }} XML Function: function newXmlDoc(doc) { // per W3school try { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); //Internet Explorer } catch(e) { try { xmlDoc = document.implementation.createDocument("","",null); //Firefox, Mozilla, Opera, etc. } catch(e) { alert(e.message) } } try { xmlDoc.async=false; xmlDoc.load(doc); // i.e. "books.xml" } catch(e) { alert(e.message) } return xmlDoc;}
  13. Ok, let's see if I'm on the right track?My assumptions:1) We can recursively call the same function.2) Variable scope is limited to within each recursive call of the same function. In other words, each time I call the function "addNode()", a whole new set of variables are created in memory.3) Except when I use pointer references (as in &$d and &$photoTag) and any modification made is visible in any of the recursive calls4) Am I using pointer references correctly?The top array is a sample PHP array and this code should transfer it to the bottom javascript sample.Are my assumption correct?TiA, Gal /* //PHP Node Array where ## = IDs to $photoTag[]:$node[ '1'=> 0=$depth [11,'12'=> 1 [23,24,25, '26'=> 2 [31,32,33,34,35] 3/2 ,27,28] 1 ,13] 0 ,'2'=> [17,'18'=> 1 [23,24,25,'26'=> 2 [31,32,'33'=> 3 [41,42,'43'=> 4 [51,52,53,54,55] 5/4 ] 3 ,34,35] 2 ,27,28] 1 ,19] 0];*/$d=0; echo "var aTreeNodes = [";addNode($node);echo "];";function addNode($arr) { $arrMax = count($arr); foreach($arr as $key => $id) { if (count($id) > 1) { echo "[".&$photoTag[$key]['name'].",".$key.","; // Add "folder" node &$d++; addNode($id); &$d--; // Dive into SubArray } else { echo "[".&$photoTag[$id]['name'] .",".$id."]"; // Add "item" node } if ($id != $arr($arrMax)) echo ","; // NOT Last element } if (&$d > 0) echo "],"; else echo "]";}/* Javascriptvar aTreeNodes = [ ['NodeText', 1, ['NodeText',11], ['NodeText',12, ['NodeText',23], ['NodeText',24], ['NodeText',25], ['NodeText',26, ['NodeText',31], ['NodeText',32], ['NodeText',33], ['NodeText',34], ['NodeText',35] ], ['NodeText',27], ['NodeText',28] ], ['NodeText',13] ], ['NodeText', 2, ['NodeText',17], ['NodeText',18, ['NodeText',23], ['NodeText',24], ['NodeText',25], ['NodeText',26, ['NodeText',31], ['NodeText',32], ['NodeText',33, ['NodeText',41], ['NodeText',42], ['NodeText',43, ['NodeText',51], ['NodeText',52], ['NodeText',53], ['NodeText',54], ['NodeText',55] ], ], ['NodeText',34], ['NodeText',35] ], ['NodeText',27], ['NodeText',28] ], ['NodeText',19] ]]; */
  14. ThanksI'm querying my database with the results building a single multi-dimensional array where the nested depth is determined by the DB query. In other words, it will vary at runtime. This data will eventually populate a javascript tree (menu) control. The array is built in PHP and transferred to JS array.I'm trying to read the PHP array in order to replicate it in JS.This may not be the best way, if not - someone please let me know.TiA, Gal
  15. Greetings-All weekend, I've been trying to walk through an array where the elements can be specific data or another sub array. The nested arrays (or depth) is unknown. I've determined "array_walk()" and "array_walk_recursive()" won't work for me because it doesn't provide feedback on the depth (which I need). So I have been trying with "foreach()" statements. The problem is I don't think hardcoding a specific number of nested foreach() statements is a good solution.There must be a better approach. Any help is appreciated (as always).Gal
  16. As you can tell from my postings, I'm new at this. But I thought about this and decided since PHP is server side scripting, all PHP code is executed prior to knowing anything about the browser.Correct me if I'm off.my 2 cents,-Gal
  17. Thanks Wander-I'm really weak on arrays in PHP, so here's what I'm trying to do. I'm building a multi-dimensional array to build a tree type menu based on only a node ID and its corresponding parent's node ID (both query in the database, sorted on the PID). $pid = -1;$grpknt = -1;while ($record = mysql_fetch_array($results)) { $id = record['id']; $photoTag = Array( '"'.$id.'"' => Array( "name" => $record['name'], "desc" => $record['description'], "apid" => $record['alt-pid'], "mid" => $record['memberId'] ) ); if ($pid != $record['pid']) { $pid = $record['pid']; $grpknt++; $eleknt = 0; $group[$grpknt][0] = $pid; // element[0] = PID (parent ID) } $eleknt++; $group[$grpknt][$eleknt] = $id; // element[1+] = IDs (children ID) $node[$id] = '@'; // Default = item, not folder}$group_rev = array_reverse($group);foreach (array_reverse($photoTag) as $id => $r) { // rec[knt][attribute] -> r[attribute] foreach ($group_rev as $grp) { // group[grpknt][eleknt] -> g[eleknt] $pid = array_shift($grp); // first element is always PID, remainder are children IDs if ($id == $pid) { // ID found in Group array $node[$id] = Array; $k=-1; foreach ($grp as $kid) { // loop thru group array $k++; if ($node[$kid] != '@') { $node[$id][$k] = Array($node[$kid]); } else { $node[$id][$k] = $kid; } } } }} I think I have the logic (untested), but I'm struggling with the array syntax.Am I anywhere close to constructing the $node[] array?-Gal
  18. Is there a way to loop through an array backwards using "foreach"? foreach (array as value){ code to be executed;} BTW, this is a multi-dimension array, so if array_reverse() is an option, whats the syntax for reversing a 2-dimensional array?Thanks, Gal
  19. Greetings-If my users use 2 different brower types (IE + FF) on the same system, are there 2 different set of cookies?Can I store my cookies in a common (non browser specific) location?Are cookies structured the same, no matter the browser type? i.e. IE can read a FF cookie?TiA, Gal
  20. watagal

    Ahggg!

    Thanks JSG, changing to 'y' and 'n' appears to have fixed it for Firefox - print_r($_COOKIE) displays "Array ( [ri1] => y [ri2] => y [i2] => e10adc3949ba59abbe56e057f20f883e [i1] => wg )".In IE, print_r($_COOKIE) displays only "Array ( )" - I'll have to wait and upload the site to my ISP to test cookies in IE.
  21. watagal

    Ahggg!

    Can someone kindly explain the output I'm getting? // Cookie check for returning members echo '[U='.$_COOKIE['ri1'].']<br />'; echo '[P='.$_COOKIE['ri2'].']<br />';if (isset($_COOKIE['ri1'])) {$chkRemUserName = ($_COOKIE['ri1'] == true) ? 'checked="checked"' : '';}else {$chkRemUserName = '';}if (isset($_COOKIE['ri2'])) {$chkRemPassword = ($_COOKIE['ri2'] == true) ? 'checked="checked"' : '';}else {$chkRemPassword = '';} echo '[U='.$chkRemUserName.']<br />'; echo '[P='.$chkRemPassword.']<br />'; FireFox Output is :[u=true][P=false][u=checked=checked][P=checked=checked]"P" should be:[P=]if originally false ??IE Output is:[u=][P=][u=][P=]thanks, Gal
  22. watagal

    $_COOKIE[]

    I think I found it. When I setcookie(), I left the path argument as an empty string ('') - the default. I changed it to root ( '/' ) and now I found my cookies.Gal
  23. watagal

    $_COOKIE[]

    I think I've tried everything - at least twice.echo '['.$_COOKIE['i1'].']'; // returns ''echo '['.isset($_COOKIE['i1']).']'; // returns ''The name is correct, I can see the cookies in FireFox > Tools > Options > Show CookiesIs this a timing issues? Are cookies available before any HTML header is sent?Thanks for taking a look, Gal
  24. watagal

    $_COOKIE[]

    Greetings-As part of my index.php (initial) file, I'm trying to read Cookies for returning members. All this parsing is done before any header (HTML) code is written (sent) to the browser.My question is when can I access those cookies? As of now, my code is not working - just not sure if there is something wrong with my logic.I know the cookies are wriiten correctly, I can see them via Ffox.TiA, Gal // Cookie check for returning members $cookieUserName = isset($_COOKIE['id1']) ? $_COOKIE['id1'] : USR_GUEST; queryUser($dblink, $cookieUserName,((strpos($cookieUserName,'@'))?'userEmail':'userName')); // Defines $_SESSION[] if ($_SESSION['userName'] != USR_GUEST) { if (isset($_COOKIE['id2'])) { if (md5($_COOKIE['id2']) != $_SESSION['password']) { queryUser($dblink, USR_GUEST,'userName'); // Defines $_SESSION[] } } }
  25. dukxud

    If you have questions, post them to the appropriate forum - that way everyone can benefit. -WataGal

×
×
  • Create New...