Re: [PHP] php/mysql Query Question.
I tend to do this robert, while looking at your example i thought to myself since i am trying to mimick a shell command why not run one. Result: ? $db = 'db'; $host = 'host'; $user = 'user'; $pass = 'pass'; $query = select * from $db.my_table; $ddvery = shell_exec(mysql -u$user -p$pass --html --execute=$query); echo pre$ddvery/pre; ? Not are the results safe but the unlimited possibilites are amazing. Thanks so much for the kick starter ad...@buskirkgraphics.com wrote: Would you mind giving me an example of this that i can stick right into a blank php file and run. I get what you are saying but i cant seem to make that even echo out the data. php 5.2 mysql 5.1.3 Apache 2.2 ?php $db = 'db'; $host = 'host'; $user = 'user'; $pass = 'pass'; $query = select * from my_table; $db = escapeShellArg( $db ); $host = escapeShellArg( $host ); $user = escapeShellArg( $user ); $pass = escapeShellArg( $pass ); $query = escapeShellArg( $query ); $command = echo $query | mysql --html -h$host -u$user -p$pass $db; echo 'Command: '.$command.\n; $html = `$command`; echo $html.\n; ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- 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
Re: [PHP] php/mysql Query Question.
ad...@buskirkgraphics.com wrote: I tend to do this robert, while looking at your example i thought to myself since i am trying to mimick a shell command why not run one. Result: ? $db = 'db'; $host = 'host'; $user = 'user'; $pass = 'pass'; $query = select * from $db.my_table; $ddvery = shell_exec(mysql -u$user -p$pass --html --execute=$query); echo pre$ddvery/pre; ? Not are the results safe but the unlimited possibilites are amazing. Thanks so much for the kick starter This presumes your information is all safe and that there are no special shell characters in any of the configuration settings (now and in the future). Also, the shell_exec() function is identical to the backtick operator that I used in my example (see the help). You've essentially done what I did, but made it less robust... except for the use of the --execute parameter which I wasn't aware existed since it's just as easy to pipe :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php/mysql Query Question.
ad...@buskirkgraphics.com wrote: Before most of you go on a rampage of how to please read below... As most of you already know when using MySQL from the shell you can write your queries in html format in an out file. Example: shellmysql -uyourmom -plovesme --html This now will return all results in an html format from all queries. Now I could “tee” this to a file and save the results returned if I so choose to save the result of the display . Let’s say I want to be lazy and write a php MySQL query to do the same so that any result I queried for would return the html results in a table without actually writing the table tags in the results. Is there a mysql_connect or select_db or mysql_query tag option to do that since mysql can display it from the shell? Here is my rendition of an result to HTML table output function. This is normally used within my db class but I have modified it to work with a MySQLi result object function debug($result) { /* get column metadata */ $html = 'table border=1tr'; foreach ( $result-fetch_fields() AS $val ) { $html .= 'th'.$val-name.'/th'; } $html .= '/tr'; foreach ( $result-fetch_row() AS $row ) { $html .= 'tr'; foreach ( $row AS $value ) { $html .= 'tdnbsp;'.$value.'/td'; } $html .= '/tr'; } $html .= '/table'; return $html; } Let us know if that works for you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php/mysql Query Question.
Before most of you go on a rampage of how to please read below... As most of you already know when using MySQL from the shell you can write your queries in html format in an out file. Example: shellmysql -uyourmom -plovesme --html This now will return all results in an html format from all queries. Now I could “tee” this to a file and save the results returned if I so choose to save the result of the display . Let’s say I want to be lazy and write a php MySQL query to do the same so that any result I queried for would return the html results in a table without actually writing the table tags in the results. Is there a mysql_connect or select_db or mysql_query tag option to do that since mysql can display it from the shell? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php/mysql Query Question.
ad...@buskirkgraphics.com wrote: Before most of you go on a rampage of how to please read below... As most of you already know when using MySQL from the shell you can write your queries in html format in an out file. Example: shellmysql -uyourmom -plovesme --html This now will return all results in an html format from all queries. Now I could “tee” this to a file and save the results returned if I so choose to save the result of the display . Let’s say I want to be lazy and write a php MySQL query to do the same so that any result I queried for would return the html results in a table without actually writing the table tags in the results. Is there a mysql_connect or select_db or mysql_query tag option to do that since mysql can display it from the shell? echo Select * from my_table | mysql --html -ufoo -pfee database_name However, this allows for your database password to be visible in the process list for a brief moment of time. You might be better served by finer grained process control where you can check the output and provide input as needed. Or a simple expect script might suffice. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php/mysql Query Question.
ad...@buskirkgraphics.com wrote: Would you mind giving me an example of this that i can stick right into a blank php file and run. I get what you are saying but i cant seem to make that even echo out the data. php 5.2 mysql 5.1.3 Apache 2.2 ?php $db = 'db'; $host = 'host'; $user = 'user'; $pass = 'pass'; $query = select * from my_table; $db = escapeShellArg( $db ); $host = escapeShellArg( $host ); $user = escapeShellArg( $user ); $pass = escapeShellArg( $pass ); $query = escapeShellArg( $query ); $command = echo $query | mysql --html -h$host -u$user -p$pass $db; echo 'Command: '.$command.\n; $html = `$command`; echo $html.\n; ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php - mysql query issue
Hi all. I am building an online events listing and when I run the following query I get the expected result set: SELECT events.id AS eventid, name, postcode, start_time, dates.date FROM events, dates_events, dates WHERE dates_events.event_id = events.id and dates_events.date_id = dates.id AND dates.date = '$start_string' AND dates.date = '$end_string' ORDER BY date ASC ...however, when I look for a one-off event the following query fails: SELECT events.id AS eventid, name, postcode, start_time, dates.date FROM events, dates_events, dates WHERE dates_events.event_id = events.id and dates_events.date_id = dates.id AND dates.date = '$start_string' ORDER BY date ASC ...if I query for that date in the dates table using this: SELECT * FROM dates WHERE date = '$start_string' I get the date record I expect. The second query above cannot seem to look for a date that equals the supplied string (BTW, all data has been escaped prior to interpolation in the query string!) Any ideas why not? I know it's more of a mySQL question so apologies in advance! -- http://www.web-buddha.co.uk http://www.projectkarma.co.uk
Re: [PHP] php - mysql query issue
Have you tried echoing out your query to run on the backend itself? Maybe there is some problem with how your join is being constructed... Perhaps a left outer join is called for? Hard to tell without having knowledge of your table structure and table data... -B Dave Goodchild wrote: Hi all. I am building an online events listing and when I run the following query I get the expected result set: SELECT events.id AS eventid, name, postcode, start_time, dates.date FROM events, dates_events, dates WHERE dates_events.event_id = events.id and dates_events.date_id = dates.id AND dates.date = '$start_string' AND dates.date = '$end_string' ORDER BY date ASC ...however, when I look for a one-off event the following query fails: SELECT events.id AS eventid, name, postcode, start_time, dates.date FROM events, dates_events, dates WHERE dates_events.event_id = events.id and dates_events.date_id = dates.id AND dates.date = '$start_string' ORDER BY date ASC ...if I query for that date in the dates table using this: SELECT * FROM dates WHERE date = '$start_string' I get the date record I expect. The second query above cannot seem to look for a date that equals the supplied string (BTW, all data has been escaped prior to interpolation in the query string!) Any ideas why not? I know it's more of a mySQL question so apologies in advance! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php - mysql query issue
On 15/09/06, Brad Bonkoski [EMAIL PROTECTED] wrote: Have you tried echoing out your query to run on the backend itself? Maybe there is some problem with how your join is being constructed... Perhaps a left outer join is called for? Hard to tell without having knowledge of your table structure and table data... Yep, I've echoed it and it says: ...WHERE dates.date = '2006-10-03'... I think you're right on the join stakes, I will investigate further, many thanks and have a great weekend.
Re: [PHP] php - mysql query issue
Also you should check if dates.date is a DATE type, not DATETIME. Lost some time on that when I wanted to select enregs for a specific date, field was DATETIME and I was querying `date` = '2006-01-01'... :p Andy Dave Goodchild wrote: On 15/09/06, Brad Bonkoski [EMAIL PROTECTED] wrote: Have you tried echoing out your query to run on the backend itself? Maybe there is some problem with how your join is being constructed... Perhaps a left outer join is called for? Hard to tell without having knowledge of your table structure and table data... Yep, I've echoed it and it says: ...WHERE dates.date = '2006-10-03'... I think you're right on the join stakes, I will investigate further, many thanks and have a great weekend. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php - mysql query issue
On Fri, September 15, 2006 7:35 am, Dave Goodchild wrote: Hi all. I am building an online events listing and when I run the following query I get the expected result set: Any ideas why not? I know it's more of a mySQL question so apologies in advance! Well, you'd have to tell us what's in $start_string. Otherwise, we are just making wild guesses with nothing to back them up. And, really, to be 100% certain, you'd want to echo out the query you've built after $start_string is interpolated. $query = SELECT ... '$start_string' ...; echo $query, hr /\n; mysql_query($query, $connection); After you've done that, it's dollars to donuts that you won't need us to answer the question. :-) -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php, mySQL query character problem
Hi, I have a query to mysql basically saying: $query = select * from table1 where colum1 like '$email%'; //where $email is defined string. When i echo $query, I get the string : select * from table 1 where colum1 like 'testdata%' If i copy paste the string into phpMyAdmin SQL, the query executes successfully and returns one record. However, when I just do$returnValue = QueryDatabase($query); echo mysql_num_rows($returnValue); I always get 0 for the # of records. Does anyone know what causes this? Also... the value i have for $email is from: $email=explode(@,$emailAddress); $email=$email[0]; Thanks, Victor C. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] php, mySQL query character problem
[snip] $query = select * from table1 where colum1 like '$email%'; $returnValue = QueryDatabase($query); echo mysql_num_rows($returnValue); I always get 0 for the # of records. [/snip] You have not included the code from your QueryDatabase functionso we would have to have a crystal ball to discern the answer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php, mySQL query character problem
* Thus wrote Victor C.: If i copy paste the string into phpMyAdmin SQL, the query executes successfully and returns one record. However, when I just do$returnValue = QueryDatabase($query); echo mysql_num_rows($returnValue); I always get 0 for the # of records. What does QueryDatabase() do and return? Curt -- The above comments may offend you. flame at will. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP - mySQL query question
I have a simple question (not for me). Why does this query does not work? $links_query = mysql_query(select id, inserted, title, information, international from links WHERE international = y; order by inserted desc LIMIT 0 , 30); The information for the international fields are: Field: international Type: char(1) Null: No Default:n The error is - Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in TIA Tracking #: BC19379918870340BDA57FD3E349C2D0B4B484BC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP - mySQL query question
Karl-Heinz Schulz wrote: I have a simple question (not for me). Why does this query does not work? $links_query = mysql_query(select id, inserted, title, information, international from links WHERE international = y; order by inserted desc LIMIT 0 , 30); The information for the international fields are: Field: international Type: char(1) Null: No Default:n The error is - Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in Your query has failed. You'd know this if you checked mysql_error() after running your query. $result = mysql_query(...) or die(mysql_error()) Your query fails because you need quotes around the y and you need to remove the semi-colon. $links_query = mysql_query(select id, inserted, title, information, international from links WHERE international = 'y' order by inserted desc LIMIT 0 , 30) or die(mysql_error()); Also, why are you selecting the international column when you're filtering the results to rows that have y for international. You already know what international is, why select it in your query? -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP - mySQL query question
single quote 'y' Jason On Sun, 25 Jul 2004 11:05:23 -0400, Karl-Heinz Schulz [EMAIL PROTECTED] wrote: I have a simple question (not for me). Why does this query does not work? $links_query = mysql_query(select id, inserted, title, information, international from links WHERE international = y; order by inserted desc LIMIT 0 , 30); The information for the international fields are: Field: international Type: char(1) Null: No Default:n The error is - Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in TIA Tracking #: BC19379918870340BDA57FD3E349C2D0B4B484BC -- 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
Re: [PHP] PHP - MySQL Query...
I'm used to do like this: $query = 'SELECT * FROM cities'; $result = mysql_query($query); if($row = mysql_fetch_array($result)) do { echo ('tr td class=city' . $row[0] . ', ' . $row[1] . '/td td' . $row[2] . '/td td' . $row[3] . /td /tr\n); } while ($row = mysql_fetch_array($result)); --- Jay Blanchard [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] [snip] $dbh = mysql_connect(localhost, login, password) or die('cannot connect to the database because: ' . mysql_error()); mysql_select_db(database); $query = 'SELECT * FROM cities'; $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { echo ('tr td class=city' . $row[0] . ', ' . $row[1] . '/td td' . $row[2] . '/td td' . $row[3] . /td /tr\n); } getting this error: *Warning*: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in... so... is the problem with the $query? I don't see anything wrong (assuming my login and database selection is correct) what are the common errors here? [/snip] mysql_query needs both the query variable and the connection variable mysql_query($query, $dbh); HTH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP - MySQL Query...
This is not true, the resource link identifier is optional! If unspecified, the last opened link is used. My suggestion is to check the results of mysql_error() for more information on the failed query. HTH, Ivo Jay Blanchard [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] [snip] $dbh = mysql_connect(localhost, login, password) or die('cannot connect to the database because: ' . mysql_error()); mysql_select_db(database); $query = 'SELECT * FROM cities'; $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { echo ('tr td class=city' . $row[0] . ', ' . $row[1] . '/td td' . $row[2] . '/td td' . $row[3] . /td /tr\n); } getting this error: *Warning*: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in... so... is the problem with the $query? I don't see anything wrong (assuming my login and database selection is correct) what are the common errors here? [/snip] mysql_query needs both the query variable and the connection variable mysql_query($query, $dbh); HTH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP - MySQL Query...
[snip] This is not true, the resource link identifier is optional! If unspecified, the last opened link is used. My suggestion is to check the results of mysql_error() for more information on the failed query. [/snip] You are right, of course...my sleepy brain just glanced at the code and fired off a reply. I always test queries with the following block; if(!($result = mysql_query($query, $connection))){ echo A query error has occured: . mysql_error() . \n; exit(); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP - MySQL Query...
* Thus wrote Steven Kallstrom ([EMAIL PROTECTED]): Hello all... I'm embarrassed by this one... I think it should work but it isn't... $query = 'SELECT * FROM cities'; $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { getting this error: *Warning*: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in... Hmm.. I thought I had replied to this.. anyway, check the output of mysql_error() after your mysql_query(), mysql_select_db() and mysql_connect() to see who is cause the query to fail. The sql syntax appears to be correct. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP - MySQL Query...
Try this, $result = mysql_query($query,$dbh); -Murugesan - Original Message - From: Jay Blanchard [EMAIL PROTECTED] To: Steven Kallstrom [EMAIL PROTECTED]; PHP List [EMAIL PROTECTED] Sent: Thursday, August 14, 2003 4:50 PM Subject: RE: [PHP] PHP - MySQL Query... [snip] $dbh = mysql_connect(localhost, login, password) or die('cannot connect to the database because: ' . mysql_error()); mysql_select_db(database); $query = 'SELECT * FROM cities'; $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { echo ('tr td class=city' . $row[0] . ', ' . $row[1] . '/td td' . $row[2] . '/td td' . $row[3] . /td /tr\n); } getting this error: *Warning*: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in... so... is the problem with the $query? I don't see anything wrong (assuming my login and database selection is correct) what are the common errors here? [/snip] mysql_query needs both the query variable and the connection variable mysql_query($query, $dbh); HTH! -- 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] PHP - MySQL Query...
Hello all... I'm embarrassed by this one... I think it should work but it isn't... $dbh = mysql_connect(localhost, login, password) or die('cannot connect to the database because: ' . mysql_error()); mysql_select_db(database); $query = 'SELECT * FROM cities'; $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { echo ('tr td class=city' . $row[0] . ', ' . $row[1] . '/td td' . $row[2] . '/td td' . $row[3] . /td /tr\n); } getting this error: *Warning*: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in... so... is the problem with the $query? I don't see anything wrong (assuming my login and database selection is correct) what are the common errors here? Thanks, SJK ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP - MySQL Query...
Steven Kallstrom wrote: Hello all... I'm embarrassed by this one... I think it should work but it isn't... $dbh = mysql_connect(localhost, login, password) or die('cannot connect to the database because: ' . mysql_error()); mysql_select_db(database); $query = 'SELECT * FROM cities'; $result = mysql_query($query); Try this instead; $result = mysql_query($query) or die(Query died: . mysql_error()); Cheers! -Michael while ($row = mysql_fetch_row($result)) { echo ('tr td class=city' . $row[0] . ', ' . $row[1] . '/td td' . $row[2] . '/td td' . $row[3] . /td /tr\n); } getting this error: *Warning*: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in... so... is the problem with the $query? I don't see anything wrong (assuming my login and database selection is correct) what are the common errors here? Thanks, SJK ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP - MySQL Query...
[snip] $dbh = mysql_connect(localhost, login, password) or die('cannot connect to the database because: ' . mysql_error()); mysql_select_db(database); $query = 'SELECT * FROM cities'; $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { echo ('tr td class=city' . $row[0] . ', ' . $row[1] . '/td td' . $row[2] . '/td td' . $row[3] . /td /tr\n); } getting this error: *Warning*: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in... so... is the problem with the $query? I don't see anything wrong (assuming my login and database selection is correct) what are the common errors here? [/snip] mysql_query needs both the query variable and the connection variable mysql_query($query, $dbh); HTH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP/MySQL Query
How do i make a form that will allow me to add 2 to the value of a MySQL field? I am trying to change it from 75 to 77. Is this possible? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/MySQL Query
mysql_query(update table set field=field+1 where whatever='whatever'); Steven M wrote: How do i make a form that will allow me to add 2 to the value of a MySQL field? I am trying to change it from 75 to 77. Is this possible? Thanks -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/MySQL Query
Leif Many thanks for that, your help is much appreciated. *smiles* Steven M -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP/MYSQL query error
I am getting a failed query error message. Could someone take a look and let me know. //F U N C T I O N S //= function AddSignupRequest($Signup_FName, $Signup_LName, $Signup_Address1, $Signup_Address2, $Signup_City, $Signup_State, $Signup_Zip, $Signup_Email, $Signup_Phone, $Signup_ContactMethod, $Signup_Date, $Signup_IP, $Signup_Status, $Signup_Comments) { /* Connecting, selecting database */ $dbh=mysql_connect ($MySQL_Host, $MySQL_User, $MySQL_Password) or die ('I cannot connect to the database.'); mysql_select_db (havasuin_Signups); /* Performing SQL query */ $query = INSERT INTO SignupRequests ('FirstName', 'LastName', 'Address1', 'Address2', 'City', 'State', 'Zip', 'Email', 'Phone', 'ContactMethod', 'Date', 'IP', 'Status', 'Comments') VALUES ('', 'Chris', 'Crane', '655 Talcottville Road', 'Apt. 185', 'Vernon', 'CT', '06066', '[EMAIL PROTECTED]', '860-659-6464', 'Email', 'August 25, 2002', '64.252.232.82', 'Newly Requested', 'Testing'); $result = mysql_query($query) or die(Query failed); /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); print br$Signup_LName, $Signup_FNamebr\n; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP/MYSQL query error
[snip] /* Performing SQL query */ $query = INSERT INTO SignupRequests ('FirstName', 'LastName', 'Address1', 'Address2', 'City', 'State', 'Zip', 'Email', 'Phone', 'ContactMethod', 'Date', 'IP', 'Status', 'Comments') VALUES ('', 'Chris', 'Crane', '655 Talcottville Road', 'Apt. 185', 'Vernon', 'CT', '06066', '[EMAIL PROTECTED]', '860-659-6464', 'Email', 'August 25, 2002', '64.252.232.82', 'Newly Requested', 'Testing'); $result = mysql_query($query) or die(Query failed); [/snip] Have you printed the query to make sure that the syntax is right? The first thing that I see is that there are 13 items in your INSERT statement and 15 items in your VALUES statement ... these must match in order for the query to work. HTH! Jay Ask smart questions: http://www.tuxedo.org/~esr/faqs/smart-questions.html Top Questions on php-general; (Answers can be found by RTFM, STFW, or STFA, save for #3 and #6 which can probably be found the same way, since they are usually one of the other questions on this list.) 1. How can I make file uploads work? 2. How come my form will not pass variables? 3. HELP! HELP! Please HELP! 4. Register_Globals ?!? 5. Is there a function to ... [insert thought here]? 6. Anyone see the error in this code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/MYSQL query error
Initially there was an error with too many values verses columns. But I think it was fixed. I am double checking now. Jay Blanchard [EMAIL PROTECTED] wrote in message 003201c24d07$b8560470$8102a8c0@000347D72515">news:003201c24d07$b8560470$8102a8c0@000347D72515... [snip] /* Performing SQL query */ $query = INSERT INTO SignupRequests ('FirstName', 'LastName', 'Address1', 'Address2', 'City', 'State', 'Zip', 'Email', 'Phone', 'ContactMethod', 'Date', 'IP', 'Status', 'Comments') VALUES ('', 'Chris', 'Crane', '655 Talcottville Road', 'Apt. 185', 'Vernon', 'CT', '06066', '[EMAIL PROTECTED]', '860-659-6464', 'Email', 'August 25, 2002', '64.252.232.82', 'Newly Requested', 'Testing'); $result = mysql_query($query) or die(Query failed); [/snip] Have you printed the query to make sure that the syntax is right? The first thing that I see is that there are 13 items in your INSERT statement and 15 items in your VALUES statement ... these must match in order for the query to work. HTH! Jay Ask smart questions: http://www.tuxedo.org/~esr/faqs/smart-questions.html Top Questions on php-general; (Answers can be found by RTFM, STFW, or STFA, save for #3 and #6 which can probably be found the same way, since they are usually one of the other questions on this list.) 1. How can I make file uploads work? 2. How come my form will not pass variables? 3. HELP! HELP! Please HELP! 4. Register_Globals ?!? 5. Is there a function to ... [insert thought here]? 6. Anyone see the error in this code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/MYSQL query error
There are 15 columns and 15 pieces of data. In my second post I fixed this error and pasted it into PHPMYADMIN and it worked fine, but not here... Chris Crane [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Initially there was an error with too many values verses columns. But I think it was fixed. I am double checking now. Jay Blanchard [EMAIL PROTECTED] wrote in message 003201c24d07$b8560470$8102a8c0@000347D72515">news:003201c24d07$b8560470$8102a8c0@000347D72515... [snip] /* Performing SQL query */ $query = INSERT INTO SignupRequests ('FirstName', 'LastName', 'Address1', 'Address2', 'City', 'State', 'Zip', 'Email', 'Phone', 'ContactMethod', 'Date', 'IP', 'Status', 'Comments') VALUES ('', 'Chris', 'Crane', '655 Talcottville Road', 'Apt. 185', 'Vernon', 'CT', '06066', '[EMAIL PROTECTED]', '860-659-6464', 'Email', 'August 25, 2002', '64.252.232.82', 'Newly Requested', 'Testing'); $result = mysql_query($query) or die(Query failed); [/snip] Have you printed the query to make sure that the syntax is right? The first thing that I see is that there are 13 items in your INSERT statement and 15 items in your VALUES statement ... these must match in order for the query to work. HTH! Jay Ask smart questions: http://www.tuxedo.org/~esr/faqs/smart-questions.html Top Questions on php-general; (Answers can be found by RTFM, STFW, or STFA, save for #3 and #6 which can probably be found the same way, since they are usually one of the other questions on this list.) 1. How can I make file uploads work? 2. How come my form will not pass variables? 3. HELP! HELP! Please HELP! 4. Register_Globals ?!? 5. Is there a function to ... [insert thought here]? 6. Anyone see the error in this code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/MYSQL query error
Why don't you do $result = mysql_query($query) or die(mysql_error()); or $result = mysql_query($query); echo mysql_error(); That way, instead of Query Failed you'll get something meaningful... probably something that will solve the problem. Justin French on 26/08/02 11:55 PM, Chris Crane ([EMAIL PROTECTED]) wrote: Initially there was an error with too many values verses columns. But I think it was fixed. I am double checking now. Jay Blanchard [EMAIL PROTECTED] wrote in message 003201c24d07$b8560470$8102a8c0@000347D72515">news:003201c24d07$b8560470$8102a8c0@000347D72515... [snip] /* Performing SQL query */ $query = INSERT INTO SignupRequests ('FirstName', 'LastName', 'Address1', 'Address2', 'City', 'State', 'Zip', 'Email', 'Phone', 'ContactMethod', 'Date', 'IP', 'Status', 'Comments') VALUES ('', 'Chris', 'Crane', '655 Talcottville Road', 'Apt. 185', 'Vernon', 'CT', '06066', '[EMAIL PROTECTED]', '860-659-6464', 'Email', 'August 25, 2002', '64.252.232.82', 'Newly Requested', 'Testing'); $result = mysql_query($query) or die(Query failed); [/snip] Have you printed the query to make sure that the syntax is right? The first thing that I see is that there are 13 items in your INSERT statement and 15 items in your VALUES statement ... these must match in order for the query to work. HTH! Jay Ask smart questions: http://www.tuxedo.org/~esr/faqs/smart-questions.html Top Questions on php-general; (Answers can be found by RTFM, STFW, or STFA, save for #3 and #6 which can probably be found the same way, since they are usually one of the other questions on this list.) 1. How can I make file uploads work? 2. How come my form will not pass variables? 3. HELP! HELP! Please HELP! 4. Register_Globals ?!? 5. Is there a function to ... [insert thought here]? 6. Anyone see the error in this code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/MYSQL query error
Thank you. I will try that. Justin French [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Why don't you do $result = mysql_query($query) or die(mysql_error()); or $result = mysql_query($query); echo mysql_error(); That way, instead of Query Failed you'll get something meaningful... probably something that will solve the problem. Justin French on 26/08/02 11:55 PM, Chris Crane ([EMAIL PROTECTED]) wrote: Initially there was an error with too many values verses columns. But I think it was fixed. I am double checking now. Jay Blanchard [EMAIL PROTECTED] wrote in message 003201c24d07$b8560470$8102a8c0@000347D72515">news:003201c24d07$b8560470$8102a8c0@000347D72515... [snip] /* Performing SQL query */ $query = INSERT INTO SignupRequests ('FirstName', 'LastName', 'Address1', 'Address2', 'City', 'State', 'Zip', 'Email', 'Phone', 'ContactMethod', 'Date', 'IP', 'Status', 'Comments') VALUES ('', 'Chris', 'Crane', '655 Talcottville Road', 'Apt. 185', 'Vernon', 'CT', '06066', '[EMAIL PROTECTED]', '860-659-6464', 'Email', 'August 25, 2002', '64.252.232.82', 'Newly Requested', 'Testing'); $result = mysql_query($query) or die(Query failed); [/snip] Have you printed the query to make sure that the syntax is right? The first thing that I see is that there are 13 items in your INSERT statement and 15 items in your VALUES statement ... these must match in order for the query to work. HTH! Jay Ask smart questions: http://www.tuxedo.org/~esr/faqs/smart-questions.html Top Questions on php-general; (Answers can be found by RTFM, STFW, or STFA, save for #3 and #6 which can probably be found the same way, since they are usually one of the other questions on this list.) 1. How can I make file uploads work? 2. How come my form will not pass variables? 3. HELP! HELP! Please HELP! 4. Register_Globals ?!? 5. Is there a function to ... [insert thought here]? 6. Anyone see the error in this code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP/MYSQL query error
I got it working. It did not like the single quotes around the column names. Chris Crane [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Thank you. I will try that. Justin French [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Why don't you do $result = mysql_query($query) or die(mysql_error()); or $result = mysql_query($query); echo mysql_error(); That way, instead of Query Failed you'll get something meaningful... probably something that will solve the problem. Justin French on 26/08/02 11:55 PM, Chris Crane ([EMAIL PROTECTED]) wrote: Initially there was an error with too many values verses columns. But I think it was fixed. I am double checking now. Jay Blanchard [EMAIL PROTECTED] wrote in message 003201c24d07$b8560470$8102a8c0@000347D72515">news:003201c24d07$b8560470$8102a8c0@000347D72515... [snip] /* Performing SQL query */ $query = INSERT INTO SignupRequests ('FirstName', 'LastName', 'Address1', 'Address2', 'City', 'State', 'Zip', 'Email', 'Phone', 'ContactMethod', 'Date', 'IP', 'Status', 'Comments') VALUES ('', 'Chris', 'Crane', '655 Talcottville Road', 'Apt. 185', 'Vernon', 'CT', '06066', '[EMAIL PROTECTED]', '860-659-6464', 'Email', 'August 25, 2002', '64.252.232.82', 'Newly Requested', 'Testing'); $result = mysql_query($query) or die(Query failed); [/snip] Have you printed the query to make sure that the syntax is right? The first thing that I see is that there are 13 items in your INSERT statement and 15 items in your VALUES statement ... these must match in order for the query to work. HTH! Jay Ask smart questions: http://www.tuxedo.org/~esr/faqs/smart-questions.html Top Questions on php-general; (Answers can be found by RTFM, STFW, or STFA, save for #3 and #6 which can probably be found the same way, since they are usually one of the other questions on this list.) 1. How can I make file uploads work? 2. How come my form will not pass variables? 3. HELP! HELP! Please HELP! 4. Register_Globals ?!? 5. Is there a function to ... [insert thought here]? 6. Anyone see the error in this code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP/MySQL Query Prob
Hey... new to the list, but didn't have time to lurk and watch the traffic, kind of in a bind here. I apologize in advance if I do something wrong... Using this code: ?php $link = mysql_connect() or die(Could not connect); mysql_select_db(mydb) or die(Could not select database); $result = mysql_query(SELECT * FROM cars WHERE year=1991); extract(mysql_fetch_array($result)); while ($row = mysql_fetch_object($result)) { $generation = $row-generation; $year = $row-year; $owner = $row-owner; $email = $row-email; $pic1 = $row-pic1; $tmb1 = $row-tmb1; printf(img src='%s'br, $pic1); printf(small%s/smallbr,$generation); printf(b%s/bbr,$year); printf(%sbr,$owner); printf(a href=mailto:'%s'%s/ap, $email, $email); printf(a href='%s'img src='%s' border=0/ap, $pic1, $tmb1); } /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); ? I'm successfully able to retrieve and display information for year='1991'. It works great. However, if I replace '1991' with any other year that I KNOW there's a matching record for, I get no results. So if I were to replace year='1991' with year='1990', no results would be produced although the same query given directly in MySQL will give results. Make sense? This same problem happens with other fields too, it seems really selective. I can use WHERE color='red' and get results, but color='black' returns nothing, although there are matching records. Taking out the WHERE in the above code will return all but the first record in the table. I fixed that just by putting a dummy record first, but that still shouldn't be happening. Any ideas? I need to get this fixed but I'm not sure what's wrong! Thanks in advance, Jason (PHP 4.1.2 Win32) (MySQL 3.23 Win32) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP/mySQL query problem...
Guys, why isn't this working? :) SELECT * FROM links WHERE name LIKE %te% OR description LIKE %te% OR url LIKE %te% AND approved=1 LIMIT 5 I am using a PHP script to add items to the database and a small search file to grab them. Thing is, I want the above to grab ONLY ones that have approved = 1. In the database they are all = 0. Is there a problem with my SQL query? Jeff
Re: [PHP] PHP/mySQL query problem...
Yes, there is a problem. -- SELECT * FROM links WHERE 1=1 and ( name LIKE %te% OR description LIKE %te% OR url LIKE %te% ) AND approved=1 LIMIT 5; -- --- Jeff Lewis [EMAIL PROTECTED] wrote: Guys, why isn't this working? :) SELECT * FROM links WHERE name LIKE %te% OR description LIKE %te% OR url LIKE %te% AND approved=1 LIMIT 5 I am using a PHP script to add items to the database and a small search file to grab them. Thing is, I want the above to grab ONLY ones that have approved = 1. In the database they are all = 0. Is there a problem with my SQL query? Jeff = Mehmet Erisen http://www.erisen.com __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- 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] PHP/mySQL Query....
Ok, using PHP and mySQL have two tables that look something like this; Table 1 (users): userID location Table 2 (resumes): resumeID userID I am trying to form a query to pull all the locations and list them on the page. While I could only just select from the users one I do want to be able to pull up the resumes as well. What is the best query for this? Jeff
RE: [PHP] PHP/mySQL Query....
I'm assuming you're trying to join them and show resumeID also with this SELECT r.resumeID,r.userID,u.location FROM resumes r,users u WHERE r.userID=u.userID; -Original Message- From: Jeff Lewis [EMAIL PROTECTED] Sent: Thursday, July 19, 2001 12:45 PM To: [EMAIL PROTECTED] Subject: [PHP] PHP/mySQL Query Ok, using PHP and mySQL have two tables that look something like this; Table 1 (users): userID location Table 2 (resumes): resumeID userID I am trying to form a query to pull all the locations and list them on the page. While I could only just select from the users one I do want to be able to pull up the resumes as well. What is the best query for this? Jeff -- 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]
Re: [PHP] PHP/mySQL Query....
Yes but for the first query all I want to do is list the locations and not multiple times Jeff - Original Message - From: King, Justin [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 19, 2001 1:46 PM Subject: RE: [PHP] PHP/mySQL Query I'm assuming you're trying to join them and show resumeID also with this SELECT r.resumeID,r.userID,u.location FROM resumes r,users u WHERE r.userID=u.userID; -Original Message- From: Jeff Lewis [EMAIL PROTECTED] Sent: Thursday, July 19, 2001 12:45 PM To: [EMAIL PROTECTED] Subject: [PHP] PHP/mySQL Query Ok, using PHP and mySQL have two tables that look something like this; Table 1 (users): userID location Table 2 (resumes): resumeID userID I am trying to form a query to pull all the locations and list them on the page. While I could only just select from the users one I do want to be able to pull up the resumes as well. What is the best query for this? Jeff -- 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 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]
RE: [PHP] PHP/mySQL Query....
Whoops.. do SELECT DISTINCT -Justin -Original Message- From: Jeff Lewis [EMAIL PROTECTED] Sent: Thursday, July 19, 2001 1:08 PM To: King, Justin; [EMAIL PROTECTED] Subject: Re: [PHP] PHP/mySQL Query Yes but for the first query all I want to do is list the locations and not multiple times Jeff - Original Message - From: King, Justin [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 19, 2001 1:46 PM Subject: RE: [PHP] PHP/mySQL Query I'm assuming you're trying to join them and show resumeID also with this SELECT r.resumeID,r.userID,u.location FROM resumes r,users u WHERE r.userID=u.userID; -Original Message- From: Jeff Lewis [EMAIL PROTECTED] Sent: Thursday, July 19, 2001 12:45 PM To: [EMAIL PROTECTED] Subject: [PHP] PHP/mySQL Query Ok, using PHP and mySQL have two tables that look something like this; Table 1 (users): userID location Table 2 (resumes): resumeID userID I am trying to form a query to pull all the locations and list them on the page. While I could only just select from the users one I do want to be able to pull up the resumes as well. What is the best query for this? Jeff -- 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 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] PHP/mySQL Query
I fought the urge to post this here but have to :( I have two tables named like this: owners -ownerID -teamname -more fields teampages -ownerID -bio Anyway, I'm doing a select on the database like this: select ownerID, last_update FROM teampages ORDER BY last_update DESC LIMIT 10 The thing is, I want to get the team name from the other table as well. Can anyone help me out? Jeff
Re: [PHP] PHP/mySQL Query
what you want to do is a join so it'd look something like this.. select teampages.ownerID, teampages.last_update, owners.teamname FROM teampages, owners where teampages.ownerID= owners.ownerID ORDER BY teampages.last_update DESC LIMIT 10 hopefully that will work! :) jay - Original Message - From: Jeff Lewis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 05, 2001 6:59 PM Subject: [PHP] PHP/mySQL Query I fought the urge to post this here but have to :( I have two tables named like this: owners -ownerID -teamname -more fields teampages -ownerID -bio Anyway, I'm doing a select on the database like this: select ownerID, last_update FROM teampages ORDER BY last_update DESC LIMIT 10 The thing is, I want to get the team name from the other table as well. Can anyone help me out? Jeff -- 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]
Re: [PHP] PHP/mySQL Query
On Thu, 5 Jul 2001, Jeff Lewis wrote: owners -ownerID -teamname -more fields teampages -ownerID -bio Anyway, I'm doing a select on the database like this: select ownerID, last_update FROM teampages ORDER BY last_update DESC LIMIT 10 The thing is, I want to get the team name from the other table as well. Can anyone help me out? SELECT owners.ownerID, ??.last_update FROM owners, teampages WHERE owners.ownerID = teampages.ownerID ORDER BY last_update DESC LIMIT 10 _should_ work. -- Sapere aude My mind not only wanders, it sometimes leaves completely. -- 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]
RE: [PHP] PHP/mySQL Query
SELECT t.ownerID, t.last_update, o.teamname FROM teampages t, owners o WHERE t.ownerID = o.ownerID ORDER BY t.last_update DESC LIMIT 10 -Original Message- From: Jeff Lewis [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 05, 2001 5:00 PM To: [EMAIL PROTECTED] Subject: [PHP] PHP/mySQL Query I fought the urge to post this here but have to :( I have two tables named like this: owners -ownerID -teamname -more fields teampages -ownerID -bio Anyway, I'm doing a select on the database like this: select ownerID, last_update FROM teampages ORDER BY last_update DESC LIMIT 10 The thing is, I want to get the team name from the other table as well. Can anyone help me out? Jeff -- 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]
Re: [PHP] PHP/mySQL Query
Jeff Lewis [EMAIL PROTECTED] wrote: I fought the urge to post this here but have to :( owners -ownerID -teamname -more fields teampages -ownerID -bio Anyway, I'm doing a select on the database like this: select ownerID, last_update FROM teampages ORDER BY last_update DESC LIMIT 10 The thing is, I want to get the team name from the other table as well. Can anyone help me out? I've read the other solutions, they all used STRAIGHT JOINs. You may want to consider a LEFT JOIN (form of an OUTER JOIN). A LEFT JOIN will return all the records from table A and those from table B that match the records from table A. The implication is that with a straight join if there is no record for an ownerID corresponding to the record from the table teampages then the record from teampages won't be returned. So if a teamname never got entered in owners or the ID was mis-entered your query would not return all of the records from teampages and you probably want it to. Using a LEFT JOIN the record from teampages will be returned, but since there's no corresponding record in table owners the field teamname will be blank. Assuming all of the data is in both tables it's not a problem, but believe me at some point when doing database programming this issue will arise. SELECT teampages.ownerID, teampages.last_update, owners.teamname FROM teampages LEFT JOIN owners ON teampages.ownerID = owners.ownerID ORDER BY last_update DESC LIMIT 10 -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/ -- 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]
RE: [PHP] PHP Mysql query data conversion newbie
On 09-May-01 Jon Haworth wrote: snip be sure to check for the NULL : if (isset($amyrow[date])) { if ($amyrow[date] == -00-00 00:00:00) { echo no date; } else { echo $amyrow[date]; } } else { echo 'pfsst.'; } echo /td; } HTH Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- 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] PHP Mysql query data conversion newbie
Hello, I pull some data from mysql with the php code below. On the date field if there is no date on mysql it displays : -00-00 00:00:00 I would like to change this -00-00 00:00:00 to no date for example.. Or if the cel is empty to (because otherwise the tableborders are messed up) I tried to put an if statement inside the while {} but i cannot figured out... Thank You, Andras {$aresult=mysql_query(select * from media where d like '$city' order by i ,$db);} while($amyrow = mysql_fetch_array($aresult)) { echo /tdtdfont face=verdana size=1; echo $amyrow[i]; echo /tdtdfont face=verdana size=1; echo $amyrow[j]; echo /tdtdfont face=verdana size=1; echo $amyrow[f]; echo /td; } -- 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]
RE: [PHP] PHP Mysql query data conversion newbie
Well, it's not immediately obvious whether your date is in i, j, or f, so let's pretend it's in date :-) Try this: while($amyrow = mysql_fetch_array($aresult)) { echo /tdtdfont face=verdana size=1; echo $amyrow[i]; echo /tdtdfont face=verdana size=1; echo $amyrow[j]; echo /tdtdfont face=verdana size=1; echo $amyrow[f]; echo /tdtdfont face=verdana size=1; if ($amyrow[date] == -00-00 00:00:00) { echo no date; } else { echo $amyrow[date]; } echo /td; } } HTH Jon -Original Message- From: Andras Kende [mailto:[EMAIL PROTECTED]] Sent: 28 April 2001 17:01 To: [EMAIL PROTECTED] Subject: [PHP] PHP Mysql query data conversion newbie Hello, I pull some data from mysql with the php code below. On the date field if there is no date on mysql it displays : -00-00 00:00:00 I would like to change this -00-00 00:00:00 to no date for example.. Or if the cel is empty to (because otherwise the tableborders are messed up) I tried to put an if statement inside the while {} but i cannot figured out... Thank You, Andras {$aresult=mysql_query(select * from media where d like '$city' order by i ,$db);} while($amyrow = mysql_fetch_array($aresult)) { echo /tdtdfont face=verdana size=1; echo $amyrow[i]; echo /tdtdfont face=verdana size=1; echo $amyrow[j]; echo /tdtdfont face=verdana size=1; echo $amyrow[f]; echo /td; } -- 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] ** 'The information included in this Email is of a confidential nature and is intended only for the addressee. If you are not the intended addressee, any disclosure, copying or distribution by you is prohibited and may be unlawful. Disclosure to any party other than the addressee, whether inadvertent or otherwise is not intended to waive privilege or confidentiality' ** -- 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]
Re: [PHP] PHP Mysql query data conversion newbie
On Sat, 28 Apr 2001, Andras Kende wrote: Hello, I pull some data from mysql with the php code below. On the date field if there is no date on mysql it displays : -00-00 00:00:00 I would like to change this -00-00 00:00:00 to no date for example.. hmm... mysql can do this, works like this: IF(EXPR,TRUE,FALSE): mysql select IF(UNIX_TIMESTAMP(lastmod)=0,NoDate,lastmod) as date from links; +-+ | date| +-+ | 2001-04-22 08:04:07 | | 2001-04-22 08:04:10 | | 2001-04-22 08:03:45 | | 2001-04-22 08:03:42 | | 2001-04-22 08:03:41 | ... | 2001-04-22 08:03:45 | | 2001-04-22 08:04:05 | | 2001-04-22 08:03:43 | | NoDate | (normally -00-00 00:00:00) | 2001-04-22 08:04:06 | | 2001-04-22 08:03:56 | | 2001-04-22 08:04:08 | | 2001-04-22 12:57:27 | | 2001-04-27 21:26:36 | | 2001-05-07 22:35:45 | +-+ 28 rows in set (0.00 sec) Or if the cel is empty to (because otherwise the tableborders are messed up) If by empty you mean NULL, you could probably do similar as above: mysql select IF(lastchk IS NULL,nbsp;,lastchk) from links; +--+ | IF(lastchk IS NULL,nbsp;,lastchk) | +--+ | 24 | | 9| | nbsp; | | 8| ... | nbsp; | | 6| | 1| | nbsp; | | nbsp; | | nbsp; | | nbsp; | +--+ 28 rows in set (0.01 sec) ... the nbsp; will hold the table cell in html. I tried to put an if statement inside the while {} but i cannot figured out... yep you could do this too. I don't know which is faster as i have not been able to test either under high enough load to make a difference :( i prefer to let mysql do all the work it can because i figure the web server is busy enough will all kind of regular html requests. good luck... hope this helped. Bill -- 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]