Hello. I'm currently developing an URL shortening service. I want to allow users to see the stats for their URLs. How has to be the table.
First, it has to be the url ID, but then, how I can sort the clicks per day?
Hi,
I have the following table:
bar_id, bar_name, subscription_id_fk, sub_name
eg:
1, Hard Rock, 2, Gold
2, TGIF, 1, Free
Now I need and SQL to extract this table, but where sub_name = Gold, I need to double the subscription_id_fk.
Can you please help
?
I'm trying to find 2 different result via JOINS.
Table look like;
SELECT id,member_id,registered_year FROM records;
I can listing which members registered in 2012 and also in 2013 with;
SELECT member_id FROM records a
INNER JOIN records b ON a.member_id=b.member_id
WHERE a.registered_year='2013' AND b.registered_year='2012';
But I can't list revers of It. How can I list which members were registered in 2012 but not in 2013?
Thnx in advance.
By default, parent_id = 0. I want to select all records with parent_id = 0 and only the last ones with parent_id 0.
I tried this, but it didn't work:
SELECT * FROM `articles`
IF `parent_id` > 0 THEN
GROUP BY `parent_id`
HAVING COUNT(`parent_id`) >= 1
END;
ORDER BY `time` DESC
What could be the solution?
Is there an easy way to dump an array returned from mysql_fetch_row into a CFArray? (part of the PHP implementation of CFPropertyList)
I'm bummed by the lack of documentation on CFPropertyList for PHP.
Iterating through each item in the array seems inefficient. I'm open to using a different mysql_fetch_... command.
I'd like to just say:
$NewArray = new CFArray( $ResultArray )
But that deosn't seem to work.
This is my current code:
$plist = new CFPropertyList();
$ResultRow = mysqli_fetch_row( $result );
$plist-add( $TableRow = new CFArray() );
foreach ( $ResultRow as $Item ){
$TableRow-add( new CFString( $Item ) );
}
hi
i have 2 tables
table items has 144602 records
table A has 27721 records
code in items = BAR8 in A
i want to show all records that equal
i try this: SELECT Items.Code, A.BAR8
FROM Items INNER JOIN A ON Items.Code = A.BAR8;
and i get 28048 records !!! i need to get 27721 , how to do it ?
thank's in advance
I have four tables
TableA:
id1
id2
id3
value
TableB:
id1
desc
TableC:
id2
desc
TableD:
id3
desc
What I need to do is to check if all combinations of id1 id2 id3 from table B C and D exist in the TableA. In other words, table A should contain all possible combinations of id1 id2 and id3 which are stored in the other three tables.
I want to remove password for user root in localhost how can I do that?by mistake I have set the password of root user thats why phpmyadmin is giving error-
#1045 - Access denied for user 'root'@'localhost' (using password: NO)
in my forum i have threads and replies.
one thread has multiple replies. but then, a reply can be a reply of an reply (like google wave). because of that a reply has to have a column "reply_id" so it can point to the parent reply. but then, the "top-level" replies (the replies directly under the thread) will have no parent reply.
so how can i fix this? how should the columns be in the reply table (and thread table).
at the moment it looks like this:
threads:
id
title
body
replies:
id
thread_id (all replies will belong to a thread)
reply_id (here lies the problem. the top-level replies wont have a parent reply)
body
what could a smart design look like to enable reply a reply?
i know that if you create a foreign key on a field (parent_id) in a child table that refer to a parent table's primary key (id), then if this parent table is deleted the child class will be deleted as well if you set onDelete to cascade when creating the foreign key in the child class.
but what happens if i set it to onUpdate = cascade?
i have date in dd/mm/yyyy format. how can i store it in databse, if i fant to do some operations on them after?
for example i must find out the rows, where date > something
what type i must set to date field?
thanks
SELECT
u.userid, u.username,
(SELECT count(*) FROM attachment as a WHERE a.userid=u.userid) as amount
FROM
user
WHERE
AND u.usergroupid=10
ORDER BY amount DESC
SELECT categories.*, COUNT(categoryID) AS kritCount
FROM categories AS categories
LEFT JOIN krits ON categories.id = categoryID
WHERE (krits.approved = '1')
GROUP BY categories.id
So this works great except that it does not return a category that has a 0 count of krits in the category.
It will if I remove the WHERE statement but I need the WHERE to only select the krits where the field approved = 1
Given an object like this:
var obj = {
first:{
second:{
third:'hi there'
}
}
};
And a key like this "first.second.third"
How can I get the value of the nested object "hi there"?
I think maybe the Array.reduce function could help, but not sure.
I have a large list of phrases / quotes / sentences in a text file. Mixed alphanumeric text, it hasn't been screened for "'s or ''s.
Is there an easy way to throw this into a table?
I'm not sure exactly why this happened, but I'm assuming it was an dump and import. The db is full of characters like — for commas and such. I've tried various solutions on the web, but nothing seems to work. I've verified that the html header specifies utf8.
Any ideas on how I can get the entire db back to normal characters?
I have a problem in the code.i have two tables 'sms' and 'bd_paid_bribe'.sms table has a column 'Message' and bd_paid_bribe table has a column 'c_addi_info'.when i execute the code first time all the values of Message column are inserted into c_addi_info column.when i enter a record for the second time instead of inserting the new record, all the records of Message column are inserted into bd_paid_bribe column.can u modify the code and provide a solution to avoid duplication and to insert only the newly added record.
<?php
$con=mysql_connect('localhost','root','');
if(!$con)
{
die("couldn't connect");
}
mysql_select_db("ipab2",$con);
$rs2=mysql_query(" select max(sms_index) from tab3");
do
{
$rs=mysql_query("insert into tab3(sms_index)select max(sms_index) from sms");
$rs3=mysql_query("SELECT max(sms_index) FROM sms");
$rs1=mysql_query("insert into bd_paid_bribe(c_addi_info) select
Message from sms ");
}while($rs2>$rs3);
?>
What I have:
key data
1 22
1 5
2 6
3 1
3 -3
What I want:
key data
1 27
2 6
3 -2
I don’t mind doing this with two or more queries, esp. if they are simple--makes for easier maintenance. Also the tables are fairly small (<2,000 records). The ‘key’ field is indexed and allows duplicates.
Muchas Gracias
This is for an upcoming project. I have two tables - first one keeps tracks of photos, and the second one keeps track of the photo's rank
Photos:
+-------+-----------+------------------+
| id | photo | current_rank |
+-------+-----------+------------------+
| 1 | apple | 5 |
| 2 | orange | 9 |
+-------+-----------+------------------+
The photo rank keeps changing on a regular basis and this is the table that tracks it:
Ranks:
+-------+-----------+----------+-------------+
| id | photo_id | ranks | timestamp |
+-------+-----------+----------+-------------+
| 1 | 1 | 8 | * |
| 2 | 2 | 2 | * |
| 3 | 1 | 3 | * |
| 4 | 1 | 7 | * |
| 5 | 1 | 5 | * |
| 6 | 2 | 9 | * |
+-------+-----------+----------+-------------+ * = current timestamp
Every rank is tracked for reporting/analysis purpose.
I talked to someone who has experience in this field and he told me that storing ranks like above is the way to go. But I'm not so sure yet.
The problem here is data redundancy. There are going to be tens of thousands of photos. The photo rank changes on a hourly basis (many time within minutes) for recent photos but less frequently for older photos. At this rate the table will have millions of records within months. And since I do not have experience in working with large databases, this makes me a little nervous.
I thought of this:
Ranks:
+-------+-----------+--------------------+
| id | photo_id | ranks |
+-------+-----------+--------------------+
| 1 | 1 | 8:*,3:*,7:*,5:* |
| 2 | 2 | 2:*,9:* |
+-------+-----------+--------------------+ * = current timestamp
That means some extra code in PHP to split the rank/time (and sorting) but that looks OK to me.
Is this a correct way to optimize the table for performance? What would you recommend?
Any suggestions would be great.
Hi, I'm creating a newsletter.
Each email contains a link for editing your subscription:
<%= edit_user_url(@user, :secret => @user.created_at.to_i) %>
:secret = @user.created_at.to_i prevents users from editing each others profiles.
def edit
@user = user.find(params[:id])
if params[:secret] == @user.created_at.to_i
render 'edit'
else
redirect_to root_path
end
end
It doesn't work - you're always redirected to root_path.
It works if I modify it like this:
def edit
@user = user.find(params[:id])
if params[:secret] == "1293894219"
...
1293894219 is the "created_at.to_i" for a particular user.
Do you have any ideas why?
How do I drop selected tables in Rails? I want to drop all tables from a database with a given prefix. PHPMyAdmin would be very useful at this point.
Thanks
I've a table with a datetime (format: 'Y-m-d H:i:s') 'created' field and 'amount' (integer) field in each row. Now I want to find out total 'amount' in last year month wise. How can I do this?
EDIT
I made an edit to clarify the actual problem.
hey guys
i record number of queries of my website and in page the below script runs , 40 extra queries added to page .
how can I change this sql connection into a propper and light one
function tree_set($index)
{
//global $menu; Remove this.
$q=mysql_query("select id,name,parent from cats where parent='$index'");
if(mysql_num_rows($q) === 0)
{
return;
}
// User $tree instead of the $menu global as this way there shouldn't be any data duplication
$tree = $index > 0 ? '<ul>' : ''; // If we are on index 0 then we don't need the enclosing ul
while($arr=mysql_fetch_assoc($q))
{
$subFileCount=mysql_query("select id,name,parent from cats where parent='{$arr['id']}'");
if(mysql_num_rows($subFileCount) > 0)
{
$class = 'folder';
}
else
{
$class = 'file';
}
$tree .= '<li>';
$tree .= '<span class="'.$class.'">'.$arr['name'].'</span>';
$tree .=tree_set("".$arr['id']."");
$tree .= '</li>'."\n";
}
$tree .= $index > 0 ? '</ul>' : ''; // If we are on index 0 then we don't need the enclosing ul
return $tree;
}
i heard , this can be done by changing it into an array , but i don't know how to do so
thanks in advance