Brian W
-
Posts
867 -
Joined
-
Last visited
Posts posted by Brian W
-
-
I need to get the date of last Friday, unless today is Friday in which case get today's date, as a column value. Can't seem to get a grasp on the STR_TO_DATE function or I'm barking up the tree entirely.
SELECT STR_TO_DATE('Friday','%W %M %Y') as `Date` FROMAny help is appreciated. Thanks
I wish I could use php to make this date, to bad in this situation I have to some how pass the date already correct.
-
kickstart, that idea didn't work. It seems to me that whatever is inside the sub-query can't be used in the sup-query's WHERE clause.
I have given the user the option to hide "projects" in which no tasks are open.
How can I use HAVING? I need to not return the project if there are no tasks.
Before I began using the subquery, I was using a LEFT JOIN with the project table on the left but it would not return projects that had no tasks, it needs to be an optional filter.
Thanks guys
-
I aliased the results of a subquery and need to tell the query to use the resulting value in the WHERE clause.
MySQL Error: Unknown column 'Tasks' in 'where clause'
SELECTp.project, p.id as pid, p.acronym, p.Client as cid, c.client,
(SELECT COUNT(t.Task) FROM tasks t WHERE t.pid = p.id GROUP BY t.pid) as Tasks
FROM projects p
LEFT JOIN clients c ON p.Client = c.id
WHERE
Tasks > 0
ORDER BY project ASC
-
Thanks all for the help!
I had trouble looping and getting the fields when they were in a table, so I did some research and found this page which gave me the idea to use elements rather than childNodes. Here is my final product (which also supports textarea elements).
var http_request = false; function makePOSTRequest(url, parameters) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type //http_request.overrideMimeType('text/xml'); http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; http_request.open('POST', url, true); http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.setRequestHeader("Content-length", parameters.length); http_request.setRequestHeader("Connection", "close"); http_request.send(parameters); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { //alert(http_request.responseText); result = http_request.responseText; //success code open_popup(result, true); } else { alert('There was a problem with the request.'); } } } function get(form, url) { var obj = document.getElementById(form); read_form(obj); makePOSTRequest(url, getstr); getstr = ""; } var getstr = ""; function read_form(obj){ if(obj.elements.length <= 0){ return false; } for (i=0; i<obj.elements.length; i++) { if (obj.elements[i].tagName == "INPUT") { if (obj.elements[i].type == "text") { getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&"; } if (obj.elements[i].type == "checkbox") { if (obj.elements[i].checked) { getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&"; } else { getstr += obj.elements[i].name + "=&"; } } if (obj.elements[i].type == "radio") { if (obj.elements[i].checked) { getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&"; } } } else if (obj.elements[i].tagName == "SELECT") { var sel = obj.elements[i]; getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&"; } else if (obj.elements[i].tagName == "TEXTAREA") { getstr += obj.elements[i].name + "=" + escape( encodeURI(obj.elements[i].value) ) + "&"; } else { alert(obj.elements[i].tagName); } } return getstr; }
You'll need to run php urldecode() on the $_POST variables especially if they have a line-carriage in the value.
-
I'll need to build the qstring with that technique too, but the parameters are grabbed using the $_POST. I hardly see the point. Any ways, like I outlined before, I need to pass the values of some textareas in the form that likely will have line-carriages in it that aren't respected when your building a qstring.
Maybe my question should be, how can I use AJAX to submit a form and respect the line-carriages in a textarea field?
-
FORM METHOD=POST is what I want to simulate but use AJAX to post the data without reloading the entire page.
-
I'm finding several scripts that all send a request with a query string, but I want to send one using POST since I'm posting several textareas with line carriages and also I think their content is too long for a query string. Any suggestions, links, leads would be helpful.
Thanks
-
mis-communication the entire way... lol
arneman, does it do what you want now? if so, PFMaBiSmAd, no worries.
-
<?php $page = pathinfo($_SERVER['PHP_SELF'],PATHINFO_FILENAME);//get the file name of the current page if($page == "index"){ //it neglects the extension, so hope you don't use index.html too echo "Footer HTML you want to show"; } ?>
-
unless your emo, harmless. lol
I'm not sure of the performance related to using eval or other possible issues, I just know generally it's not a favored technique.
Best,
Brian
-
well, if your trying to output the code (w/o highlight), you need to use htmlentities() on the result. If you want the php being returned in the result to process as php, your need to use eval().
WARNING: eval() will allow several attacks on your site if you allow user submitted data to pass through it. For example, some one inputs
<?php print_r($_SESSION); ?>
or other sensitive data is echoed out to the end user.
-
Sorry, got playing with it, it won't work...
Retry:
<?php echo "<table width=\"100%\">\n<tr>\n"; $r=0; $c=0; while ($row = mysql_fetch_assoc($result)) { $name = $row['first_name']; $last_name = $row['last_name']; $title = $row['title']; $office = $row['office']; $lab = $row['lab']; $officeTel = $row['office_phone']; $labTel = $row['lab_phone']; $url = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $row['url']); $email = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href="mailto:\\1">\\1</a>', $row['email']); $title = $row['title']; if($c==1){ $c=0; echo "</tr>\n<tr>"; } echo "<td><table> <tr> <td><b>$last_name, $name</b></td> <td>Office/Lab $office, $lab</td> <td>Office/Lab Tel # $officeTel, $labTel</td> <td>Email: <a href='mailto:$email@cornell.edu'>$email@cornell.edu</a></td> </tr> </table></td>"; $c++; } echo "</tr></table>"; ?>
-
I believe that that is saying that $videos['category'] is not set. Not just empty, but hasn't been defined at all.
Try:
$cat = (is_set($videos['category'])) ? $videos['category'] : "NULL"; echo "<a href='www.aaa.co.uk/Newdirectory/video.php?category=".$cat ."'>".$cat ."</a>";
mjdamato, whats the problem, do explain...
-
if you go to view source what do you get? Or if you have FF w/ Firebug, when you inspect the element what do you get?
-
hmm, line 64 was the issue... use the code I posted before:
echo "<a href='www.aaa.co.uk/Newdirectory/video.php?category=".$videos['category']."'>".$videos['category']."</a>";
-
whats line 63-65, line 64 checks out as far as I can tell. You could try this just to be sure it gets parsed as expected (not that it should have any issues as is):
echo "<a href='www.aa.co.uk/Newdirectory/video.php?category=".$videos['category']."'>".$videos['category']."</a>";
-
Try this:
<?php $i=0; while ($row = mysql_fetch_assoc($result)) { $name = $row['first_name']; $last_name = $row['last_name']; $title = $row['title']; $office = $row['office']; $lab = $row['lab']; $officeTel = $row['office_phone']; $labTel = $row['lab_phone']; $url = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $row['url']); $email = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href="mailto:\\1">\\1</a>', $row['email']); $title = $row['title']; $align = ($i%2) ? "right" : "left"; //switch right and left for odds and evens. Starts on Left echo "<table width=\"49%\" align=\"$align\"> <tr> <td><b>$last_name, $name</b></td> <td>Office/Lab $office, $lab</td> <td>Office/Lab Tel # $officeTel, $labTel</td> <td>Email: <a href='mailto:$email@cornell.edu'>$email@cornell.edu</a></td> </tr> </table>"; $i++;//Incriment i } ?>
-
Of course when they sign up, they will need to select the question they want to use and they will need to answer it.
The questions should be stored in a table in your db with a PRIMARY_KEY you can reference to.
The answer should be stored with the user's data and also the reference key to the question used.
To pull the question again for them to answer (in order to get their password), something like this
SELECT q.question, u.id
FROM users u
LEFT JOIN questions q
ON u.question = q.id
WHERE u.email = '$email'
That should return their question and their user id so that you can send the answer for form processing and compare it to their answer in the db. Note: Remember to note make the answers case sensitive.
Now, you also don't want to output their password right there, that would be a security risk, Email the user their password. Pretty much any one I know knows where I grew up, what my first school was, what my mothers maiden name is, ect. These questions are only a buffer from basic attacks.
-
mysql_num_rows() not mysql_affected_rows when you're selecting data.
Good catch
-
The method I use for this may be easier.
MD5 the password when they enter it the first time, store the hashed value of their password. When they go to sign in and type in the password, MD5 their input and use it in the SELECT statement.
Example (dirty):
<?php $Pass = "test"; $hashed = md5($Pass); //INSERT INTO users ...... , '$hashed'); //Now for when they signing $_POST['password'] = "test"; $hashed = md5($_POST['password']); //SELECT FROM users WHERE username='$username' AND password='$hashed' if(mysql_num_rows($query) == 1){ //signin } else { //fail } ?>
-
no body has any ideas?
-
This is probably a simple issue, but can't seem to figure it out...
When I watermark the image, everything is fine besides the transparency on the watermark is black rather than clear.
<?php function ratio($x, $y, $max){ if($x > $y){ if($x > $max){ $y = round(($y*$max)/$x); $x = $max; } } else { if($y > $max){ $x = round(($x*$max)/$y); $y = $max; } } return array($x, $y); } function upload_image($img){ global $time; $time = time(); if(!isset($img['type'])){ return "ERROR: invalid image upload"; } if($img['type'] != "image/jpg" && $img['type'] != "image/jpeg" && $img['type'] != "image/pjpeg"){ return "ERROR: file must be a JPEG or JPG.".$img['type']; } $src = $img['tmp_name'];//Temp File $temp = imagecreatefromjpeg($src) or die("ERRO on temp"); list($ox, $oy) = getimagesize($src); $large_max = 500; $small_max = 160; list($lx, $ly) = ratio($ox, $oy, $large_max); list($sx, $sy) = ratio($ox, $oy, $small_max); list($wx, $wy) = ratio(400, 80, $lx); $wpx = round($lx - $wx)/2; $wpy = round($ly - $wy)/2; // Watermark XY Positions //die((string)$wpy); $water_mark_src = imagecreatefrompng(ROOT."\\uploads\\watermark.png"); $water_mark = imagecreatetruecolor($wx, $wy); imagecopyresampled($water_mark, $water_mark_src, 0, 0, 0, 0, $wx, $wy, 400, 80); $large = imagecreatetruecolor($lx, $ly); imagecopyresampled($large, $temp, 0, 0, 0, 0, $lx, $ly, $ox, $oy); imagecopymerge($large, $water_mark, $wpx, $wpy, 0, 0, $wx, $wy, 20) or die("here");//Overlay Watermark imagejpeg($large, ROOT."\\uploads\\large\\".$time.".jpg", 100); $small = imagecreatetruecolor($sx, $sy); imagecopyresampled($small, $temp, 0, 0, 0, 0, $sx, $sy, $ox, $oy); imagejpeg($small, ROOT."\\uploads\\small\\".$time.".jpg", 100); //return "$wx $wy"; return true; } ?>
[attachment deleted by admin]
-
Hey, that makes since...
So basically I pass the already created object to the next class and then to the next class and then to the next class... simply stacking them.
Problem though, the variables become static...
if(true){ // for testing $epm->user = new user; $epm->auth = new auth($epm->user); $epm->id = 2; echo $epm->auth->id;
returns 1, not 2.
I think I'm going to take a different rout on this and just pass the variables around outside the classes themselves. Not as pretty, doesn't seem right to me, but it will work.
-
I've made no progress in the past hour messing with it more. in the OOP vs not OOP battle for php, I think OOP looses out in my book unless someone can help me to understand how to get the classes to use variables and methods from other classes.
[SOLVED] Getting the right date
in MySQL Help
Posted
hmm, interesting idea. I like it, but it doesn't work.
the - 7 gets whatever today is - 7 days (same day of the week).
I can use some conditional statements if I can figure out how do do something like
if the day was monday (2), it would work like
7(days in week) - 2 (monday) = 5
2(today) - 5 = - 3
NOW() + -3 = 3 days ago which from Monday is Friday I think