Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





MySQL Conditional Statement


What I am trying to do is kind of like an advanced search. Basically, I have three dropdowns, for this I am going to use the example books: Three dropdowns, which are

1) Author
2) Language
3) Type (Hardback or Paperback)

Typical search: I want to get a list of all books written by STEPHEN KING, that are written in ENGLISH and that are HARDBACK ok fine, but what if I just want to search for ALL books by STEPHEN KING regardless of the language or the type of book?? Heres the SQL i would use for all 3 "search parameters": PHP Code:




View Complete Forum Thread with Replies

Related Forum Messages:
OR Conditional Statement
I am trying to do this. But for some reason or does not work. How do you do an or statement with PHP?

if ($var == 8 or $var == 9) {
print "is eight or nine";
} else {
print "not eight or nine";
}

View Replies !
Conditional Statement
I have made pages to create databases and the db gets created, but if i specify a not null auto_increment ,primary key the script ignores it and just makes the column a int column. Code:

View Replies !
Writing Conditional Statement
I'm trying write a conditional statement that updates the database in 1 of 2 ways depending on the values given. I'm only 2 weeks into learning PHP/MySQL so I realize the way I've written it out is probably sloppy and more inefficient than what it could be. I've just been winging it from examples and trial and error and have gotten everything working except for this. I'm not sure if I have my logic or syntax wrong.

Application-specific details:
This is a simple invoicing application. Every invoice is in either 1 of 3 states:

- pending (default state when a new invoice is entered)
- paid (state when invoice is paid in full)
- partial (state when only partial payments have been made on the invoice)

What I'm trying to do is this:

1. If a partial payment is made on an invoice, the status is set to 'partial' (this is working)
2. If the payment posted was the full amount of the invoice or the final amount needed to pay it in full, the status is set to 'paid' (this is not working)

My processing logic works like this:
1. There is a total invoice amount stored in the invoice table represented by $total variable (working)
2. When payments have been made to that invoice (stored in the payments table), I show the remaining balance on their invoice by calculating the sum of those payments and subtracting them from the total (this is represented by the $diff variable and is working)
3. The part not working: When the remaining balance ($diff) minus the payment amount posted ($_POST['amount']) is equal to 0, the status is set to paid. PHP Code:

View Replies !
Help With Posting Conditional If Statement
I've tried scaling down a script to the bare minimum and
it still is not working correctly. What I think should happen is that when
the field app_fname is blank, that $hold_chk will get set to 1 and the 1st
if statement will be executed. What actually happens is that when I hit
submit, the form stays where it is, for example if the form where the submit
button is located is on the form other.php, then when I hit submit this is
where it stays. If I then hit the submit button a 2nd time, it post to the
some.php form. I've tried this script without the conditional if(isset()
and it works. I need to have the isset() otherwise the form displays all
empty fields as soon as it loads, before the submit button is hit.

<?php

$holdchk = 0;

if (isset($_POST['B1'])) {

echo "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk == 1 ){
echo "<form method="POST" action="some.php">";

}

if ($holdchk == 0 ){
echo "<form method="POST" action="other.php">";

}
}
?>

<html>

<head>
</head>

<form method="POST" action="">

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

View Replies !
Conditional Statement 'Begins With'
I am trying to pass a form variable that a user would enter a postcode/zipcode value and cannot get the conditional statement to work. What I want to happen is when a user enter a postcode/zipcode ie: CF2 I want to set the condition to the first two letters 'CF' so if it 'begins with' 'CF' then displays on price and 'does not begin with' 'CF' shows another price. see below what I have so far come up with PHP Code:

if($_SESSION['cboBolton'] == 'No')
  $int_sale_fee = 0.00;
else if($_SESSION['cboBolton'] == 'Yes' && $_SESSION['txtPostcode_A'] == "CF")
  $int_sale_fee = 350;
else if($_SESSION['cboBolton'] == 'Yes' && $_SESSION['txtPostcode_A'] != "CF")
  $int_sale_fee = 50;

View Replies !
Function Like A Conditional Statement
how to use the function which works like a conditional statement.

I think it is something like: 3 < 4 : $something ? $something

View Replies !
Conditional Statement To Check
I'm modifying some old code on our system and have ran into this stupid roadblock. Essentially, the old system had these lre_codes with values 1-8. The lre_codes have been changed and now have the following values (32,35,13,34,15,16,36,33). Here is the way the original code was written. PHP Code:

if (($lre_code>0)&&($lre_code<9)){
    $cnts['s_d'][$lre_code][$lre_1077_age]=$cnts['s_d'][$lre_code][$lre_1077_age]+1;
    $cnts['s_d'][$lre_code]['total']=$cnts['s_d'][$lre_code]['total']+1;
    $cnts['s_d']['age_counts'][$lre_1077_age]=$cnts['s_d']['age_counts'][$lre_1077_age]+1;
    $cnts['s_d']['grandtotal']=$cnts['s_d']['grandtotal']+1;
}

I need to change the if statement to check for the above codes and I just can't figure out how to get it to work. Very simple, most likely.

View Replies !
Trim And Conditional Statement
$_REQUEST['statement'] = (trim($_REQUEST['statement']) != "" ? $_REQUEST['statement'] : $_LANG['Nostatement']);

Can someone tell me what the above is doing? Statement is always truncated in output, obviously because of trim, but what does the whole statement do?

Can i just take out trim? Is the trim the problem, i thought it only takes out whitespaces.

View Replies !
OnClick- Conditional Statement
What I'm trying to do is make an if statement for when somebody clicks on an image. What I want to happen-(this is for an upload form):

1. The User fills in the info about the video
2. THEN they have to click on the image before the "upload" button appears.

I don't know if I should use JavaScript's "onClick", or create a function which allows the "upload" button to appear.

View Replies !
Htaccess Conditional Statement
I have this setting in my htaccess file: Code:

php_flag magic_quotes_gpc 0
php_flag magic_quotes_runtime 0

I have based my program around this, and I don't want to turn it on. I am trying to integrate phpshop, I require access to the session array so I simply Code:

<?php
require_once ($rootDir.'public_html/phpshop/index.php');
?>

View Replies !
Simplifying A Basic If Statement Conditional
Is there a more efficient way to write this:
if($var=1 || $var=4 || $var=27 || $var=28 || $var=30 || $var=37||
$var=38){echo "true";}

View Replies !
Conditional Statement For Default Case
I'm trying to create a conditional statement for my menu that will check to see if the page is on the default case. Code:

View Replies !
Syntax Issue With Form And Conditional Statement
Is it possible for a <form ... action="program.php"> to contain a conditional statement for the action? For example, I want to call one PHP program if variable $a="screen" and another program if variable $a="download". I have been struggling with this for some time and cannot seem to get it to work.

View Replies !
Add A Conditional Statement To My Update Record Form.
I wish to add a conditional statement to my update record form. Basically the form has an image upload feature and I wish to make it so that only if an image is specified should that field be updated, otherwise it should just ignore updating that field. The update code is below:

$updateSQL = sprintf("UPDATE news SET Type=%s, Headline=%s, Poster=%s, Summary=%s, Content=%s, Image=%s, `Date`=%s, Disabled=%s WHERE Id=%s", GetSQLValueString($HTTP_POST_VARS['type'], "int"),
GetSQLValueString($HTTP_POST_VARS['headline'], "text"),
GetSQLValueString($HTTP_POST_VARS['poster'], "text"),
GetSQLValueString($HTTP_POST_VARS['summary'], "text"),
GetSQLValueString($HTTP_POST_VARS['content'], "text"),
GetSQLValueString($HTTP_POST_VARS['image'], "text"),
GetSQLValueString($HTTP_POST_VARS['date'], "date"),
GetSQLValueString(isset($HTTP_POST_VARS['disabled'
]) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($HTTP_POST_VARS['Id'], "int"));

I have tried inserting an if statement around the particular field but this caused the page to flip out and generate errors all over the place.

View Replies !
Conditional Statement - Image Upload Script
I'm pulling my hair out over a conditional statement I just can't seem to get right.
Basically I have a image upload script but I only want to use it if there is an image selected. If this filed is empty then move on to the rest of the code. This is what I have PHP Code:

//if there is a logo
[b]if(!empty($_FILES['vImage'])&& ($_FILES['vImage']!= ''))[/b]{

image upload script here

// now we need to insert into the articles table
insert  data script
}
//if there isn't a logo
else{
just insert data script
}

what is going wrong with my if statement ?

View Replies !
Conditional Statement - Glossary Database (glos) That Can Search The Database
I'm setting up a glossary database (glos) that can search the database for '$sometext' using a form, and then prints out a list of all the words that match with their respective links. The following code works just fine. But if there are no results, I get just a blank page. I would love to get something like "Sorry but your word is not in the database" plus some extra stuff like another form to submit the new word, etc. I just don't know where or how to put in a logic script for if there are no results, do something else. Thanks for any help you can give a php newbie.

<?
$result = mysql_query(
"select * from glos where $word like '%$sometext%' order by word");
while ($i = mysql_fetch_array($result)){
print <<<END
<a href="/definition.php?word={$i['word']}">{$i['word']}</a><br>

END;
}

mysql_close();
?>

View Replies !
Write A Conditional Statement To See If The Current Item In An Array Is The Last Item.
This seems like it would be so simple, but I haven't been able to solve it. I want to write a conditional statement to see if the current item in an array is the last item. I tried

if (count($array) == (current($array))

but that didn't work. count($array) will give me the number of items in the array. What do I use for the current position in the array.

View Replies !
Conditional Select From Mysql
I have a mysql database which stores race data that I want to open up to users for viewing. I want the user to be able to select various subsets of the data according to the parameters: race, gender, age, and type (and maybe sometime, by name as well). This is BOTH a mysql question and a php one, as I ask for a more efficient solution (see bottom this post).

Here is a snippet of how I am implementing the mysql statements to select only the exact subset of data. PHP Code:

View Replies !
Mysql Real Escape String() In Conditional Statements
I created the following bit of code that allows me to pass a MySQL conditional statement to a function.

I am trying to figure out where and how would I go about incorporating the mysql_real_escape_string() function?

Is there a way to call the mysql_real_escape_string() in the function itself? Code:

View Replies !
PHP And MySQL WHERE Statement
I can write simple MySQL stuff in PHP but I'm having problems putting in WHERE clauses. Everytime I do I get errors like this:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:program
filesapache groupapachehtdocsvodmineral_action.php on line 10

The code that generated this crap is: Code:

View Replies !
Php/mysql If Statement
I'm trying to check records in mysql to see if a record exists. and if it does, the date should be more then the current date:

$query=mysql_query("SELECT * FROM BM_Orders WHERE idClient=$_SESSION[user_id] AND end_date > ".date("j/n/Y")."");
if (mysql_num_rows($query) == 0)
{

problem is that the if statement always comes up as false, no matter what the date in the mysql record is. i'm going wrong here?

View Replies !
IF Statement With MySQL
I'm trying to check whether a record exists in the table before I perform an INSERT.
WITH SQL Server you can use an IF statement but is ther a way to do this in MySQL with inline code in PHP?

$sSQL = "IF (SELECT TrackID
FROM TempShoppingBasket
WHERE TrackID = ".$_GET['tid'].") >= 1
THEN
INSERT INTO phpShoppingBasket (SessionID, TrackID, LUpdate)
SELECT '".session_id()."', ".$_GET['tid'].", now()
END IF;";

View Replies !
PHP -> MySQL Insert Statement
heres what i am using : Code:

if (($p1 == $p2) && ($p1 != " ")) {print "accepted";
print "<br>entering you into the database....";
$enter = 'INSERT INTO member(name, psw) VALUES("$name", "$p1")'
$goenter = mysql_query($enter) or die("Entery Failed due to " . mysql_error());}
else {print "<br><font size=+1>Password did not match, try again!</font>";}} ?>


now heres the problem : when it writes to the table (all the db selection etc is fine) all that gets written is : "$name" and "$p1"

literally $name and $p1 *** not their values. I have tried combinations of quotes ( as " " will interpolate but ' ' will not) but still no dice. and w/o the quotes around the values ("$name" , "p1") --- it will return an error stating the colum ($name value) does not exsist.

View Replies !
Run A Sql (select) Statement On A MySQL DB
I am trying to run a sql (select) statement on a MySQL DB, using the sum function...
It keeps returning a value that I know is not correct (in fact it is 1.3356959598149e-315)...

The statment is: Select sum(domain_cost), sum(domain_charge) from table_name;

I know the answer should be about $12,000, but it is clearly not giving me this... Is there a formatting that needs to be included in the statement.

View Replies !
Mysql Query Statement
What I'm trying to do is search a field in mysql, and if it has an _ in the file name, change it to a - instead.  And alos change any capital letters to lower case.

From:  This_is_my_example
To : this-is-my-example

I figure it would be something like: UPDATE 'file'  SET '-' WHERE `filename` LIKE '_'

I"m not really sure how to put a regular expression in there to only replace the underscore put leave the data.

View Replies !
Updating Mysql In WHILE Statement.
What I'm trying to do, is if a condition is met, then update the mysql db. So I have the following:

$server_date = date('U');
$result = mysql_query("SELECT * FROM article
WHERE status LIKE 'notlive' AND date>0");

while($row = mysql_fetch_array($result))
  {
  if ($server_date >= $row['date']) {
  echo "Changed<BR>";
  $query = "UPDATE article SET status = 'live' WHERE status='notlive'";
  mysql_fetch_array($query);}
  }

I know the condition is met since it displays "Changed" twice, but the UPDATe doesn't appear to go through.  Am I able to send an UPDATE in the WHILE statement?

View Replies !
Mysql OR Statement Output
I'm trying to figure out the output statements in one using or's but I need to make sure its the best way to out put it. Code:

View Replies !
MySQL Statement Optimization
I'm reading and loading large data amounts from a text file into my MySQL database. It works fine but it takes way too long for such a simple process, so I was wondering if I am not optimizing my MySQL statements correctly. Here's what I'm dealing with: Code:

View Replies !
MySQL Select Statement
$query = "SELECT DISTINCT albumName FROM fotoPhotos, fotoUsers WHERE fotoPhotos.userid = fotoUsers.id AND fotoUsers.username = ".$username." ORDER BY albumName ASC";

I don't get an error message. The variable $username is set and exists in the database.

But there is something wrong that I cannot fathom.

View Replies !
Mysql Create Statement
create table order_items
(
order_id int unsigned not null references orders(order_id)
)

i undersant everything except the "references orders(order_id)

i know that orders is the orders table but what exactly is it doing?

View Replies !
Mysql Statement Not Working?
I have the following PHP code on a password resetting form Code:

View Replies !
Quote Escaping For MySQL Statement
I'm doing a data migration and used gnumeric to change some big
spreadsheets into .csv files for upload into a MySQL database through php.

It seems to have done fine on my local machine, but it is dying on the
production dB when it encounters a single
quote, e.g. "The Manufacturer's specification ..."
Right there------------------^

magicquotes is On
Is there a handy extra function that can improves a string's chances of
getting into MySQL cleanly?

The setting for the csv export was "Always" (escape-quote everything)

View Replies !
MySQL - Using Expressions In ORDER BY Statement
I am currently teaching myself PHP/MySQL to add functionality to a website showing event listings for an entertainment venue. The events in any day can run from 11am until 3am. I have a search script that will return all events by title, time, date and other criteria and users can click on any column heading in the results to sort by that column.

My problem is the event start time column. Sorting the data using "ORDER BY time" puts the post-midnight shows at the beginning of the list not the end.

Does anyone have any ideas as to how I could adapt the ORDER BY part of the SELECT statement to return the post-midnight shows at the end of the list.

I could presumably sort after deducting 4 hours off every time. Would something like ORDER BY (time-4) work (using simplistic shorthand for the "time-4")? I assume I would have to use the DATE_SUB() command but I am not sure about the format.

The time is currently recorded simply as hh:mm:ss in the MySQL database.

View Replies !
PHP, MySQL, $_GET And If Statement Problem
I am having a issue that I have been working on for the last few days.
I am using PHP 5, MySQL 4.1 and PEAR.

The following code works by itself between <?php and ?tags:

$isbn = $_GET['isbn'];
$sql = "DELETE FROM lounge WHERE isbn = $isbn";
$db->query($sql);
print $sql;

Now, if I put it inside of an If statement, it does not work and I get
a "DB Error: syntax error":

if ($_POST['yes_no'] == 'yes') {
$isbn = $_GET['isbn'];
$sql = "DELETE FROM lounge WHERE isbn = $isbn";
$db->query($sql);
print $sql;
} else {
print "Unable to delete record";
}

This isbn is stored as an INT in MySQL. Does anyone have any ideas?

View Replies !
Switch Statement + Reading From MySQL DB
I have created a templated site, with the use of switch statements [shown below] Anyway, this works fine, accept the person I am doing this for knows little html so what I want to do is be able for him to add new sections easily without doing any HTML, thus the MySQL DB.

But I am stumped what is the best way to do this?? I would be very grateful if someone can help.. PHP Code:

View Replies !
PEAR DB/MySQL Prepared Statement With LIKE
how to create a select statement using PEAR
DB or MySQL with the LIKE function.
That is I am looking of how I can get statement like this work.
SELECT * FROM customer WHERE name LIKE '%?'

View Replies !
Question Regarding A MySQL SELECT Statement
I tried hunting for a MySQL specific NG and didn't find one but I did
see that MySQL questions get asked here. If this isn't appropriate and
you know of an appropriate NG then that would be great.

In one table I have inventory...
table name is "inventory"
columns are..
-----------------------------
item_number item_name
-----------------------------
1 radishes
2 carrots
3 potatoes
4 oranges
etc..etc

Table two is "sold"
------------------------------
date item_number
13Mar 1
14Mar 4
15Mar 2
16Mar 1


What I am querying is the table "sold" for the Unique items (1,4,2)
and then retrieving their names from table 1.

My query below isn't working..
SELECT item_name FROM inventory WHERE inventory.item_number =
sold.item_number;

I am just now starting to get into complicated MySQL queries and
actually the more I learn about it the more I love it.

View Replies !
Trouble MySQL AES_ENCRYPT() Using PHP For SQL Statement
I want to add a binary element (AES_ENCRYPT()) to a $_POST array. I need to
make it binary because it is going into a BLOB field.

$results = $dbr->Execute('select * from table1 where id='.$_GET['id']);
....
// validation take place and now is processed
$_POST["field1"] = $dbr->GetOne('select
AES_ENCRYPT('.trim($_POST['field1']).', 'salt*&)#')');
// there are other $_POST fields that are in cluded in the next line
// GetInsertSQL is a function that eventually calls $dbr->Execute()
$dbr ->GetInsertSQL($results, $_POST, true);
It decrypts most records (field1) but not all. After researching it, I think
the problem lies in how I am adding the encrypted field.

I think I need to make the $_POST["field1"] binary, somehow.

If so, how do I do that?

View Replies !
Using Several Variables In A Mysql Statement In A Php Script
1. asking the user to select a teacher and adding to the hyperlink a variable ($id) to be used in the next page

2. showing a list of classes that teacher gave and ordering them by date or title.

problems:
1. when i try and use variables for the "order by" function (one for $orderby and another for $direction), from some reason the query fails. I think that problem is about the other variable ($id) which is used in the same statement.... when i take that variable off and just enter a static number there is no problem. However trying to use these two or even three variables in the same mysql statement fails. any ideas? Code:

View Replies !
SELECT Statement From MYSQL Table
I have at MYSQL table called "results" w/ the following fields:

tournaments / team / participants / fish / weight / lunker

Lake1 / team1 / participants1 / fish1 / weight1 / lunker1
Lake1 / team2 / participants1 / fish1 / weight1 / lunker1
Lake1 / team3 / / fish2 / weight2 / lunker2
Lake1 / team4 / / fish3 / weight3 / lunker2

Here is some of my code:

View Replies !
Variable As Column Name In MySQL Statement
Let's say db has 4 cols: user id, favorite color, shoe size, hair color. User only has the option of entering 2 variables. 1 has to be user id, 2nd one (radio button) can be color OR size OR hair color.

Depending on what user entered, php should look up user id #, and then locate parameter under variable 2 col (whatever was entered for variable 2: fave color or shoe size or hair color) that belongs to that user id.

View Replies !
Debugging Correct Mysql Statement
"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1" But i have sevral on die statments in my page, is there anyway to try and distinguise which mysql statement it is. I notice the code is or die (mysql_error()) can i put anything inthe () to try and show which error it is like a number, i did try a number but that just errored or is it a simple remove the on die and try again till you find the one thats erroring.

View Replies !
PHP/mySQL Insert Into Statement With Auto Increment
When i use mysql from the linux command line it is just plain simple to add an row into a table, even with php this isn't a problem. But when the table has aan field with auto_increment php won't allow to insert a new row in the table. I'll get an invalid query back.. In don't understand how to insert a new row into a table with the auto increment. Btw this is also the primary key: Code:

View Replies !
Getting Form Info Into A Mysql Select Statement
I'd like to get user input from an html form into a mysql select
statement. Here's where I'm stumped:

$result = mysql_query("SELECT * FROM dept WHERE notes LIKE
'%search-string%'",$db);

I need to get the user's input into the '%search-string%' section, but I
do not understand how to do this. I can hard-code a specific search
string and it will work, but I want the users to be able to dynamically
define the search-string. So, I created a basic html form and used the
post method to grab their input, but now I can't insert that input into
the mysql select statement. Any ideas? I think it should be easy, I just
don't know how to do it. I've tried this:

$result = mysql_query("SELECT * FROM dept WHERE notes LIKE
'%$_POST["search"]%'",$db);

But it doesn't work. Below is the form in html and the php file:

<html>
<title>Search Test</title>
<head>
</head>
<body>
<form action="search-db.php" method="POST">
<p>Enter Your Search: <input type=text name=search></p>
<input type="submit">
</form>
</body>
</html>
-----------------------------------------------------------
<html>
<body>
<?php
$db = mysql_connect("localhost", "Anonymous");
mysql_select_db("computers",$db);
$result = mysql_query("SELECT * FROM dept WHERE notes LIKE
'%surplus%'",$db);
echo "<table border=1>
";
while ($myrow = mysql_fetch_array($result)) {
printf("<tr><td><b>%s</b></td></tr>
", $myrow[notes]);
}
echo "</table>
";
?>
</body>
</html>

View Replies !
MySQL Prepare Statement Performance Bottom-neck
When doing mysql query (SELECT statements) in php, we often use prepare
statement to prevent SQL injection. However, I just noticed that the
prepare statements can SLOW the number of queries per second by a
factor of 2 times (max).

So are there any faster method that can prevent SQL injection, but has
a better performance?

View Replies !
MySQL UNION: Only The First Select Statement Returns A Result.
I am attempting to join multiple select statements into a single query.
However, I am not able to extract the result of any of the UNIONED selects.











$query1 = mysql_query ("
(
SELECT SUM(deposits) AS total_deposits
FROM table1
)

UNION ALL
(
SELECT SUM(withdrawals) AS total_withdrawals
        FROM table1
)
")
or die (mysql_error());

$result1 = mysql_fetch_array($query1);
extract($result1);




When I echo the results of the second select statement I get nothing.


echo  $total_withdrawals;

View Replies !
MYSQL CASE Statement Within PHP Syntax Or Correct Quoting ?
I'm trying to use a MySQL "CASE" statement within PHP to develop a conditional query. The query runs fine within from the MySQL command prompt with the "case" statements. And the PHP code works fine when I remove the lines that begin with "case". However when I run the query as listed below within my PHP code i get the following:


[Fri Apr 20 22:15:24 2007] [error] [client 10.188.50.74] PHP Parse error:  parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /srv/www/htdocs/mysql-learn/acetrack-post.php on line 68, referer: http://webserver1/mysql-learn/acetrack-post.html


< code snip >

$query  ="
SELECT
   acetitle, tracking_no, aceamt,
      case when (To_days(curdate()) - To_days(create_date)) >= 90 Then pototalamt else "" end   as  "90past" ,
      case when (To_days(curdate()) - To_days(create_date)) < 90 and (To_days(curdate()) - To_days(create_date)) > 30 Then pototalamt else "" end  as "30-90past"
     FROM Purtable t
LEFT JOIN acelog a
ON ace=acenum
WHERE ace='0220'
         GROUP by po ASC
         ";

   $result = mysql_query($query);

< /code snip >


Thanks in advance for any help.

View Replies !
Mysql Query Syntax Problem With Join Statement
I'm writing a custom blog script and I want to get the latest blog entry and post it on the front page. I have two tables comments and entries The structure is as follows:

entries: pid (post no), user, time, entrytitle, entry
comments: cid (comment no), pid (no of related post), user, time, comment

I want to retrieve the user,time,entrytitle,entry and the number of associated comments. I've never used JOIN before. Code:

View Replies !
MySQL SELECT Statement - Search A Field In Table
I am trying to search a field in my table for more than one likeness. Can I create a query that says: PHP Code:

<?php

$query = "SELECT * FROM $table WHERE $search_field (LIKE '%$this%) || (LIKE '%$that%')";

?>

OR, should I just do two different query statements and concatenate the results?

View Replies !
Update Statement Causes Mysql Varchar Field To Be Set To Empty String
I have come across a problem that has me baffled.

I am using PHP with MySQL 4.1.14. Whenever I execute an update
statement against a specific table, some of the varchar fields do not
get set to the new values, but get set to empty strings instead.

I have simplified the code down to updating a single column in the
table, but the same results happen when updating just the single
column.

Here is the stripped down code which causes the problem:

$queryString = "UPDATE REGISTRATION SET passwd = '$pass'' WHERE id =
388";
$db = mysql_connect("hostname", "user", "pass");
mysql_select_db("CUSTOMER", $db) or die(mysql_error());
mysql_query($queryString, $db) or die(mysql_error());

Printing the query string after executing mysql_query shows the
following query:

UPDATE REGISTRATION SET passwd = 'test' WHERE id = 388

This query updates the column successfully when run directly through
phpMyAdmin. When run through PHP using the code above then column is
set to an empty string value.

There is no error returned if I call mysql_error() nor is there any
unusual info returned from mysql_info() (other than it telling me that
1 row was affected).

Does anyone have any ideas what the underlying problem is on this one?
Could be an attribute of the database table or columns that would cause
this behavior? I have racked my brain for a while over this problem.

View Replies !
Select Statement - Transfered The Tables To MYSQL From Ms Access Is Not Working
SELECT Attendance.Event, Attendance.Date, Sum(IIf([Name]="tnaril",1,0)) AS Attended
FROM Attendance RIGHT JOIN [Event List] ON Attendance.Event=[Event List].Event
GROUP BY Attendance.Event, Attendance.Date;

I got this working in MS Access. Basically it compares the Event_List.event row, to the Attendance.event row. Filtered by Attendance.name. It puts a 1 if rows match and a 0 if they dont. It works great in MS Access just when I transfered the tables to MYSQL I cant get it to work in PHPMyadmin.

View Replies !
Convert An IF ELSE Statement To A SWITCH CASE Statement?
How do I convert an IF ELSE statement to a SWITCH CASE statement? The switch case below doesn't work.

$textlen = strlen($descr);

if($textlen>10 && $textlen<50) {
$completeness = 1; $deduct = 1000;
}
elseif($textlen>50 && $textlen<100) {
$completeness = 2; $deduct = 500;
}
else {
$completeness = 0; $deduct = 2000;
}

switch($textlen) {
case >10 && < 50: $completeness = 1; $deduct = 1000; break;
case >50 && < 100: $completeness = 2; $deduct = 500; break;
default: $completeness = 0; $deduct = 2000; break;

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved