i need to get a query where the elements are displayed in case the first letter is E (the word is electronics).. i have tried with the following :
mysql_query("select * from nested_category where name like '[A-F]%'");
Is there any way to handle exceptions in sql(ORACLE 9i)?
Since I was trying to divide values of a column that contains both numbers and literals
,I need to fetch out only numbers from it ,as if it divisible by any number then its number else if contains literals it would not get divided it will generate error.
how to handle those errors?
Please suggest!!
here is my query
$sql = 'SELECT *
FROM Orders
INNER JOIN [Order Details] ON Orders.OrderNumber = [Order Details].OrderNumber
WHERE
Orders.CartID =2
AND [Order Details].Option10 Is Null
AND [Order Details].Status="Shipped"';
this queries when entered in MS_Access sql view, returns the correct results,
but when I copy and paste the same query in my php script, it fails and gives the error
Too few parameters, expected 1...
although data is there, query is working in access...
Please note if I omitted on AND condition, it works eg if I removed shipped conidtion or is null condition, it works then too..
any hint? whats wrong with it?? any help?thanks
Tables:
Product: [id, name, brand_id, is_published]
Brand: [id, name, is_published]
Awards: [id, name]
ProductAwards [product_id, award_id]
How do I select the list of PUBLISHED brands along with the number of AWARDS of brand's products that are Published.
I am cool with all the part except issuing the "is_published" restriction when counting Awards.
I hope this is clear; can anyone just suggest where to dig?
I have a query that creates a table view and then another that queries the view. The results are extremely slow.
Here is the code:
create or replace view $view_table_name as select * from wp_2_postmeta where post_id IN (
select ID FROM wp_2_posts wposts
LEFT JOIN wp_2_term_relationships ON (wposts.ID = wp_2_term_relationships.object_id)
LEFT JOIN wp_2_term_taxonomy ON (wp_2_term_relationships.term_taxonomy_id = wp_2_term_taxonomy.term_taxonomy_id)
WHERE wp_2_term_taxonomy.taxonomy = 'category'
AND wp_2_term_taxonomy.parent = $cat || wp_2_term_taxonomy.term_id = $cat
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post')
The $values have been put it in for this example that queries the view table for the results.
select distinct(ID) from $view_table_name wposts LEFT JOIN wp_2_postmeta wpostmeta ON wposts.ID = wpostmeta.post_id WHERE post_status = 'publish' AND ID NOT IN (SELECT post_id FROM wp_2_postmeta WHERE meta_key = '$var' && meta_value = '$value1') AND ID NOT IN (SELECT post_id FROM wp_2_postmeta WHERE meta_key = '$var' && meta_value = '$value2') AND ID NOT IN (SELECT post_id FROM wp_2_postmeta WHERE meta_key = '$var' && meta_value = '$value3') AND postmeta.meta_key = 'pd_form' ORDER BY CASE wpostmeta.meta_value WHEN '$value5' THEN 1 WHEN '$value6' THEN 2 WHEN '$value7' THEN 3 WHEN '$value8' THEN 4 WHEN '$value9' THEN 5 THEN '$value10' THEN 6 WHEN '$value11' THEN 7 WHEN '$value11' THEN 8 END
how to select all the data from many tables?
i try
`"SELECT * FROM `table1`, `table2`"`
,
but result none understandable for me. it returns only some rows from table1, and 3 times all the data from table2. i've red one same question here, but don't understand the answer. so could you help me? thanks in advance.
update:
when i try
(SELECT * FROM `videos`) UNION (SELECT * FROM `users`)
it returns
#1222 - The used SELECT statements have a different number of columns
I have indexes/primaries on all appropriate ID fields for each type. I'm wondering though how I could make this more efficient. It takes a while to load the page with only 15,000 rows and that'll quickly grow to 500k.
The $whereSql variable simply has a few more parameters for the main ebay_archive_listing table.
NOTE: This is all done in a single query because I have ASC/DESC sorting for each subquery value.
NOTE: I've converted some of the sub queries to INNER JOIN's
SELECT
product_master.product_id,
(
SELECT
COUNT(listing_id)
FROM ebay_archive_product_listing_assoc '.$listingCountJoin.'
WHERE ebay_archive_product_listing_assoc.product_id = product_master.product_id) as listing_count,
sku,
type_id,
(
SELECT
AVG(ebay_archive_listing.current_price)
FROM ebay_archive_listing
INNER JOIN ebay_archive_product_listing_assoc ON (
ebay_archive_product_listing_assoc.listing_id = ebay_archive_listing.id AND
ebay_archive_product_listing_assoc.product_id = product_master.product_id
)
WHERE '.$whereSql.' AND
ebay_archive_listing.current_price > 0
) as average_bid_price,
(
SELECT
AVG(ebay_archive_listing.buy_it_now_price)
FROM ebay_archive_listing
INNER JOIN ebay_archive_product_listing_assoc ON (
ebay_archive_product_listing_assoc.listing_id = ebay_archive_listing.id AND
ebay_archive_product_listing_assoc.product_id = product_master.product_id
)
WHERE '.$whereSql.' AND
ebay_archive_listing.buy_it_now_price > 0
) as average_buyout_price,
(
SELECT
MIN(ebay_archive_listing.current_price)
FROM ebay_archive_listing
INNER JOIN ebay_archive_product_listing_assoc ON (
ebay_archive_product_listing_assoc.listing_id = ebay_archive_listing.id AND
ebay_archive_product_listing_assoc.product_id = product_master.product_id
)
WHERE '.$whereSql.' AND
ebay_archive_listing.current_price > 0
) as lowest_bid_price,
(
SELECT
MAX(ebay_archive_listing.current_price)
FROM ebay_archive_listing
INNER JOIN ebay_archive_product_listing_assoc ON (
ebay_archive_product_listing_assoc.listing_id = ebay_archive_listing.id AND
ebay_archive_product_listing_assoc.product_id = product_master.product_id
)
WHERE '.$whereSql.' AND
ebay_archive_listing.current_price > 0
) as highest_bid_price,
(
SELECT
MIN(ebay_archive_listing.buy_it_now_price)
FROM ebay_archive_listing
INNER JOIN ebay_archive_product_listing_assoc ON (
ebay_archive_product_listing_assoc.listing_id = ebay_archive_listing.id AND
ebay_archive_product_listing_assoc.product_id = product_master.product_id
)
WHERE '.$whereSql.' AND
ebay_archive_listing.current_price > 0
) as lowest_buyout_price,
(
SELECT
MAX(ebay_archive_listing.buy_it_now_price)
FROM ebay_archive_listing
INNER JOIN ebay_archive_product_listing_assoc ON (
ebay_archive_product_listing_assoc.listing_id = ebay_archive_listing.id AND
ebay_archive_product_listing_assoc.product_id = product_master.product_id
)
WHERE '.$whereSql.' AND
ebay_archive_listing.current_price > 0
) as highest_buyout_price,
round(((
SELECT
COUNT(ebay_archive_listing.id)
FROM ebay_archive_listing
INNER JOIN ebay_archive_product_listing_assoc ON (
ebay_archive_product_listing_assoc.listing_id = ebay_archive_listing.id AND
ebay_archive_product_listing_assoc.product_id = product_master.product_id
)
WHERE '.$whereSql.' AND
ebay_archive_listing.status_id = 2
) / (
SELECT
COUNT(listing_id)
FROM ebay_archive_product_listing_assoc '.$listingCountJoin.'
WHERE ebay_archive_product_listing_assoc.product_id = product_master.product_id ) * 100), 1) as sold_percent
FROM product_master
'.$joinSql.'
WHERE product_master.product_id IN (
SELECT
product_id
FROM ebay_archive_product_listing_assoc
INNER JOIN ebay_archive_listing ON (
ebay_archive_listing.id = ebay_archive_product_listing_assoc.listing_id AND
'.$whereSql.'
)
)
I read the http://htmlpurifier.org/docs/enduser-youtube.html doc, but I still can't figure out where to put the code to allow object, param and embed tags and Use experimental features with my htmlpurifier. Can someone please show me how to do this?
So, I have created a big website (a lot of text in different files and a lot of programming). I need to add one more language, how should I do? What is the fastest way I can add second language and let my visitors to choose between them? Any ideas?
Thanks.
I can think of a number of ways to do this in PHP or even JavaScript, but I'm wondering if there's a SQL-based technique I'm overlooking.
I have a database table, let's say 20 fields X 10 rows. I want to display the entire table on an web page, so I'd do something like SELCT * FROM data_table;, and then format the result set using HTML table tags.
However, I'd also like to highlight values in the table based on whether they are the maximum or minimum value in their column. For example, I'd add bold tags around the max in each column. A resulting table might look something like this, with bold tags shown:
id | field1 | field2 | field3 | ...
0 | 5 | 2 | <b>7</b> | ...
1 | 3 | <b>8</b> | 6 | ...
2 | <b>9</b> | 5 | 1 | ...
...
I could do a separate SELECT with an ORDER BY for each field and then interpret the results, but that seems like a lot of extra DB access.
My alternative right now is to just fetch the whole table, and then sort/search for the highlight values using PHP.
Is there a better way?
Suppose you have these tables:
Table Name: Salesman
Fields: S_ID(Primary Key), Name
Table Name: Region_1
Fields: Reg_ID(Primary Key), S_ID(Foreign Key), sales
Table Name: Region_2
Fields: Reg_ID(Primary Key), S_ID(Foreign Key), sales
Table Name: Region_3
Fields: Reg_ID(Primary Key), S_ID(Foreign Key), sales
Table Name: Region_4
Fields: Reg_ID(Primary Key), S_ID(Foreign Key), sales
Query 1: Find out total of sales of each salesman in all the regions.
Query 2: Find out total of sales of a particual salesman in all the regions. (if the first one is solved I think this will be easy. :-) )
I've made a couple of scripts. One is a stock screener that can search through every stock. Another creates a heatmap that tells you what's performed well and badly over the past day. They aren't really that useful, just did them to work on my programming skills. I was able to throw some SQL in my scripts too. Would you call that intermediate? Thanks? How do you guys list your programming skills on your resume? Maybe there's a better way of putting it on my resume than "intermediate" or "beginner."
Hi, I'm just wondering how I can retrieve a specific value (only 1 thing will be returned) from a database using php.
My query is
mysql_query("SELECT balance FROM users WHERE username = '". $this->username . "'")
I'm just looking for it to retrieve the data from that row so I can save it directory into a variable.
This may be a completely dumb question, but I've seen a couple examples declaring the variables AFTER putting them in bind_param:
http://devzone.zend.com/article/686
I've never seen this done before and all my programming knowledge says I should define them before hand. Is this a valid/preferred way?
I am planning to make a railway reservation project...
I am maintaining following tables:
trainTable
(trainId,trainName,trainFrom,trainTo,trainDate,trainNoOfBoogies)...PK(trainId)
Boogie
(trainId,boogieId,boogieName,boogieNoOfseats)...CompositeKey(trainId,boogieId)...
Seats
(trainId,boogieId,seatId,seatStatus,seatType)...CompositeKey(trainId,boogieId,seatId)...
user
(userId,name...personal details)
userBooking
(userId,trainId,boogieId,seatId)...
Is this good design?
I'm building a database class and thought it'd be a good idea to incorporate some form of SQL injection prevention (duh!). Here's the method that runs a database query:
class DB
{
var $db_host = 'localhost';
var $db_user = 'root';
var $db_passwd = '';
var $db_name = 'whatever';
function query($sql)
{
$this->result = mysql_query($sql, $this->link);
if(!$this->result)
{
$this->error(mysql_error());
} else {
return $this->result;
}
}
}
There's more in the class than that but I'm cutting it down just for this. The problem I'm facing is if I just use mysql_real_escape_string($sql, $this->link); then it escapes the entire query and leads to a SQL syntax error. How can I dynamically find the variables that need to be escaped? I want to avoid using mysql_real_escape_string() in my main code blocks, i'd rather have it in a function.
Thanks.
I have a table that looks like this:
|StreetName NR| NR |
|Teststreet 34| 34 |
How can i delete only the number in Streetname when it is the same in NR??
Hello there,
Been at this for a few hours now and I can't make any sense of it. I've used this way of selecting multiple values for same column a few times, but there is something weird with this one.
SELECT * FROM employee as s
INNER JOIN works AS w1 ON w1.name = s.name
INNER JOIN employee AS w2 ON w2.name = s.name
INNER JOIN employee AS w3 ON w3.name = s.name
WHERE w2.city = 'Washington'
Basically what I want to do is find all companies which have people in all the cities. The company name is under 'works'. The problem is however that if I have the WHERE w2.city='Washington' it will make ALL the cities match Washington when it should only touch w2 and leave w3 alone so I could match it with another value.
Anyone know why its doing this? Or know a better way to do it.
Thank you very much in advance.
Hello,
i'm using CodeIgniter for developing a community board. As I'm using nested sets to get a nested forum hierarchy, I have to run a lot of queries such as:
SELECT `id` FROM `forums` WHERE 1 BETWEEN `lft` AND `rgt`
My problem: CodeIgniter is replacing the "1" by "`1`" because the "1" is recognized as a column name. Of course, the query does not work any more.
Is there a way to get it working?
thx in advance
I have the following code which produces following output:-
<?
$tablaes = mysql_query("SELECT * FROM members where id='$order[user_id]'");
$user = mysql_fetch_array($tablaes);
$idsd=$user['id'];
$rPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "'");
$hdPaid = mysql_fetch_array($rPaid);
$sPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE user_id='$idsd' AND type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "'");
while ($hPaid = mysql_fetch_array($sPaid)) {
?>
<td><?=$user['username']?></td>
<td><?=$hPaid['total']?></td>
<?
}
?>
</tr>
It appears like this http://dl.dropbox.com/u/14384295/darrenan.jpg
I want same data to appear only once..
Like Username: Vegas and price with him only once.
I'm not sure if this is even a good question or not.
I have a complex query with lot's of unions that searches multiple tables for a certain keyword (user input). All tables in which there is searched are related to the table book.
There is paging on the resultset using LIMIT, so there's always a maximum of 10 results that get withdrawn.
I want an extra column in the resultset displaying the total amount of results found however. I do not want to do this using a seperate query. Is it possible to add a count() column to the resultset that counts every result found?
the output would look like this:
ID Title Author Count(...)
1 book_1 auth_1 23
2 book_2 auth_2 23
4 book_4 auth_.. 23
...
Thanks!
I am current in planning on creating a big database (2+ million rows) with a variety of data from separate sources. I would like to avoid structuring the database around auto_increment ids to help prevent against sync issues with replication, and also because each item inserted will have a alphanumeric product code that is guaranteed to be unique - it seems to me more sense to use that instead.
I am looking at a search engine to index this database with Sphinx looking rather appealing due to its design around indexing relational databases. However, looking at various tutorials and documentation seems to show database designs being dependent on an auto_increment field in one form or another and a rather bold statement in the documentation saying that document ids must be 32/64bit integers only or things break.
Is there a way to have a database indexed by Sphinx without auto_increment fields as the id?
dear all..i have a textfield
<tr>
<td>
<td><input type="text" id="mod"></td>
</td>
</tr>
and a cell
<tr>
<td><div id="value">//i want data show here</div>
</td>
</tr>
beside that, i've a table "settingdata" in database it consist of 2 field:itemdata and remark..
itemdata's value are "UD" and remark's value are "FM=87.5-108.0MHZ"...
what must i do if i want after type "0103UD" at textfield inside
<div id="value"></div>
can show "FM=87.5-108.0mhz"...
Hi All
I am developing a user manager which must control access to the detail view of editable items. At present, when a user clicks 'edit', the application queries the link table to check if a user is currently editing that page, if not, it allows access to the page and then inserts a record into the link table preventing another user from editing the same page at the same time.
My question is what would the best way to handle the removal of records if say a user exists the browser without saving etc, therefore no action to remove the record.
I have a couple of ideas but would like other input before I decide.
BenTheDesigner
I would like to use "ON DUPLICATE KEY UPDATE" in Zend Framework, is this possible?
Example
INSERT INTO sometable (...)
VALUES (...)
ON DUPLICATE KEY UPDATE ...