|
|
Cheers, will look at the possibilities.
So, when you have to program a PHP web app by your own, do you hand code all patterns needed to control objects between each others? Like controlling FKs between relations.
|
|
|
|
|
yes I hand code it, including table/data relations. But I have what I guess would be a custom pattern I have developed over the years and find it able to adjust and handle any web/app I can toss at it while still being readable and flexible.
Chris J
www.redash.org
|
|
|
|
|
|
Hey CodeProject!
So I'm trying to make a query in PHP and mySQL..
One of the database tables has a value I want to SELECT DISTINCT while selecting everything else regularly with an asterisk (*).
Example:
<br />
<br />
$model_select = "select DISTINCT model FROM models where shw=1 ORDER BY modelid";<br />
$model_select = "select * FROM models where shw=1 ORDER BY modelid";<br />
<br />
Is there a way I can do both DISTINCT and * in the same query command? Or is there a way around this without making 2 queries?
It would be great if I could 'cause I'm using the mysql_fetch_array thing.
Thanks.
-Paul
|
|
|
|
|
I don't know, however I think it can't be done because the results would be undefined.
Assume the MODELS table holds the following data:
field1 field2
1 2
1 3
1 4
5 6
7 8
7 9
If you do "SELECT DISTINCT field1 FROM MODELS" you would get 1, 5, and 7.
Now there are three rows with field1=1, which field2 value should contribute to the result?
Assuming "SELECT field2, DISTINCT(field1) FROM MODELS" would be accepted, the field2 values would be unpredictable, i.e. the query is ambiguous.
Things would make more sense if you would need, and were allowed to do, the following:
"SELECT MAX(field2), DISTINCT(field1) FROM MODELS"
PS: this isn't a PHP question, it is a database related question, the MySQL forum would have been a better choice.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I think you can use
select distinct * from tablename where col='mycondition'
or you may select only required columns, if you get unexpected rows
select distinct model,col1,col2,col2 from tablename where col='mycondition'
|
|
|
|
|
A sub-select with a GROUP_CONCAT should do it....although I have not test this query.
select GROUP_CONCAT((select DISTINCT model FROM models where shw=1 ORDER BY modelid)) as mod_name, * FROM models where shw=1 ORDER BY modelid
this would return the subselect as a comma seperated value on each row by a column named "mod_name".
I would advise that you do not use the "*" in the other query as this forces mysql to do a secondary query to find and return the column names for the table models, it is better to just set them in the query to improve performance.
Chris J
www.redash.org
|
|
|
|
|
Hi All,
<?php
echo "Hello World";
?>
This index.php is not outputting anything to the browser but I can copy this file to another computer and it works as expected. Also, on the problem machine phpinfo() works fine and displays everything you'd expect.
I'm running Ubuntu 11.04 32-bit, Apache 2.2.17, and PHP 5.3.5-1. I'm guessing there must be something wrong with the php configuration but I haven't a clue as to what that might be. I've also tried print() as well and get the same results.
Suggestions?
Thanks much for any help...
|
|
|
|
|
First, I would check that the page is actually blank, and not just serving the PHP as HTML.
The next thing I would check is the file permissions.
After that I would take a look at the server log to see if there are any errors reported there.
Next, I would make sure display_errors and error_reporting are turned on and insert an error into the page to make sure it is actually being executed.
|
|
|
|
|
Thanks,
display_errors help a lot. I had a parsing error. I wasn't able to see it in nano but when I erased it and re-typed the line, it worked fine.
|
|
|
|
|
Hi, I am new to PHP. I am currently working on CRM project, I need to keep track of email status and update into my database such as who read the email or who opened?, who deleted?, who replied? and also When was the email opened/deleted/replied? Date and time. is there any possible to track if someone has read the email or hasn't which I have sent the email to them?
|
|
|
|
|
And you are what, writing the mail client then. No mail client will ever sent you a notification upon deletion, reading or reply.
You could try a redirect under each and every link in the e-mail, or possibly the images used in the e-mail. And you could track the hits this redirect page gets. This would give you a somewhat decent overview of how many people open / read. But again delete is a lot harder if not impossible to track.
|
|
|
|
|
thanks for your reply, I used images with my message content, I got read status. but I need delete status. First of all I want to know is it possible to track for delete? if yes is there a way to find out if someone delete the email which i have been sent?
|
|
|
|
|
If my memory serves IMAP has some features for this but your code has to manage this. If the user can connect to the email via an outside email program, outlook for example, then I do not think you can do anything about it.
You may look at your email server, the actual software that manages the email, and see if it has any kind of user logging features.
try read this in the php manual http://php.net/manual/en/function.imap-delete.php[^]
Chris J
www.redash.org
|
|
|
|
|
Dear,
I am a self learner, i wanted to know " How to browse a .php file and which compiler is used to compile?
|
|
|
|
|
If your PHP files are related to web sites, you can use a web server that supports PHP. Xampp[^] would be one example; it will interpret the required PHP files on the spot; it can also be used to just compile-and-run a PHP file, as PHP is a general programming language, not necessarily linked to web stuff. You'd have to look the details up in the manual of your PHP system.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hey Friends
I got a XP Machine, Active Perl Installed, Symbian SDK 0.9 installed & Carbide C++ installed & creating new symbian project.
When i compile the project, i get the error BLDMAKE ERROR: Can't find any RVCT installation.
Any idea what is that ? & how to fix it?
Regards
|
|
|
|
|
|
hello guys... I have an html page inwhich I collect some data using text boxes. Now in this page, I have button and I set the action attribute of <form> a php script like this
<form action="test.php" method="post">
-----
Now this does the job. But the problem is that I dont want to be redirected and want to stay on the same page but at the same time want to execute the test.php script. How can I do that? thnx
|
|
|
|
|
You can do that with an ajax call.
I.e create an HttpWebRequest object, ask for test.php and then display the results on your (already loaded & displayed) page.
I'll see if I can't fish out some old code I have lying about somewhere.
|
|
|
|
|
Perhaps it's your lucky day!
Couldn't find the old code that I had in mind, so quickly hacked something together that should demonstrate the principle for you.
Also helped improve my own code in the process of ensuring that this code would be pretty easy to re-use. The submitForm function is fresh off my neurons and axioms - wish I'd thought of doing that when I last coded in php.
You'll need to download AjaxRequest.js - I've not included it in this post due to it's size. (AjaxRequest[^)
Though everything else you need is here.
Apologies for the total lack of error handling, and the Mickey Mouse test.php. It should however be more than enough to demonstrate my approach. I'd be interested in seeing what devoutees of jQuery think (yeah, I know it's already written, but it's about 18 times the size of code performs the functionality that I need)
=================================
File #1, index.php
=================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript" src="ajaxRequestCompressed2.js"></script>
<script type="text/javascript">
function byId(el){return document.getElementById(el)}
function myGetAjaxResponse(target, url)
{
AjaxRequest.get(
{
'url':url,
'onSuccess':function(req){ target.innerHTML=req.responseText; }
}
);
}
function submitForm(formIdString, targetPhpFileString, pageTgtContainerIdString)
{
var theForm, curItem, url;
theForm = byId(formIdString);
for (curItem = 0; curItem<theForm.length; curItem++)
{
if (curItem == 0)
url = targetPhpFileString + "?";
else
url = url + "&";
url = url + theForm.elements[curItem].id + "=" + theForm.elements[curItem].value;
}
myGetAjaxResponse(byId(pageTgtContainerIdString), url)
}
</script>
</head>
<body>
<h1>Welcome to my CP test!</h1>
<form id="form1" name="form1">
<label>First Name<input id="firstName"/></label>
<label>Last Name<input id="lastName"/></label>
<input type=button onclick="submitForm('form1', 'test.php', 'ajaxTarget')" value="SubmitMe"/>
</form>
<div id="ajaxTarget"> </div>
</body>
</html>
=================================
File #2: test.php
=================================
<?php
$firstName = $_GET["firstName"];
$lastName = $_GET["lastName"];
printf("%s, %s<br>", $lastName, $firstName);
?>
|
|
|
|
|
Hello, guys!
I am a newbie in web building, but I want to make my personal web site by myself. I want to embed there a php login form, but it is difficult for me to write the correct code. I surfed the internet and found a program that builds any form you want. It is called php forms (http://phpforms.net/). But I don't know whether to try it or not.
Has anybody worked with this software? What would you suggest me to do?
Life is too short to be small
|
|
|
|
|
Hi,
I have a form that I am creating for my website, and its for people to use if they find a butterfly or moth and cannot identify it. Basically what I want is for the user to fill in the form and if they have an image to send, select an image and send the message. Code I have:
<form action="mailer.php" method="post" name="form1" id="form1" style="margin:0px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:300px;" onsubmit="MM_validateForm('from','','RisEmail','subject','','R','verif_box','','R','message','','R');return document.MM_returnValue"><br />
<br />
Your Name:<br /><br />
<input name="name" type="text" id="name" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['name'];?>"/><br />
<br /><br />
<br /><br />
<br />
Your e-mail:<br /><br />
<input name="from" type="text" id="from" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['from'];?>"/><br />
<br /><br />
<br /><br />
<br />
Stage:<br /><br />
<select name="stage"><br />
<option value="Caterpillar">Caterpillar</option><br />
<option value="Pupa">Pupa</option><br />
<option value="Cocoon">Cocoon</option><br />
<option value="Adult">Cocoon</option><br />
<option value="Leaf Mine">Leaf Mine</option><br />
<option value="Leaf Mine Vaccated">Leaf Mine (Vaccated)</option><br />
</select><br /><br />
<br /><br />
Method:<br /><br />
<select name="method"><br />
<option value="UV Light Trap">UV Light Trap</option><br />
<option value="MV Lamp">Mercury Vapour Lamp</option><br />
<option value="Tungsten Light">Tungsten Light</option><br />
<option value="Actinic Light">Actinic light</option><br />
<option value="Household Bulb">Household Bulb</option><br />
<option value="Camping Lamp">Camping Lamp</option><br />
<option value="Infrared">Infrared Light</option><br />
<option value="LED Lights">LED Lights</option><br />
<option value="Carlights">Car Headlights</option><br />
<option value="Lighted Window">Attracted to Lighted Window</option><br />
<option value="Streetlight">At street light</option><br />
<option value="Security light">At security light</option><br />
<option value="Torch">Found via torchlight</option><br />
<option value="Dead Road">Found dead on road</option><br />
<option value="Spider Web">Found in Spider Web</option><br />
<option value="Nighttime">Night time observation</option><br />
<option value="Daytime">Daytime Observation</option><br />
<option value="Hibernating">In Hibernation</option><br />
<option value="Beaten">Beaten from vegetation</option><br />
<option value="Dusking">Found while dusking</option><br />
<option value="Netted">Netted</option><br />
<option value="Birdseed">Found in Bird Seed Bag</option><br />
<option value="Fruit/Veg">Found inside a fruit or vegetable</option><br />
<option value="Pheromone">Attracted via pheramone lures</option><br />
<option value="Feeding signs">Feeding signs</option><br />
<option value="Fish">Found inside a fish</option><br />
<option value="Indoors">Found Indoors</option><br />
<option value="Tree trunk">Found on Tree Trunk</option><br />
<option value="Wall">Found on Wall</option><br />
<option value="Other">Other Method</option><br />
</select><br /><br />
<br /><br />
Country:<br /><br />
<input name="country" type="text" id="country" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['subject'];?>"/><br />
<br /><br />
<br /><br />
Town/City:<br /><br />
<input name="town/city" type="text" id="town/city" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['subject'];?>"/><br />
<br /><br />
<br /><br />
Habitat:<br /><br />
<input name="Habitat" type="text" id="Habitat" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['subject'];?>"/><br />
<br /><br />
<br /><br />
Habitat Information:<br /><br />
<br /><br />
<textarea name="Habitat Information" cols="6" rows="5" id="HabitatInformation" style="padding:2px; border:1px solid #CCCCCC; width:300px; height:100px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"><?php echo $_GET['message'];?></textarea> <br />
<br />
<br /><br />
<br /><br />
If you have an image, select it here (JPEG image, max 5MB):<br />
<input type="file" name="datafile" size="40"><br /><br />
<br /><br />
<br />
Type verification image:<br /><br />
<input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"/><br />
<img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /><br /><br />
<br /><br />
<br />
<!-- if the variable "wrong_code" is sent from previous page then display the error field --><br />
<?php if(isset($_GET['wrong_code'])){?><br />
<div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;">Wrong verification code</div><br /> <br />
<?php ;}?><br />
<br />
Additional Information:<br /><br />
<br /><br />
<textarea name="message" cols="6" rows="5" id="message" style="padding:2px; border:1px solid #CCCCCC; width:300px; height:100px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"><?php echo $_GET['message'];?></textarea> <br />
<br />
<input name="Submit" type="submit" style="margin-top:10px; display:block; border:1px solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;" value="Send Message"/><br />
</form>
What I want is a way to make sure the user has filled in all fields (except the file input field) before sending, to make sure when they press send message, it sends with information on it. Second I want when the user uses the file input to upload a file, it has to be a JPEG with a max size of 5MB. Anyone know how I would do this?
In the end we're all just the same
|
|
|
|
|
Briefly, you will need to add a scrap of javascript to your page. In your <form ... > add something like
onsubmit="return check_fields()"
Somewhere in your page (I put it in the head section) put something like
<script type="text/javascript">
function check_fields() {
if (document.getElementById("xxx").checked || document.getElementById("yyy").checked)
return true;
alert("You must select either xxx or yyy!");
return false;
}
</script>
The function should return true if it's OK to submit. If there's something wrong, spit out an alert to say what the problem is, and return false so the form won't actually be submitted. Obviously, your checking will be more complex than this example which I ripped out of one of my sites.
Cheers,
Peter
If this answers your question, vote for it.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|