-
Posts
9,409 -
Joined
-
Last visited
-
Days Won
1
Everything posted by MadTechie
-
I Mean, I have no idea what your talking about Oh look a bug it says I just edited my last post but I didn't honest!
-
echo "Agreed"; I mean echo 'Agreed';
-
In that case why not just use a XML parse ? instead of replying on 2 sites to pull out a small section on text!
-
ahh that because of the as heres a function update function fieldFilter($str){ //filter out AS $str = preg_replace('/^.*as\s+/i', '', $str); //filter out spaces and back ticks and ][ $str = trim($str," ][`'"); return $str; }
-
Sorry if I appeared mad, that was not my intent, I just find if I have a lot of HTML in 1 of more variables I know I'm probably going to update it later, so I use the logic of single quotes for strict and double quotes for dynamic, for the whole variable. then I just have to remember to escape the double quotes, for example in $_GET['league'] league is strict (won't change) but $_GET["league{$x}s"] is dynamic and LOOK's cleaner (to me) instead of $_GET['league'.$x.'s'] as I said it's down to personal preference really. Oh and I maybe mistaken but I believe the biggest difference in speed was in PHP4 but was optimised in PHP5. in a loop of 10,000 the difference was 0.03 seconds EDIT: that's $url = 'http://www.site.com/soccer/'.$_GET['league']; winning by 0.03 seconds
-
Well the logic your using seams long winded and has pointless code! why your passing it to w3.org seams a little weird! a simple download html and extract is all that's needed,
-
add ][ to the time Nice RegEx Cags
-
I find that if i start with this $url = 'http://www.site.com/soccer/'.$_GET['league']; this takes me longer $Domin = "site.com"; $Section = "soccer"; $url = 'http://www.'.$Domin.'/'.$Section.'/'.$_GET['league']; than if i start with this $url = "http://www.site.com/soccer/{$_GET['league']}"; and update do this $Domin = "site.com"; $Section = "soccer"; $url = "http://www.$Domin/$Section/{$_GET['league']}"; //or $url = "http://www.{$Domin}/{$Section}/{$_GET['league']}"; and I find it slightly easier to read! but with any micro optimization it normally depends on the personal preference. My Logic is simple, if its a hundredth of a second faster at run time but takes 2 seconds longer to read a design time I'll probably not worry about the hundredth of a second.
-
Its very slightly fast 100th of a second but IMHO I find Nightslyr solution cleaner as I find it quicker to update later (that saves me a little longer that a 100th of a second
-
And how exactly do that get the seconds ? my extension of oni-kun code seams more practical, and while it make be necessary to use cURL thats a simple change
-
Indeed, anything we try say is going to be guess work but I added a pre-filter, this may not be the best route but its workable! <?php $SQL = "SELECT col1, col2, col3,col4 , IFNULL(blah, 'foo') AS foolah, foo AS bar1, COUNT(foo) AS bar2 FROM table WHERE col1='A';"; if (preg_match('/SELECT (.*?) FROM /i', $SQL, $regs)) { $regs[1] = preFilter($regs[1]); $result = explode(",",$regs[1]); $result = array_map('fieldFilter', $result); } var_dump($result); function fieldFilter($str){ //filter out spaces and back ticks $str = trim($str," `"); //filter out AS $str = preg_replace('/^.*as\s+/i', '', $str); //etc return $str; } function preFilter($str){ //filter out any () contents $str = preg_replace('/\(.*?\)/i', '', $str); //etc return $str; }
-
your welcome If solved please click topic solved (bottom left)
-
Your see the HOST, servers time, This is because PHP is server based, for the clients time you can use javascript, BUT you can change the timezones on PHP date_default_timezone_set('America/Los_Angeles');
-
Valid Point If so I would use the same logic but create a function called fieldFilter $result = array_map('fieldFilter', $result); function fieldFilter($str){ $str = trim($str); //filter AS //Filter backticks //etc return $str; }
-
Unless they have 2 spaces! but you can't just replace the spaces, cleaner solution would be <?php $SQL = "SELECT col1, col2, col3,col4 FROM table WHERE col1='A';"; if (preg_match('/SELECT (.*?) FROM /i', $SQL, $regs)) { $result = explode(",",$regs[1]); $result = array_map('trim', $result); } var_dump($result); But I'm too lazy to type it D'oh!
-
You may want to echo the value if it does exists! ie Name: <input type="text" name="name" value="<?php if (!isset($_POST['name'])){echo 'Default';}else{echo $_POST['name'];} ?>" />
-
Try this <?php $SQL = "SELECT col1, col2, col3 FROM table WHERE col1='A';"; if (preg_match('/SELECT (.*?) FROM /i', $SQL, $regs)) { //extracts the col1, col2, col3 $result = explode(",",str_replace(", ",",",$regs[1])); //changes ", " to "," (without the quotes) and puts into array } var_dump($result);//display array details EDIT: added commented
-
Example (expanded from oni-kun) <?php $query = "php"; preg_match('%\(<b>([^<]*)</b> seconds\)%i',file_get_contents("http://www.google.com/search?q=".urlencode($query)),$found); echo $found[1];
-
problem with inserting data in mysql using php
MadTechie replied to Rahmi's topic in PHP Coding Help
Yeah i am having difficulty seeing the problem as well! would you mind showing the code, that has the problem! -
Well the first thing I would do, would be fetch from the database, as your not pulling out the data <?php date_default_timezone_set('Asia/Kolkata'); $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'labview'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'phpscheduleit'; mysql_select_db($dbname,$conn) or die ("could not open db".mysql_error()); //$start_date = 1259865000; //$starttime = 900; //$endtime = 960; // Make timestamp for today's date $dv = array(); $today = getdate(); $dv['month'] = $today['mon']; $dv['day'] = $today['mday']; $dv['year'] = $today['year']; $default = true; $dv['todayTs'] = mktime(0,0,0, $dv['month'], $dv['day'], $dv['year']); $Tdate = date('H') * 60 + date('i'); $userId = $_POST['resid1']; $sql = "SELECT resid, start_date, starttime, endtime FROM reservations WHERE resid = '$userId'"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); //Fetch Data and use $row to get fields data if ($dv['todayTs'] == $row['start_date']){ if($Tdate >= $row['starttime'] && $Tdate < $row['endtime']) { echo "www.localhost/e1.html(user should navigate to this page)"; } else { echo "This is not your time slot"; } }else { echo "Your slot is booked for some other day"; } }else{ echo "Wrong Reservation id"; } ?>
-
Could somebody please explain this drop down driven page to me?
MadTechie replied to spenceddd's topic in PHP Coding Help
As a note theirs a comment in the form (as its easy to miss) <!-- THIS IS ALSO A COMMENT Simple Javascript that checks a value form the drop down has been selected --> -
Three Dependent Drop down Boxes with Data from Mysql Database
MadTechie replied to surajkandukuri's topic in PHP Coding Help
May help Dynamic DropDown PHP/AJAX (its a bit dated now) -
Erm.. 5Gb upload.. FTP seam the better route, or some client side scripts like flash or java, in any case that's going to take ages for any standard home user to upload! a quicker route would be to give a DVD to a delivery company or carrier pigeon !!
-
Could somebody please explain this drop down driven page to me?
MadTechie replied to spenceddd's topic in PHP Coding Help
NO... Okay read the comments <?php //error_reporting(E_ALL); require_once('db.php'); ?> <?php /** * 1. Query the database and get the ID and attend FROM the table seminar */ mysql_select_db($database_db, $db); $query_seminars = "SELECT id, attend FROM seminar"; $seminars = mysql_query($query_seminars, $db) or die(mysql_error()); $row_seminars = mysql_fetch_assoc($seminars); $totalRows_seminars = mysql_num_rows($seminars); /** * 2. If the form was submitted then get the ID from the attend text box * This is used for the form location, from and leadership */ $colname_chosen_seminar = "-1"; if (isset($_POST['attend'])) { $colname_chosen_seminar = (get_magic_quotes_gpc()) ? $_POST['attend'] : addslashes($_POST['attend']); } mysql_select_db($database_db, $db); $query_chosen_seminar = sprintf("SELECT * FROM seminar WHERE id = %s", $colname_chosen_seminar); $chosen_seminar = mysql_query($query_chosen_seminar, $db) or die(mysql_error()); $row_chosen_seminar = mysql_fetch_assoc($chosen_seminar); $totalRows_chosen_seminar = mysql_num_rows($chosen_seminar); /** * Display form */ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <script type="text/javascript"> <!-- THIS IS ALSO A COMMENT Simple Javascript that checks a value form the drop down has been selected --> function chkFrm(el){ if(el.selectedIndex == 0){ alert("Please choose an option"); return false } else{ el.form.submit(); } } </script> </head> <body> <form name="form1" method="post" action=""> <p> <select name="attend" onchange="chkFrm(this)"> <option value="Choose" <?php if (!(strcmp("Choose", $_POST['attend']))) {echo "SELECTED";} ?>>Choose Seminar</option> <?php /** * Loop thought the records found in 1., to build the drop down list for the attend's, Value = the attend ID while ie displays the field attend * if the last posted the same attend ID then that will the selected one in the list */ do { ?> <option value="<?php echo $row_seminars['id']?>"<?php if (!(strcmp($row_seminars['id'], $_POST['attend']))) {echo "SELECTED";} ?>><?php echo $row_seminars['attend']?></option> <?php } while ($row_seminars = mysql_fetch_assoc($seminars)); $rows = mysql_num_rows($seminars); if($rows > 0) { mysql_data_seek($seminars, 0); $row_seminars = mysql_fetch_assoc($seminars); } ?> </select> </p> <p>Location <input name="textfield" type="text" value="<?php echo $row_chosen_seminar['location']; ?>"> <br> From <input name="textfield" type="text" value="<?php echo $row_chosen_seminar['from']; ?>"> <br> Leader <input name="textfield" type="text" value="<?php echo $row_chosen_seminar['leadership']; ?>"> </p> </form> </body> </html> <?php mysql_free_result($seminars); mysql_free_result($chosen_seminar); ?> -
LOL, love that! Well the use of a class doesn't mean its OOP for example, would you call this OOP ? <?php class test1{ var $user = ""; var $pass = ""; function login($user, $pass){ $this->user = $user; $this->pass = $pass; if("MadTechie" == $this->pass){ echo $this->user." Logged in"; }else{ echo $this->user." NOT Logged in"; } } } $test = new test1; $test->login("John","MadTechie");