Jump to content

danieliser

Members
  • Posts

    45
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

danieliser's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. If you never found a solution here is the one i came up with and works fine.. For your java: function index_get($link) { var req = CreateXmlHttpObject(); // fuction to get xmlhttp object if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { //data is retrieved from server if (req.status == 200) { // which reprents ok status document.getElementById('content_body').innerHTML=req.responseText;//put the results of the requests in or element var title = document.getElementById('title').innerHTML document.title = title } else { alert("There was a problem while using XMLHTTP:\n"); } } } req.open("POST", "calls/index_get.php?" + $link, true); //open url using get method req.send(null);//send the results } } here i pass a simple link from my database build menus link field "product=18" or "page=3" my index_get.php explodes that into 'product' and '18' then gets the info for that product from the database containing a title field.. i then have that title asigned to a hidden div echo "<div id='title' style='display: none'>New Title</div>"; this div wont be displayed and once the page is loaded the ajax gets the value of the title div and then using javascript replaces the title.. the content of the index_get.php is processed and displayed before the var title is asigned. document.getElementById('content_body').innerHTML=req.responseText;//put the results of the requests in or element var title = document.getElementById('title').innerHTML document.title = title hope that helps.. its been a while since you posted but i couldnt find the solution either.. had to figure it out.
  2. lol.. i feel retarded haha.. the first page of that deals with that.. i didnt even realize i was on the second.. but im happy cause i thought of using a function before i read that haha.. i know im getting the hang of php and sql when im laying in bed at night to fall asleep and running through the code it would take to add a function to the site in my head haha.. usually forget by morning though.. blah.. thanks again..
  3. I dont mind that now.. but i am planning to template this for sale to other companies of which i dont know thier requirements.. if i were to get a client that had a mass selection of products.. such as hypathetically walmart.. cough cough.. that model wouldnt work as well with records constantly changing and being added/removed. I also am thinking possibly a php funtion.. and upon any record having childcount > 0 calling the funtion which would just loop back on itself til there were no results left. but that would require multiple querys.. so i guess im gonna moch up several of these different ways and see which works best for my needs.
  4. thanks for the help.. i have previously read http://www.sitepoint.com/article/hierarchical-data-database/2/ and i am not sure that will work for me.. or at least i am confused on how i would implement it.. i have an admin area setup already that allows for the adding of pages and products and i will add in the ability to change the sort order column on my table to change the sort of the menu. but the site above would require the menu table to be rebuilt to affect the menu. im just lost as to where i would do that.. i guess on submission of a new page/product i could attach the rebuild to the submission. hmm.. maybe an easier way out i guess.. i would love to make it work without that and be a completely independent dynamic menu.. i have been toying with the idea of asigning all the values to variables in the loop and then possibly allowing the php to loop back through to reorder and output.. not sure if that is feasible.. or if it would be less server load than just multiple select statements.. oh.. ps.. i know this isnt in the right forum.. but is it possible in php to have a loop inside a loop but the contents of the inside loop also loop back to the first loop? i know in C i could just use GOTO LINE or something haha.. that would be to simple here..
  5. well avg time now since the first try is around .002 - .003 seconds per query. not sure what you mean by put an inde on parent_id though. i am making a CMS setup that i can template and use for my web design business.. i have been putting it off for a while.. but im tired of having to add new prodcuts for my clients and id hate to have to do that for 100+ products. im not 100% this query will do the work i want it to now.. as im trying to code the php to do a limitless level menu. i dont want to have to have my php setup using loop inside of loop inside of loop.. and even then im almost forced to use a second select statement to retrieve the children. any ideas to do this using only one query? as this will be loaded everytime you refresh the page i want it very lightweight.
  6. not sure if it was just a lag in the connection or if it memorized the results.. but now it is loading the results in navicat in .003secs... seems to be working as fast as i was hoping..
  7. wow.. worked perfect lol.. i would have never come up with that.. thanks a ton.. although after running it several times.. it might be to cumbersome to run on a larger menu.. took several seconds with only 12 results. might have to try and achieve the result using php.. any tips? trying to make this lightweight and fast.. hence the reason i am trying to do it with only one query..
  8. MySQL Version - 5.1.33-community ok im trying to build a dynamic menu setup and the way i want to go about it is to get the following from a single table table is as follows -- ---------------------------- -- Table structure for menu -- ---------------------------- DROP TABLE IF EXISTS `menu`; CREATE TABLE `menu` ( `id` int(11) NOT NULL AUTO_INCREMENT, `label` varchar(50) NOT NULL DEFAULT '', `link_url` varchar(100) NOT NULL DEFAULT '#', `parent_id` int(11) NOT NULL DEFAULT '0', `sort_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=latin1; Ok, so what i want returned is ID | LABEL | LINK_URL | PARENT_ID | SORT_ID | COUNT1 COUNT1 is where this is tricky.. i have tried using COUNT and GROUPBY but i am either not doing it right or i am needing something else I want COUNT1 to return the number of other row where parent_id = ID of the current row so that if there is a submenu it will return > 0. If not it returns zero. Then i can loop that with php to echo the proper format for my menu.
  9. awesome.. i figured it was a function like explode.. ive used that before but wasnt sure how to work the code.. So i should just put that on for the else and make an array of the bad codes? any chance you know how to modify and add java verification to vbulletin userfields huh?
  10. Back Story: Im using vbulletin and using a custom user field for each user to list there game id which should be formatted '123-123-123'. I was unable to incorporate a js function to format it automatically as they type. I got the function working but could not get it working inside the code on vbulletin admincp. I am looking into hardcoding the field into the register.php but havent got that worked out.. Problem is is users are constantly inputting the data as 123123123 or 123 123 123 or even 123~123~123. I was able to put together a regex to check the format. but i cant get that working in vbulletin either.. so until i do. I am gonna run a cron job every 24 hours using php and getting all results from the table within the last 24 hours and checking them using regex. Ive got that part working. Current Issue: For my else statement i need to figure out how to break down 123123123 and 123 123 123 and reformat them as 123-123-123 then update the database. here is what i have so far.. <?php require('includes/db.php'); $sql = "SELECT userid, field5 FROM userfield"; $result = mysql_query($sql); while ($myrow = mysql_fetch_array($result)) { $userid = $myrow['userid']; $field5 = $myrow['field5']; $i = 0; $e = 0; if (eregi('^[0-9]{3}-[0-9]{3}-[0-9]{3}$', $field5)) { $e = ($e + 1); } else { reformat blah blah $newfield5 = $update = "UPDATE userfield SET field5='$newfield5' WHERE userid='$userid'" $i = ($i + 1); }; } $total = ($e + $i); echo $total, ' NEW RECORDS TODAY!<br />'; echo $e, 'USERS NOT CHANGED<br />'; echo 'SUCCESSFULLY UPDATED ',$i,' USERS RECORDS'; ?>
  11. No i dont get a result.. but im trying to correct that with php.. here is what ive got so far.. <?php ///////////////////////////////////////////// //Get The Last Underlord Date Already Taken// ///////////////////////////////////////////// $sql = "SELECT underlord_date, COUNT(*) AS Total FROM underlord WHERE underlord_date>CURDATE() AND underlord_date NOT IN (SELECT underlord_date FROM underlord WHERE userid='$userid') GROUP BY underlord_date HAVING Total<16 ORDER BY underlord_date LIMIT 1"; $result_1 = mysql_query($sql); if (mysql_num_rows($result_1) == 0) {echo 'IF 1 OPTION 1<br />'; $sql = "SELECT underlord_date FROM underlord WHERE underlord_date>CURDATE() ORDER BY underlord_date DESC LIMIT 1"; $result_2 = mysql_query($sql); if (mysql_num_rows($result_2) == 0) //Set Date to Day after Today {echo 'IF 2 OPTION 1<br />'; $phpdate = strtotime(date('Y-m-d')); $next_available = date('Y-m-d',$phpdate + 86400); $underlord_next = $next_available; } elseif (mysql_num_rows($result_2) != 0) //Set Date to Day after Last Day in Table {echo 'IF 2 OPTION 2<br />'; $myrow = mysql_fetch_array ($result_2); $last_date = $myrow['underlord_date']; $phpdate = strtotime($last_date); $next_available = date('Y-m-d',$phpdate + 86400); $underlord_next = $next_available; } else; } elseif (mysql_num_rows($result_1) != 0) {echo 'IF 1 OPTION 2<br />'; $myrow = mysql_fetch_array ($result_1); $underlord_next = $myrow['underlord_date']; } else; echo $underlord_next,'<br />'; ?> So far it works perfect.. im trying to break it though.. any chance you wanna break it for me? i know it lacks in 2 ways.. 1 a verification that it had the right day, 2 PHP/MYSQL Security.. i need to read up on that part.. any good guides? need to protect my investment.. mostly time but w/e.. dont want anybody injecting freebies.. by the way i loop this for the quantity funciton i was trying to achieve.. im gonna use Paypal IPN.. so you need to insert the variables manually for $userid and $quantity.. my ipn script gets that and passes it on..here is the loop.. for ($i = $quantity; $i > 0;) { require('./includes/underlord_next.php'); $sql="INSERT INTO `underlord` VALUES ('', '$userid', '$underlord_next')"; $insert = mysql_query($sql); $i = ($i-1); }
  12. Did you see this query i came up with several posts up.. it will effectively check for all dates the user is listed on and then group all the groups of days excluding those in the results of the other subquery Here it is again.. SELECT underlord_date, COUNT(*) AS Total FROM underlord WHERE underlord_date>CURDATE() AND underlord_date NOT IN (SELECT underlord_date FROM underlord WHERE userid='$userid') GROUP BY underlord_date HAVING Total<16 ORDER BY underlord_date That works perfect... im having trouble now rebuilding my application using those results though.. im sure its something simple so i am currently adding a or die(custom error) for every line to see what is going on..
  13. here is the php i came up with.. does it look right? i mean its not gonna skip any days.. whether or not they are already in there.. i have a ton of testing to do in the morning.. but im done for tonight.. night all.. ipn.php <?php //////////////////////////////// // GET USERID FROM USER TABLE // //////////////////////////////// $sql="SELECT * FROM user WHERE email='$payer_email'"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); $userid = $myrow['userid']; //////////////////////////// // ASSIGN PURCHASED DATES // //////////////////////////// if ($item_name == 'dracula') { for ($i = $quantity; $i > 0;) { require('includes/dracula_next.php'); $sql="INSERT INTO `dracula` VALUES ('', '$userid', '$dracula_next')"; $result = mysql_query($sql); $i = ($i-1); } } elseif ($item_name == 'overlord') { for ($i = $quantity; $i > 0;) { require('includes/overlord_next.php'); $sql="INSERT INTO `overlord` VALUES ('', '$userid', '$overlord_next')"; $result = mysql_query($sql); $i = ($i-1); } } elseif ($item_name == 'underlord') { for ($i = $quantity; $i > 0;) { require('includes/underlord_next.php'); $sql="INSERT INTO `underlord` VALUES ('', '$userid', '$underlord_next')"; $result = mysql_query($sql); $i = ($i-1); } } else; ?> overlord_next.php <?php $sql="SELECT underlord_date, COUNT(*) AS Total FROM underlord WHERE underlord_date>CURDATE() AND underlord_date NOT IN (SELECT underlord_date FROM underlord WHERE userid=$userid) GROUP BY underlord_date HAVING Total<16 ORDER BY underlord_date LIMIT 1"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); $underlord_available = $myrow['underlord_date']; if (!$result) { $sql="SELECT * FROM underlord ORDER by overlord_date DESC LIMIT 1"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); $last = $myrow['overlord_date']; $phpdate = strtotime($last); $phpdate = strtotime(date("Y-n-d")); $next_available = $phpdate + 86400; $underlord_next = date('Y-m-d',$next_available); } else; ?>
  14. Ive been hacking away and digging the internet for hours.. ive come up with this.. it works so far that ive tested and i intend to test more.. just wanting to know if this would be trumped by something else? or any critiquing SELECT underlord_date, COUNT(*) AS Total FROM underlord WHERE underlord_date>CURDATE() AND underlord_date NOT IN (SELECT underlord_date FROM underlord WHERE userid='$userid') GROUP BY underlord_date HAVING Total<16 ORDER BY underlord_date DESC
  15. Does this look right.. after much much tinkering i think i got it.. tests so far have been correct.. although i need to test it much further.. any critique would be much appreciated. SELECT underlord_date, COUNT(*) AS Total FROM underlord WHERE underlord_date>CURDATE() AND underlord_date NOT IN (SELECT underlord_date FROM underlord WHERE userid='$userid') GROUP BY underlord_date HAVING Total<16 ORDER BY underlord_date
×
×
  • 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.