Jump to content

soddengecko

Members
  • Posts

    43
  • Joined

  • Last visited

Everything posted by soddengecko

  1. I am quite new to PHP and have only got a grasp of the simpler functions so far. I knew it had to have something to do with looping through the data. Thank you again for your help. Mark
  2. WOW. that's it. I have tested it and it all appears to be working. I cannot thank you enough for your help on this. This is the whole code that is now being used function prep_data($input,$widget_column_id){ $widget_column_id = str_replace(",","','",$widget_column_id); $string = (int)$input; return "UPDATE sg_desktop_widgets SET column_id = '$string' WHERE id IN ('$widget_column_id')"; } $insertions = null; foreach($_GET as $ind=>$val){ $ind = preg_replace ('/[^\d\s]/', '',$ind); //strip non-numeric characters $ind = (int)$ind;//make it an integer $insertions = prep_data($ind,$val); mysql_query("$insertions") or die('<div class="error ui-corner-all">Error, insert query failed</div>'); Thank you again for all the help you guys have provided.
  3. This is what I have currently <?php include "includes/config.php"; function prep_data($input,$widget_column_id){ $string = ''; $columns = explode(",",$input); foreach($columns as $number){ $num = (int)$number; if(!empty($string)){$string .= " AND";} $string .= "$number"; } return "UPDATE sg_desktop_widgets SET column_id = '$string' WHERE id = '$widget_column_id'"; } $insertions = null; foreach($_GET as $ind=>$val){ $ind = preg_replace ('/[^\d\s]/', '',$ind); //strip non-numeric characters $ind = (int)$ind;//make it an integer $insertions = prep_data($ind,$val); echo $insertions; } ?> The output of $insertions is UPDATE sg_desktop_widgets SET column_id = '1' WHERE id = '1,4,2,9,5'UPDATE sg_desktop_widgets SET column_id = '2' WHERE id = '6,10,3'UPDATE sg_desktop_widgets SET column_id = '3' WHERE id = '8'UPDATE sg_desktop_widgets SET column_id = '4' WHERE id = ''UPDATE sg_desktop_widgets SET column_id = '5' WHERE id = '7' It is getting very close.
  4. ok, so I made it this far UPDATE sg_desktop_widgets SET column_id = 1 WHERE id = 1,3,10,2UPDATE sg_desktop_widgets SET column_id = 2 WHERE id = 6,9UPDATE sg_desktop_widgets SET column_id = 3 WHERE id = 8UPDATE sg_desktop_widgets SET column_id = 4 WHERE id = 4,5UPDATE sg_desktop_widgets SET column_id = 5 WHERE id = 7 how do I break each update statement out of that long string and split the ID's up so I can add this all to the database? TIA Mark
  5. fantastic. That fixed it. my update statement is now UPDATE sg_desktop_widgets SET 'column_id' = 1,2 WHERE 'id' = (1) UPDATE sg_desktop_widgets SET 'column_id' = 6 WHERE 'id' = (2) UPDATE sg_desktop_widgets SET 'column_id' = 8,9,3 WHERE 'id' = (3) UPDATE sg_desktop_widgets SET 'column_id' = 4,5 WHERE 'id' = (4) UPDATE sg_desktop_widgets SET 'column_id' = 7,10 WHERE 'id' = (5) It is not quite correct, the id's are the wrong way round but its close and I will try make the changes myself. I will get back to you shortly. Thank you for all of your help. I am sure I will have more questions on this particular problem. back in 10
  6. Hi Mikesta The script is from another forum member trying to help me out with a problem I am having. Your amendment has helped and I know get this as the output: UPDATE sg_desktop_widgets SET 'column_id' = WHERE 'id' = (2)UPDATE sg_desktop_widgets SET 'column_id' = WHERE 'id' = (61)UPDATE sg_desktop_widgets SET 'column_id' = WHERE 'id' = (893)UPDATE sg_desktop_widgets SET 'column_id' = WHERE 'id' = (45)UPDATE sg_desktop_widgets SET 'column_id' = WHERE 'id' = (710) As you can see, I am not getting the column ID's at all and the numbers are now bunched together ie. (45) That should be a 4 and a 5 not 45. Can you see where it is going wrong?
  7. Hi I get a "Cannot access empty property in" for this line foreach($_GET as $ind->$val){ the ("2,3,8") is the sort order rather than the ID
  8. the result of the dump is array(5) { ["column1"]=> string(3) "1,2" ["column2"]=> string(1) "6" ["column3"]=> string(3) "8,3" ["column4"]=> string(5) "4,5,9" ["column5"]=> string(4) "7,10" } i am storing the data in a table called sg_desktop_widgets and the table has the following rows id (auto increment/primary key) name column_id widget_order an example would be id | name | column_id | widget_order ------------------------------------ 1 | RSS Feeds | 1 | 0 2 | Bookmarks | 1 | 1 3 | Misc | 2 | 0 I get the widgets from the DB by order of column, then sort the widgets in each column by widget_order. Hope that makes sense to you
  9. Hi kratsg Absolutely beautiful. That works well. I am now using the following script (please correct me if there is a better way to iterate through all available columns without me having to code each one) function prep_data($input,$column){//1 $string = ''; $numbers = explode(",",$input); foreach($numbers as $number){//5 <---------------- THIS IS LINE 20 $num = (int)$number; if(!empty($string)){$string .= ",";} $string .= "($num)"; } return "($column) VALUES".$string; }//10 $insertions = array();//1 $insertions[] = prep_data($_GET['column1'],'1'); foreach($insertions as $inserts){ //mysql_query("INSERT INTO `tablename` $inserts"); echo $inserts . "<br />"; }//5 $insertions = array();//1 $insertions[] = prep_data($_GET['column2'],'2'); foreach($insertions as $inserts){ //mysql_query("INSERT INTO `tablename` $inserts"); echo $inserts . "<br />"; } $insertions = array();//1 $insertions[] = prep_data($_GET['column3'],'3'); foreach($insertions as $inserts){ //mysql_query("INSERT INTO `tablename` $inserts"); echo $inserts . "<br />"; } $insertions = array();//1 $insertions[] = prep_data($_GET['column4'],'4'); foreach($insertions as $inserts){ //mysql_query("INSERT INTO `tablename` $inserts"); echo $inserts . "<br />"; } $insertions = array();//1 $insertions[] = prep_data($_GET['column5'],'5'); foreach($insertions as $inserts){ //mysql_query("INSERT INTO `tablename` $inserts"); echo $inserts . "<br />"; } This then returns the following info (depending which widget is in which column) (1) VALUES(3),(9),(1),(2),(6) (2) VALUES(0) (3) VALUES( (4) VALUES(4),(5) (5) VALUES(7),(10) I believe (with your kind help) that i am now making progress. One last hurdle is how to tell the database what to update and where. Thank you Mark
  10. Hi Kratsg Thank you for the explanation, I really appreciate your help and patience. I have a slight problem though, I have put the code on the page and when run I get a parse error that I am not sure how to fix. this is the error Parse error: syntax error, unexpected T_INT_CAST, expecting '&' or T_STRING or T_VARIABLE or '$' in /var/www/updateDesktop.php on line 20 This is the code I have on the page. <?php include "includes/config.php"; $col1 = explode('&', $_GET['column1']); $col2 = explode('&', $_GET['column2']); $col3 = explode('&', $_GET['column3']); $col4 = explode('&', $_GET['column4']); $col5 = explode('&', $_GET['column5']); //print_r($col1); //print_r($col2); //print_r($col3); //print_r($col4); //print_r($col5); function prep_data($input,$col1){//1 $string = ''; $numbers = explode(",",$input); foreach($numbers as (int)$number){//5 <---------------- THIS IS LINE 20 if(!empty($string)){$string .= ",";} $string .= "($number)"; } return "($col1) VALUES".$string; }//10 $insertions = array();//1 $insertions[] = prep_data($_GET['column1'],'column1'); foreach($insertions as $inserts){ //mysql_query("INSERT INTO `tablename` $inserts"); echo $inserts; }//5 ?> As I said, this piece of code is more complex than I have used so am having a little trouble working it out. If it would be easier and a help I can explain in greater detail what I am trying to build? TIA Mark
  11. Hi kratsg I am not sure I fully understand your code. i have five variables passed from the ajax string like so ?column1=1,2&column2=........ and so on. I can grab those variables like so $col1 = explode('&', $_GET['column1']); $col2 = explode('&', $_GET['column2']); $col3 = explode('&', $_GET['column3']); $col4 = explode('&', $_GET['column4']); $col5 = explode('&', $_GET['column5']); print_r($col1); print_r($col2); print_r($col3); print_r($col4); print_r($col5); this prints the array as my last post states. I have also changed the code to a GET instead of POST Could you help break down your code for me. I am sorry if I seem a little dumb on this one but it is more complex than I am used to. TIA Mark
  12. Hi Yes, I am using ajax to send the data. each column is the variable and the widgets in the column are the variable data. I will try what you have suggested and get back you
  13. sorry, that array data actually looks like this Array ( [0] => 1,2 ) Array ( [0] => 3,4 ) Array ( [0] => 5,6 ) Array ( [0] => 7,8 ) Array ( [0] => 9,10 )
  14. Hi Thank you for the info. I use the following on the server side to get the POST data $_POST['column1'] $_POST['column2'] $_POST['column3'] so the values are like so 1,3 2 4,5 for each column respectively. After following what you have suggested I know have the following array data Array ( [0] => 1,2 ) Array ( [0] => 3,4 ) Array ( [0] => 5,6 ) Array ( [0] => 7,8 ) Array ( [0] => 9,10 ) I think the array numbers are wrong, they cannot all be 0 surely?
  15. Hi All I have a jquery script that allows me to drag and drop multiple widgets across multiple columns. The code is below. What I am trying to achieve is to update a database to remember the positions of the widgets on the stage and their open/closed state. $(function(){ $('.dragbox') .each(function(){ $(this).hover(function(){ $(this).find('h2').addClass('collapse'); }, function(){ $(this).find('h2').removeClass('collapse'); }) .find('h2').hover(function(){ $(this).find('.configure').css('visibility', 'visible'); }, function(){ $(this).find('.configure').css('visibility', 'hidden'); }) .click(function(){ $(this).siblings('.dragbox-content').toggle(); }) .end() .find('.configure').css('visibility', 'hidden'); }); $(document).ready(function(){ function slideout(){ setTimeout(function(){ $("#response").slideUp("slow", function () { }); }, 5500);} $('.column').sortable({ connectWith: '.column', handle: 'h2', cursor: 'move', placeholder: 'placeholder', forcePlaceholderSize: true, opacity: 0.4, stop: function(event, ui){ $(ui.item).find('h2').click(); var sortorder=''; $('.column').each(function(){ var item_order=$(this).sortable('toArray'); var columnId=$(this).attr('id'); sortorder+=columnId+'='+item_order.toString()+'&'; }); /*alert(sortorder);*/ /*Pass sortorder variable to server using ajax to save state*/ console.log(sortorder); $.get('updateDesktop.php', sortorder, function(Response){ $("#response").html(Response); $("#response").slideDown('slow'); slideout(); }); } }) .disableSelection(); }); }); The output I get from the post data is like so column1=2,1&column2=&column3=3&column4=& What I want to know, is anyone able to point me in the right direction to update the database. Does a change of JS need to be done to output the variables differently or can I get the data sorted correctly on the server side? TIA Mark
  16. I would like to say a huge thank you to RussellReal for helping me with this. He took his time to chat to me on msn and build a script that would do just what I needed. Thank you
  17. hi all. i need some help if you can. I am trying to build a regex that will read cinema listings from my local cinemas website. the cinema site is here - http://www.odeon.co.uk/fanatic/film_times/s3/Cardiff/index.php So far I am using the regex below to get the data i need <?php $content = file_get_contents("http://www.odeon.co.uk/fanatic/film_times/s3/Cardiff/index.php"); $get_film_data_regex = '#<div\b[^>]*class=([\'"])?filminfos(?(1)\1)[^>]*>.*?</div>#s'; preg_match_all($get_film_data_regex,$content,$regexed_film_data); foreach ($regexed_film_data as $film_data) { foreach ($film_data as $data) { print "$data\n</div>\n\n"; } //nothing here } ?> The code above works fine, i get the data as one large chunk. My issue is that I want to be able to dissect the data into component parts for integration into my local Intranet site. (film title, certificate, film info and of course, the days and times) this is a sample of the data I will be trying to get the info from (below). this sample code is for one movie. the end of the data will increase/decrease depending on how many days and at what times the film is available, but it will always have this format, starting with <div class="rightside"> and the closing div after the view trailer link. (after the view trailer div has been closed) <div class="rightside"> <div class="filminfos"> <h1><a href="/fanatic/film_info/s3/Cardiff/m11900/12_Rounds/" title="Film information, ratings & guest reviews of "12 Rounds"">12 Rounds</a></h1> <a href="/fanatic/classifications/" title="More information about film classifications"><img src="http://m2.odeon.co.uk/img/certificates/greymiddle/12.gif" alt="Classification: 12A"></a><br class="cl"> <div class="details">Running time: 108 mins (Contains moderate action violence and moderate language)</div> </div> <div class="formats"></div> <div class="ratingBox clearfix"></div> </div> <div class="cl"></div> </div> <div class="timeslisting clearfix fRegular fWednesday fThursday"> <div class="dayline clearfix fWednesday"> <div class="day"><span>Wednesday</span></div> <div class="showingtimes"><span><a href="/fanatic/booking/s3/p1886900/" title="Book tickets online now for the movie "12 Rounds" on Wednesday, 21:20 at the ODEON cinema in Cardiff">21:20</a></span></div> <div class="cl"></div> </div> <div class="cl"></div> <div class="dayline clearfix fThursday"> <div class="day"><span>Thursday</span></div> <div class="showingtimes"><span><a href="/fanatic/booking/s3/p1886957/" title="Book tickets online now for the movie "12 Rounds" on Thursday, 21:20 at the ODEON cinema in Cardiff">21:20</a></span></div> <div class="cl"></div> </div> <div class="cl"></div> </div> </div> <a name="mf11438" id="mf11438"></a> <div class="filmdiv" id="f11438"> <div class="filmblock clearfix fSaturday fSunday fMonday fTuesday fWednesday fThursday"> <div class="leftside"><img src="http://m2.odeon.co.uk/_uploads/film_images/small/13724.jpg" alt="Film image of "17 Again""> <div class="trailerlink"><img src="http://m2.odeon.co.uk/img/content/view_trailer_darkblue.gif" alt=""> <a href="/fanatic/film_info/s3/Cardiff/m11438/17_Again/trailer/" title="Movie trailer, film information, guest reviews & ratings of "17 Again"">View Trailer</a></div> </div> can anyone point me in the direction i need to take to get this working? I have spent days on this, exhausted 100's of google search results and even downloaded an application that was supposed to help me work it out (yeah, i was grasping at straws) If you need more info, or I have missed something then let me know and I will get back to you TIA Mark
  18. Hi All I am building a script to authenticate users against active directory. I have this working fine on the main page. I enter my user details and click submit and I log in fine. My problems start when I try to navigate to another page on the site. I get the login box appear again. My header is a separate file and is included in all pages, in the header is the login script below. I know the session variables still exist from page to page as I can output them with print_r on every page but the page still fails to authenticate and already logged in user. can anyone please shed some light on this? <?php session_start(); function authenticate() { ?> <form action="" method="POST"> <div style="height:10%"></div> <table cellspacing="0" cellpadding="0" border="0" align="center" class="loginBox"> <tr> <td colspan="2" class="topbar">New User Info</td> </tr> <tr> <td colspan="2"><img src="images/header_top.jpg" alt="New User Info" width="270" height="46" class="loginImage" /></td> </tr> <tr><td colspan="2" height="36" class="error"><?php print $login_error; ?></td></tr> <tr> <td class="loginLabel">Username:</td> <td class="loginField"><input type="text" name="loginname" value="" /></td> </tr> <tr> <td class="loginLabel">Password:</td> <td class="loginField"><input type="password" name="loginpass" valign="bottom" /></td> </tr> <tr><td colspan="2" height="12"></td></tr> <tr class="footerImage"> <td colspan="2" class="loginBottom"><input type="submit" class="loginButton" value="Login"></td> </tr> </table> </form> <?php exit; } $loginname = $_POST['loginname']; $loginpass = $_POST['loginpass']; if(!isset($loginname) && isset($_SESSION['user']) && isset($_SESSION['password']) && isset($_SESSION['domain'])){ //if the session does not exist, call the authentication script again authenticate(); } else{ //grab the username and password enetered and process it against the AD site $_SESSION["domain"] = $domain = 'MYDOMAIN'; // <- your domain $_SESSION["user"] = strtoupper($loginname); $_SESSION["password"] = $loginpass; // this is the active directory details we need to verify authentication. $LDAPServerAddress1="XXX.XXX.XXX.XXX"; // <- IP address for your 1st DC $LDAPServerPort="389"; $LDAPServerTimeOut ="60"; $LDAPContainer="dc=MYDOMAIN,dc=LOCAL"; // <- your domain info $BIND_username = "MYDOAMIN\\administrator"; // <- an account in AD to test using $BIND_password = "PASSWORD"; $filter = "sAMAccountName=".$_SESSION["user"]; $login_error_code = 0; if(($ds=ldap_connect($LDAPServerAddress1)) ) { ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); if($r=ldap_bind($ds,$BIND_username,$BIND_password)) { if($sr=ldap_search($ds, $LDAPContainer, $filter, array('distinguishedName'))) { if($info = ldap_get_entries($ds, $sr)) { $BIND_username = $info[0]['distinguishedname'][0]; $BIND_password = $_SESSION["password"]; if ($r2=ldap_bind($ds,$BIND_username,$BIND_password)) { if($sr2=@ldap_search($ds, $LDAPContainer, $filter, array("givenName","sn","mail","displayName","samaccountname","telephonenumber","mobile","l","department","company","manager","physicaldeliveryofficename","distinguishedname"))) { if($info2 = @ldap_get_entries($ds, $sr2)) { //retrieve all required data from AD and store them as session variables. $_SESSION["name"] = $info2[0]["givenname"][0]." ".$info2[0]["sn"][0]; $_SESSION["firstName"] = $info2[0]["givenname"][0]; $_SESSION["lastName"] = $info2[0]["sn"][0]; $_SESSION["email"] = $info2[0]["mail"][0]; $_SESSION["displayname"] = $info2[0]["displayname"][0]; $_SESSION["ntlogon"] = $info2[0]["samaccountname"][0]; //session name = AD field $_SESSION["telephone"] = $info2[0]["telephonenumber"][0]; $_SESSION["mobile"] = $info2[0]["mobile"][0]; $_SESSION["location"] = $info2[0]["l"][0]; $_SESSION["department"] = $info2[0]["department"][0]; $_SESSION["company"] = $info2[0]["company"][0]; $_SESSION["manager"] = $info2[0]["manager"][0]; $_SESSION["office"] = $info2[0]["physicaldeliveryofficename"][0]; $_SESSION["dn"] = $info2[0]["distinguishedname"][0]; } else { $login_error = "Could not read entries"; $login_error_code=1; } } else { $login_error = "Could not search"; $login_error_code=2; } } else { $login_error = "User password incorrect"; $login_error_code=3; } } else { $login_error = "User name not found"; $login_error_code=4; } } else { $login_error = "Could not search"; $login_error_code=5; } } else { $login_error = "Could not bind"; $login_error_code=6; } } else { $login_error = "Could not connect"; $login_error_code=7; } if($login_error_code > 0) { //authenticate(); // if the error code is greater than 0 then fail and ask for authentication again. //print $login_error; //print the login error for debugging } else { } } ?> If anyone needs a further explanation then let me know TIA Mark
  19. hi all I am loading my content externally into a div to show recent updates to my site. at the moment i am deleting old entries so that i am only showing 10 updates at a time. the data is a simple list of items. is it possible to have javascript go through this list and only output only the first ten entries in the <ul>?
  20. Absolutely perfect. Thank you very much for that one. That worked like a dream and is keeping my client happy.
  21. hi all. I have a while statement that pulls all data from the db where a certain criteria is met. in this case where the manufacturer name matches the POST'ed value. works a treat. here is the code: while ($row = mysql_fetch_array( $result )) { $row_class = ($row_count % 2) ? $class1 : $class2; $id = $row['id']; $manu = $row['manufacturer']; $mod = $row['model']; $colour = $row['colour']; $whole = $row['wholesale_price']; $retail = $row['retail_price']; $quan = $row['quantity']; ?> do html stuff here <? // Add 1 to the row count $row_count++; } I have a set of links listing all the manufacturers in the db from the manufacturers table which is pre-populated with all manufacturers. when the link is clicked a page showing the DISTINCT models made by the defined manufacturer is shown. this all works inside my while loop. the issue is when i try to create an else clause for products that are not in the db. so if i click on LG and there are no LG products i want an error message stating there is nothing to display. when I wrapped my while statement inside an IF it did this but only shows one product instead of looping through and displaying all. this is the IF statement <? if ($row = mysql_fetch_array( $result )) { $row_class = ($row_count % 2) ? $class1 : $class2; $id = $row['id']; $manu = $row['manufacturer']; $mod = $row['model']; $colour = $row['colour']; $whole = $row['wholesale_price']; $retail = $row['retail_price']; $quan = $row['quantity']; ?> do html here <? // Add 1 to the row count $row_count++; } else { echo "nada"; } ?> how do i get the IF to loop through all data, or how do i nest a while statement inside the IF?
  22. time consumption is not so much of a worry and it is a way of doing it. i would much prefer to have the function auto generate the page etc otherwise i am going to end up with a few hundred pages just to get what i need. i will keep thinking about it. anyone else have anything to throw into the mix?
  23. it's a good idea. one i have thought about doing. my client is somewhat daft and he has asked for a specific way of doing this. i see similar things on blogs with the archive sections. link is created for a given month, clicking it will list all posts from that month so my client is asking me to do the same thing for the app i am building. i have no idea what you would call this function so i am having trouble googling for it.
  24. hi all i am calling all data from a database and listing it in a table. The main trouble is that some sections will have a large amount of data in them with different categories. for example, i have a db of mobile phone manufacturers and models. as you can imagine there are a lot of them. so far i have the data paged with 30 results a page and it is all listed in alphabetical order by manufacturer so it is relatively easy to find data if you keep clicking through the lists. what i would like to do is have a set of links (which i have done using manufacturer as the title). how do i use those links for the following: if i click on Nokia for instance, how do i get ALL Nokia only phones listed and not show any other data?
×
×
  • 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.