Jump to content

using query results in another query


petroz

Recommended Posts

Hi Guys,

 

I am having some troubles with this script. The goal is to get a unique ID from one table, store it as a array, then with another query update a second table using information from the first table all related to that first array created on the first query.

 

I am getting "Parse error: syntax error, unexpected T_STRING" on the first line of the second query.

 

I am pretty knew at this.... so please forgive any stupid mistakes or complete misunderstandings.

 

Thanks,

P

 

<?
include "db.php";
$uid = $_GET['uid'];
$request = $_GET['req'];
$requid = $_GET['requid'];

$getresp = "SELECT resp_uid FROM requests WHERE request = '$req'"; 

$result = mysql_query($getresp) or die(mysql_error());

$row = mysql_fetch_array($result) or die(mysql_error());

$accept = "UPDATE requests2 SET `status` = '$status', `resp_name` = (SELECT `name` FROM `users` WHERE `uid` = '.$row'), `resp_organization` = (SELECT `organization` FROM `users` WHERE `uid` = '.$row'), `resp_email` = (SELECT `email` FROM `users` WHERE `uid` = '.$row'), `resp_phone` = (SELECT `phone` FROM `users` WHERE `uid` = '.$row'), `resp_url` (SELECT `email` FROM `users` WHERE `uid` = '.$row'), `resp_im` = (SELECT `im` FROM users WHERE `uid` = '.$row'),  `resp_address` = (SELECT `address` FROM `users` WHERE `uid` = '.$row')";  

$acceptresult = mysql_query($accept) or die(mysql_error());
?>

Link to comment
https://forums.phpfreaks.com/topic/176225-using-query-results-in-another-query/
Share on other sites

with the way you've got it you're missing some quotes and some concatenation and the keys for $row, and a couple of equals

$accept = "UPDATE requests2 SET `status` = '".$status."', `resp_name` = (SELECT `name` FROM `users` WHERE `uid` = '".$row['resp_uid']."'), `resp_organization` = (SELECT `organization` FROM `users` WHERE `uid` = '".$row['resp_uid']."'), `resp_email` = (SELECT `email` FROM `users` WHERE `uid` = '".$row['resp_uid']."'), `resp_phone` = (SELECT `phone` FROM `users` WHERE `uid` = '".$row['resp_uid']."'), `resp_url`= (SELECT `email` FROM `users` WHERE `uid` = '".$row['resp_uid']."'), `resp_im` = (SELECT `im` FROM users WHERE `uid` = '".$row['resp_uid']."'),  `resp_address` = (SELECT `address` FROM `users` WHERE `uid` = '".$row['resp_uid']."')";  

But...I would use a join for the first query

$getresp = "
SELECT 
users.name, 
users.organization, 
users.email,
users.phone,
users.email as url, 
users.im, 
users.address
FROM 
requests JOIN users on requests.resp_uid=users.uid 
WHERE 
resp_uid.request = '$req'
"; 

then

$result = mysql_query($getresp) or die(mysql_error());
while($row=mysql_fetch_array($result)) 
{
$accept="UPDATE requests2 SET `status` = '".$status."', `resp_name` = '".$row['name']."'), `resp_organization` = '".$row['organization']."', `resp_email` = '".$row['email']."', `resp_phone` = '".$row['phone']."', `resp_url`='".$row['url']."', `resp_im` = '".$row['im']."',  `resp_address` = '".$row."' where uid='".$row['uid'];  
}

you'll need to double check me,  some of the column names and keys might be wrong.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.