Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-02-16, 08:56 PM
Junior Member
 
Join Date: Feb 2006
Posts: 4
timgraham
Default

Is it possible to filter a recordset using a PHP variable.
I have tried to do this below, without success. The PHP variable is created from the first recordset, then I need to filter the second recordset with the new variable. I used the Dreamweaver option "filter by server variable". Is this the way to do it ?

Thanks For reading


$colname_find_user = "-1";
if (isset($_GET['cm'])) {
$colname_find_user = (get_magic_quotes_gpc()) ? $_GET['cm'] : addslashes($_GET['cm']);
}
mysql_select_db($database_mx_shop, $mx_shop);
$query_find_user = sprintf("SELECT * FROM order_ord WHERE id_ord = '%s'", $colname_find_user);
$find_user = mysql_query($query_find_user, $mx_shop) or die(mysql_error());
$row_find_user = mysql_fetch_assoc($find_user);
$totalRows_find_user = mysql_num_rows($find_user);

$user_id = $row_find_user['userid_ord'];

$colname_old_credits = "-1";
if (isset($_SERVER['$user_id'])) {
$colname_old_credits = (get_magic_quotes_gpc()) ? $_SERVER['$user_id'] : addslashes($_SERVER['$user_id']);
}
mysql_select_db($database_connblog, $connblog);
$query_old_credits = sprintf("SELECT * FROM tbl_users WHERE int_user_id = %s", $colname_old_credits);
$old_credits = mysql_query($query_old_credits, $connblog) or die(mysql_error());
$row_old_credits = mysql_fetch_assoc($old_credits);
$totalRows_old_credits = mysql_num_rows($old_credits);
Reply With Quote
  #2 (permalink)  
Old 2006-03-14, 03:50 PM
Member
 
Join Date: May 2003
Posts: 47
barand
Default

When you are looking up a value with one query then using that value in the WHERE clause of a second query the same result can usually be achieved with a single, joined query

Code:
$sql = "SELECT COUNT(*) as numcreds
    FROM order_ord o INNER JOIN tbl_users u
    ON o.userid_ord = u.int_user_id
    WHERE io.d_ord = '$colname_find_user' ";
$result = mysql_query($sql) or die(mysql_error());
$totalRows_old_credits = mysql_result($result, 0, 'numcreds');
__________________
Barand
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:32 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.