Jump to content

jattsurma

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by jattsurma

  1. Hello Everyone, I am working on a CMS site and I'm stuck very badly with arrays. I don't have much experience with arrays. In fact, this is probably the first time I have used them this heavily. Here is my situation: I have a for each loop with $i++; which takes values from sessions and puts them into arrays: $bundle_pickup[$i]['bundle_ID']=$bundle_ID; $bundle_pickup[$i]['pickup_date']=$_SESSION['bundle'][$bundle_ID]['pickup_date']; $bundle_pickup[$i]['pickup_time']=$_SESSION['bundle'][$bundle_ID]['pickup_time']; $bundle_pickup prints the following total results: Array ( [1] => Array ( [bundle_ID] => 3 [pickup_date] => 2012-11-08 [pickup_time] => 9 AM to 12 PM ) [2] => Array ( [bundle_ID] => 4 [pickup_date] => 2012-11-08 [pickup_time] => 9 AM to 12 PM ) [3] => Array ( [bundle_ID] => 5 [pickup_date] => 2012-11-08 [pickup_time] => 9 AM to 12 PM ) [4] => Array ( [bundle_ID] => 6 [pickup_date] => 2012-11-08 [pickup_time] => 9 AM to 12 PM ) ) Everything so far is good. Here is what I need to do: I need to loop through $bundle_pickup array and find out which arrays are different. I need to get $bundle_pickup['bundle_ID'] of all the unique arrays The idea is, if the customer picks same pickup date and time for all bundles, he only pays one pickup charge. If he chooses multiple pickup dates or times, he will need to pay multiple charges. If two bundles have same pickup dates/times and other two have same ( but different than first two ), the customer will pay two pick up charges. Since this is a CMS site, I will not know the bundle_ID, pickup dates, pickup times and order of the bundles. If anyone can suggest how I can get $bundle_pickup['bundle_ID'] of all the unique arrays, that would be greatly appreciated. Once I have the IDs, I can use them to fetch other data from the database. Thanks in advance. Jatt Surma
  2. Thanks for your help guys. I tried it out and it worked flawlessly. I appreciate it. Jatt Surma
  3. Hi, I'm trying to figure out how to select all the males from database that are within the ages of 20 - 30. I can't get the query working. If someone can point me to right direction, it will be greatly appreciated. Here is my query: $query = "SELECT * FROM profiles WHERE sex={$_GET['sex']}, age >= 20, age <= 30 ORDER BY pId DESC"; this is what I get when I echo the $query: SELECT * FROM profiles WHERE sex=Male, age >= 20, age <= 30 ORDER BY pId DESC Thank in advance for your help. Jatt Surma
  4. Hello Everyone, I have a little trouble figuring out something. I was hoping that one of the masterminds out there can help me out. Here is what I'm trying to do: I got an Ajax script from dynamic drive. This script opens a page within a div. Here is the script: <script type="text/javascript"> /*********************************************** * Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no) var loadedobjects="" var rootdomain="http://"+window.location.hostname var bustcacheparameter="" function ajaxpage(url, containerid){ var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject){ // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} } } else return false page_request.onreadystatechange=function(){ loadpage(page_request, containerid) } if (bustcachevar) //if bust caching of external page bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime() page_request.open('GET', url+bustcacheparameter, true) page_request.send(null) } function loadpage(page_request, containerid){ if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) document.getElementById(containerid).innerHTML=page_request.responseText } function loadobjs(){ if (!document.getElementById) return for (i=0; i<arguments.length; i++){ var file=arguments var fileref="" if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding if (file.indexOf(".js")!=-1){ //If object is a js file fileref=document.createElement('script') fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", file); } else if (file.indexOf(".css")!=-1){ //If object is a css file fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", file); } } if (fileref!=""){ document.getElementsByTagName("head").item(0).appendChild(fileref) loadedobjects+=file+" " //Remember this object as being already added to page } } } </script> That is within my <head></head> tags and it does its job. I'm using it to open 3 different forms in the same div, for example: <a href="javascript:ajaxpage('form1.php', 'contentarea');">Form #1</a> <div id="contentarea"></div> <a href="javascript:ajaxpage('form2.php', 'contentarea');">Form #2</a> <div id="contentarea"></div> <a href="javascript:ajaxpage('form3.php', 'contentarea');">Form #3</a> <div id="contentarea"></div> Up to this point everything is good. Here is the problem: Every form has an action and a submit button. When I press the submit button, the result appears on a different page and I want it to appear in the same "contentarea" div. Can anyone suggest what should I do? Thanks in advance for your help. Regards Jatt Surma!
  5. Hello Ignace, Thanks for your help! Your second query was all I needed. I changed the userdata.account_type to userdata.account_id and it worked like a charm. Thanks again! I appreciate it. I really gotta learn how to join tables. Jatt Surma
  6. Hello, I'm having a bit of trouble with trying to figure out what to do. If someone can point me to right direction, it will be greatly appreciated. Here is what I need: I have 2 MYSQL tables in this format: Table userdata: uId, fName, lName, address, account_type, manager_id etc. Table projects: pId, width, height, pic1, pic2, agent_id etc. What I'm trying to accomplish is: 1) I want to get all the agents (account_type from userdata table) from 1 manager using the manager_id. 2) Show all the projects posted by all the agents under this manager. Can someone tell me how can this be done using php and MYSQL. Thanks in advance for your suggestions and help! Jatt Surma
  7. Hello EmlynK, You are a GENIUS. it worked like a charm. Thank you! Jatt Surma
  8. hello ansharma, Thanks for your help. I understand why I'm getting that message. It's because I'm logged in as "internal admin" and than I have same statement saying that "If account type is not super admin" show that error. What I'm trying to do is that only the "Super admins" and "internal admins" have access to that page. So customers or anyone else can not view it. How should I do that? Thanks again for your time. Jatt Surma
  9. Hello Everyone, From time to time, I get into a situation where my if statements do not give the desired results. I always have to play around with them to get the things working. I'm in same situation right now. I'm guessing that I do not completely understand the logic. If someone can take a look at the code below and tell me what's wrong, it will be greatly appreciated. if($_SESSION['account_type'] != 'internal admin'){ die('<font color="red"><b>Error:</b> This page can only be accessed by internal or super admin.</font>'); break; } elseif($_SESSION['account_type'] != 'super admin'){ die('<font color="red"><b>Error:</b> This page can only be accessed by internal or super admin.</font>'); break; } I have echoed out the $_SESSION['account_type'] and I'm getting "internal admin" but for some reason, I'm getting the error "Error: This page can only be accessed by internal or super admin." Thanks in advance for your help. Jatt Surma
  10. Hello Maq, Thanks again! I have 2 records in MYSQL table and they both match with the query. Here is result of $myAgents echo: SELECT * FROM userdata WHERE MATCH(fName,lName) AGAINST('John' IN BOOLEAN MODE) AND account_type='agent' AND manager_id='222222' ORDER BY fName ASC Here is rest of the code: <?php echo'<div align="left"><form name="search" method="get" action="'.$site_url.'portal/my-agents.php?do=search'.'"> <input type="text" name="terms" size="20" value="'.$_GET['terms'].'"><input type="submit" value="Find"> </form></div> '; if($_GET['terms']){ $terms = $_GET['terms']; $myAgents = "SELECT * FROM userdata WHERE MATCH(fName,lName) AGAINST('$terms' IN BOOLEAN MODE) AND account_type='agent' AND manager_id='".$_SESSION['manager_id']."' ORDER BY fName ASC"; //echo $myAgents; mysql_query($myAgents) or die(mysql_error()); } else{ $myAgents = mysql_query("SELECT * FROM userdata WHERE account_type='agent' AND manager_id=".$_SESSION['manager_id']); } $tMyAgents = @mysql_num_rows($myAgents); echo' <table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td valign="top" align="left">Name:</td> <td valign="top" align="left">Leads:</td> <td valign="top" align="left">Contracts:</td> <td valign="top" align="left">Status:</td> </tr>'; for($i=1;$i<=$tMyAgents;$i++){ $agent = mysql_fetch_array($myAgents); $leads = mysql_num_rows(mysql_query("SELECT project_id FROM projects WHERE agent_id=".$agent['agent_id']." AND status='LEAD'")); $contracts = mysql_num_rows(mysql_query("SELECT project_id FROM projects WHERE agent_id=".$agent['agent_id']." AND status='CONTRACT'")); echo'<tr> <td valign="top" align="left">'.$agent['fName'].' '.$agent['lName'].'</td> <td valign="top" align="left">'.$leads.'</td> <td valign="top" align="left">'.$contracts.'</td> <td valign="top" align="left">'.$agent['status'].'</td> </tr>'; } echo'</table>'; ?> As you can see that there are 2 queries 1 with search and 1 without search. One without search works perfectly. So its something with the search query. Thanks again! I appreciate your help. Jatt Surma
  11. Hello Maq, Thanks a lot! That took care of the error part. for some reason, it is not working. I'm not getting any errors neither any results. I know all the variables have the right values as well as the MYSQL table. Any other suggestions? Thanks again for your help. Jatt Surma
  12. Hello Everyone, I'm new here so "Hi" to all the php freaks out there. I'm new to php as well but I'm getting hang of things pretty quickly. I have one issue that I'm struggling with so your help will be greatly appreciated. Here is my problem: I'm trying a create a simple boolean search function with multiple WHERE conditions. Here is the code: if($_GET['terms']){ $terms = $_GET['terms']; $myAgents = "SELECT * FROM userdata WHERE MATCH(fName,lName) AGAINST('$terms' IN BOOLEAN MODE) AND WHERE account_type='agent' AND WHERE manager_id='".$_SESSION['manager_id']."' ORDER BY fName ASC"; //echo $myAgents; mysql_query("$myAgents") or die(mysql_error()); } But for some reason it is not working and I'm getting this: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE account_type='agent' AND WHERE manager_id='222222' ORDER BY fName ASC' at line 1 Can someone please tell me what am I doing wrong? Thanks in advance for your suggestions and help! Jatt Surma
×
×
  • 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.