Table 1 has columns : entry_id user_id ...
Table 2 has columns : entry_id user_id ...
the user_id entry is not always the same so I would like to extract both of them so I can later on compare them in my script
SELECT * FROM
table1 as t1
INNER JOIN table2 as t2 on t1.entry_id=t2.entry_id
WHERE t1.user_id='%s'
I would like to extract t1.user_id and t2.user_id ...the problem is the result array has only user_id
thank you
I've use following code
$con = mysql_connect("localhost","root","");if (!$con) {die('Could not connect: ' . mysql_error());}
It's works. but when
$db_host='localhost';$db_id='root';$db_pass='';
$con = mysql_connect($db_host,$db_id,$db_pass);if (!$con) {die('Could not connect: ' . mysql_error());}
it didn't works, trying to swap ("),('),and empty in mysql_connect() and in $var and vice versa. Any help would be appreciated. Thanks.
Hi!
Is there any lightweight validation library available for PHP that easily can check if a specific string or value is valid for a known database type -
Something like this:
if (is_MEDIUMINT($var)) {
$this->db->insert($anothervar);
}
Thanks!
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
?
Okay I use this script here to make a backup of my database:
mysqldump -u root -h localhost -pPASSWORD forums | gzip -9 > backup-$(date +%Y-%m-%d).sql.gz
This is used in a cron daily.
But I need to download this remotely or through a ftp program every day as well so I have a physical copy of it on my home hard drive, is this possible? I know it is, can anyone tell me a quick way to do it?
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.
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 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
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 ) );
}
I am getting this error when I pass an invalid SQL string... I spent the last hour trying to find the problem assuming - It's not my SQL it must be the db handle... ANyway, I've now figured out that it was bad SQL...
What I want to do is test the result of the mysql_query() for a valid resultset.
I am simply using empty($result)... Is this the most effective test? Is there a more widely accepted method of testing a resultset for a valid result?
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
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?
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
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 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
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?
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)
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);
?>
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 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 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?
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.