Re: [PHP] newbie php/mysql need help
p80 wrote: I do a mysql request like this one: SELECT DISTINCT (brand), COUNT( brand )FROM `machines` where category like 'sold' group by brand" Try adding aliases to your query, such as : SELECT DISTINCT (brand), COUNT (brand) AS brand_count FROM `machines` WHERE `category` LIKE 'sold' GROUP BY `brand` Then, you can echo the result thusly: while($row = mysql_fetch_assoc($result)) { echo $row['brand']; echo $row['brand_count']; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] newbie php/mysql need help
Simple but should work. $query = " SELECT DISTINCT (brand), COUNT( brand )FROM `machines` where category like 'sold' group by brand;"; $result = mysql_query($query) or die(mysql_error()); While($data = mysql_fetch_array($result)) { echo "{$data[0]} - {$data[1]}\n"; } -Original Message- From: p80 [mailto:[EMAIL PROTECTED] Sent: Sunday, March 13, 2005 4:35 PM To: php-general@lists.php.net Subject: [PHP] newbie php/mysql need help I do a mysql request like this one: SELECT DISTINCT (brand), COUNT( brand )FROM `machines` where category like 'sold' group by brand" I get this from mysql: brand COUNT( brand) brandx4 brandy12 how can I echo this result in php? thanx in advance Pat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] newbie php/mysql need help
I do a mysql request like this one: SELECT DISTINCT (brand), COUNT( brand )FROM `machines` where category like 'sold' group by brand" I get this from mysql: brand COUNT( brand) brandx4 brandy12 how can I echo this result in php? thanx in advance Pat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Newbie: PHP/MySQL (SELECT)
if one of $titulotxt or $cdstxt is not set, your query will look something like this: SELECT * FROM divx WHERE && cds like '$cdstxt' ORDER BY titulo As you see, there is unnecessery &&. I build my search queries using this form: $query_cond=''; foreach($_GET as $col => $val) { switch($col) { case 'cds': // you can add more cases here for conditions that need to be exact $query_cond .= " $col LIKE '$val' AND "; break; case 'titulo': // you can add more cases here for conditions that need not to be exact $query_cond .= " $col LIKE '%$val%' AND "; break; } } // get rid of final AND $query_cond = substr($query_cond, 0, strlen($query_cond) - 4); // and as you don't have any other conditions, $query_cond cannot be empty - we would have excessive WHERE // so if it is empty, make it 1 if($query_cond=='') $query_cond='1'; $sql="SELECT * FROM divx WHERE $query_cond ORDER BY titulo"; Mr. BuNgL3 wrote: Hi... I'm with a little sintax problem... The question is that i have two search fields (titulotxt and cdstxt) and i want to create an mysql condition... i trying: $sql1=($titulotxt) ? "titulo like '%".$titulotxt."%'":""; $sql2=($cdstxt) ? "cds like '$cdstxt'":""; $sql="SELECT * FROM divx WHERE" .$sql1 " && " .$sql2 " ORDER BY titulo"; but he's giving me a sintax error on the 3 line... Can anyone teach me how i must do to validate the mysql condition and make it work? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Newbie: php/mysql (Select)
At 20:23 20.11.2002, Mr. BuNgL3 said: [snip] >Hi... >I'm with a little sintax problem... >The question is that i have two search fields (titulotxt and cdstxt) and i >want to create an mysql condition... i trying: > > $sql1=($titulotxt) ? "titulo like '%".$titulotxt."%'":""; > $sql2=($cdstxt) ? "cds like '$cdstxt'":""; > $sql="SELECT * FROM divx WHERE" .$sql1 " && " .$sql2 " ORDER BY titulo"; > >but the bastard is giving me a sintax error on the 3 line... Can anyone >teach me how i must do to validate the mysql condition and make it work? [snip] As already said, put a space after the WHERE clause. What happens if $sql1 or $sql2 are empty (as your example provisons)? Create an $sql3 that combines $sql1 and $sql2, and construct your SQL accordingly: $sql1 = ($titulotxt ? null : "titulo like '%$titulotxt%'"); $sql2 = ($cdstxt? null : "cds like '$cdstxt'"); $sql3 = $sql1 . ($sql1 && $sql2 ? ' AND ' : null) . $sql2; $sql = 'SELECT * FROM divx ' . ($sql3 ? "WHERE $sql3 " : null) . 'ORDER BY titulo'; -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: PHP/MySQL (SELECT)
$sql1 = "titulo like '%$titulotxt%'" $sql2 = "cd like '$cdstxt'"; $sql = "SELECT * FROM divx WHERE $sql1 AND $sql2 ORDER BY titulo"; I think you are getting the error because of the ($titulotxt) ? portion of your sql statements. You really only need the two statements listed above and then put into your actual sql statement. Robbert van Andel -Original Message- From: Mr. BuNgL3 [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 20, 2002 11:54 AM To: [EMAIL PROTECTED] Subject: [PHP] Newbie: PHP/MySQL (SELECT) Hi... I'm with a little sintax problem... The question is that i have two search fields (titulotxt and cdstxt) and i want to create an mysql condition... i trying: $sql1=($titulotxt) ? "titulo like '%".$titulotxt."%'":""; $sql2=($cdstxt) ? "cds like '$cdstxt'":""; $sql="SELECT * FROM divx WHERE" .$sql1 " && " .$sql2 " ORDER BY titulo"; but he's giving me a sintax error on the 3 line... Can anyone teach me how i must do to validate the mysql condition and make it work? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php "The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers."
Re: [PHP] Newbie: PHP/MySQL (SELECT)
> On Thursday 21 November 2002 03:53, Mr. BuNgL3 wrote: > > Hi... > > I'm with a little sintax problem... > > The question is that i have two search fields (titulotxt and cdstxt) and i > > want to create an mysql condition... i trying: > > > > $sql1=($titulotxt) ? "titulo like '%".$titulotxt."%'":""; > > $sql2=($cdstxt) ? "cds like '$cdstxt'":""; > > $sql="SELECT * FROM divx WHERE" .$sql1 " && " .$sql2 " ORDER BY titulo"; > > > > but he's giving me a sintax error on the 3 line... Can anyone > > teach me how i must do to validate the mysql condition and make it work? > > Try: > > $sql="SELECT * FROM divx WHERE" .$sql1. " && " .$sql2. " ORDER BY titulo"; and add a space after the WHERE. Also consider the positioning of the single quotes (') and double-quotes (") in the $sql1 assignment statement - they must be nested. Finally, consider echoing sql1, $sql2, and $sql to be able to see with your own eyes! =dn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Newbie: PHP/MySQL (SELECT)
On Thursday 21 November 2002 03:53, Mr. BuNgL3 wrote: > Hi... > I'm with a little sintax problem... > The question is that i have two search fields (titulotxt and cdstxt) and i > want to create an mysql condition... i trying: > > $sql1=($titulotxt) ? "titulo like '%".$titulotxt."%'":""; > $sql2=($cdstxt) ? "cds like '$cdstxt'":""; > $sql="SELECT * FROM divx WHERE" .$sql1 " && " .$sql2 " ORDER BY titulo"; > > but he's giving me a sintax error on the 3 line... Can anyone > teach me how i must do to validate the mysql condition and make it work? Try: $sql="SELECT * FROM divx WHERE" .$sql1. " && " .$sql2. " ORDER BY titulo"; -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* He thinks by infection, catching an opinion like a cold. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Newbie: PHP/MySQL (SELECT)
Hi... I'm with a little sintax problem... The question is that i have two search fields (titulotxt and cdstxt) and i want to create an mysql condition... i trying: $sql1=($titulotxt) ? "titulo like '%".$titulotxt."%'":""; $sql2=($cdstxt) ? "cds like '$cdstxt'":""; $sql="SELECT * FROM divx WHERE" .$sql1 " && " .$sql2 " ORDER BY titulo"; but he's giving me a sintax error on the 3 line... Can anyone teach me how i must do to validate the mysql condition and make it work? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Newbie: php/mysql (Select)
Hi... I'm with a little sintax problem... The question is that i have two search fields (titulotxt and cdstxt) and i want to create an mysql condition... i trying: $sql1=($titulotxt) ? "titulo like '%".$titulotxt."%'":""; $sql2=($cdstxt) ? "cds like '$cdstxt'":""; $sql="SELECT * FROM divx WHERE" .$sql1 " && " .$sql2 " ORDER BY titulo"; but the bastard is giving me a sintax error on the 3 line... Can anyone teach me how i must do to validate the mysql condition and make it work? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie: php/mysql
The usual way of doing logins with encrypted/hashed passwords is adding new user into the table: INSERT users SET username='$_POST[username]', password=MD5('$_POST[pwd]'); checking if username/password match: SELECT * FROM users WHERE username='$_POST[username]' AND password=MD5('$_POST[pwd]'); hashed passwords cannot be decrypted Mr. BuNgL3 wrote: Hey... I have a little problem... i want to read an encrypted field from mysql database to a php variable... what is the code line that i must enter? (ex: password validation in a login form) Thanks... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] newbie: php/mysql
Hey... I have a little problem... i want to read an encrypted field from mysql database to a php variable... what is the code line that i must enter? (ex: password validation in a login form) Thanks... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Newbie - PHP & MySQL
Ben Clumeck wrote: > When using MySQL to Authenticate users for a specific directory (i.e. > www.mysite.com/user) how would it know to go to that directory ("/user"). > How would it know to not let someone access a file directory in that > directory (i.e. www.mysite.com/user/page2.php)? this question is too general - you should describe your idea of what you want to do and where your problem is a bit more. In general is is you who would be responsible to write the code that checks if a user is authenticated and should have access to something, and you have to include that piece of code at the beginning of each page you want to limit access for. >If I am using MySQL to > query a row in a table can how would it know to only let a specific user(s) > have access to the information? > this either a mysql related question - as mysql deals with the problem that a user has to be authenticated within mysql_connect or mysql_pconnect to access some information - or it is a matter of your application design - if you want only special users to do something or to get some views of the data you queried from mysql you can go and create a user table with users and poasswords, and a permission table where users are designated to specific tasks, then, before you show some data in your script, you ask the user for a password, look him up in your users table, and only let him view the things he is allowed to. but, again, this is a very general answer on a general question, which might be the reason why nobody answered until now, to get some real useful answers or solutions to your problem you have to be more specific. maybe you want to go through some basic tutorials first before doing such comlicated things and learn the basics of php and mysql before playing around with big applications, permissions for users, etc... (sorry, got no URL for something lkike this at hand now, use google) hope this still helps henning -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Newbie - PHP & MySQL
When using MySQL to Authenticate users for a specific directory (i.e. www.mysite.com/user) how would it know to go to that directory ("/user"). How would it know to not let someone access a file directory in that directory (i.e. www.mysite.com/user/page2.php)? If I am using MySQL to query a row in a table can how would it know to only let a specific user(s) have access to the information? Any help you can give me would be greatly appreciated. Thanks, Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Newbie PHP/MySQL Question
Ok, Im' pretty new at this, but I can't see what may be wrong here: Table IMT - User (char) SessionID (char) StartTime(TIMESTAMP) EndTime(TIMESTAMP) Code on first page: INSERT INTO IMT VALUES ('testuser', '$id', CURRENT_TIMESTAMP, '/0'); Code on second page: UPDATE IMT SET EndTime=NOW() WHERE SessionID='$id'; The problem I am having is that when the second page is executed, it places the current time in both StartTime and EndTime. However, while I am viewing the contents throught the process, the StartTime value is correct until the second page is executed, and then whatever is placed into EndTime shows up in StartTime. If it matters, the only session variable i'm using is session_id(). TIA Pete van der Maas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]