Page 1 of 1
[Solved] Help with my query string
Posted: Wed Aug 17, 2005 7:32 pm
by Addos
If I run this
Code: Select all
<?php echo nl2br($row_getProperties['properties_idpk']); ?>
I get the correct value of the number 2 returned.
I’m then trying to pass a value to the following but without success and I wonder if it is possible or am I simply getting the syntax wrong. I have tried various ways but most keep throwing different errors.
Code: Select all
$query_rstThumbs = sprintf("SELECT * FROM images WHERE idpk = $row_getProperties['properties_idpk']", $colname_rstThumbs);
Thanks for any help.
B
Posted: Wed Aug 17, 2005 8:19 pm
by feyd
try
Code: Select all
$query_rstThumbs = sprintf("SELECT * FROM images WHERE idpk = '{$row_getProperties['properties_idpk']}'", $colname_rstThumbs);
with that said, sprintf() doesn't seem like it's a best fit for that query unless $row_getProperties['properties_idpk'] is like %s or something that'd use $colname_rstThumbs..
Posted: Thu Aug 18, 2005 3:18 am
by Addos
Thanks for your help it’s much appreciated.
I have tried what you suggested but it didn’t work and I even removed sprintf() as I actually can get away without this and tried this -
Code: Select all
$query_rstThumbs = "SELECT * FROM images WHERE idpk = '{$row_getProperties['properties_idpk']}'";
but nothing returns the value I want. If I simply try replacing
Code: Select all
{$row_getProperties['properties_idpk']}
with a number i.e. 1 it gives me the desired output in my browser.
I will happily post all the code if necessary but maybe this is sufficient for more help for the moment.
Thank you again
B
Posted: Thu Aug 18, 2005 3:31 am
by s.dot
Code: Select all
$query_rstThumbs = "SELECT * FROM images WHERE idpk = '".$row_getProperties['properties_idpk']."'";
If that doesn't work.. use the same query and echo it to your browser
Code: Select all
$query_rstThumbs = "SELECT * FROM images WHERE idpk = '".$row_getProperties['properties_idpk']."'";
echo $query_rstThumbs;
See if it's giving you what you think it should be giving you.
Posted: Thu Aug 18, 2005 3:42 am
by Addos
Still no luck with this. Here are a few of my results. If I echo
Code: Select all
<? echo $row_getProperties['properties_idpk'];?>
the output is 1 which I expect so I know that this is returning a value.
Code: Select all
$query_rstThumbs = "SELECT * FROM images WHERE idpk = '".$row_getProperties['properties_idpk']."'";
Result
SELECT * FROM images WHERE idpk = ''
This works if I hand code it in that I get the correct output in the browser but for some reason I can seem to pass this through a variable.
Code: Select all
$query_rstThumbs = "SELECT * FROM images WHERE idpk = 1";
Result
SELECT * FROM images WHERE idpk = 1
Thanks very much
B
Posted: Thu Aug 18, 2005 3:58 am
by s.dot
Hrm, I really do not know why that wouldn't work. Perhaps set it equal to a single variable
Like:
Code: Select all
$var = $row_getProperties['properties_idpk'];
$query_rstThumbs = "SELECT * FROM images WHERE idpk = '$var'";
Posted: Thu Aug 18, 2005 4:02 am
by Jean-Yves
Try the $var without the single quotes around it. Since it's an integer, it should not need it.
EDIT: Mind you, it should make no difference. I can't see why it would not work either, to be honest.
Posted: Thu Aug 18, 2005 4:23 am
by Addos
Ok I got this sorted but I’m probably showing up my in experience but I simply moved
Code: Select all
mysql_select_db********** **********);
$query_rstThumbs = "SELECT * FROM images WHERE idpk = '".$row_getProperties['properties_idpk']."'";
$rstThumbs = mysql_query($query_rstThumbs, $appartments) or die(mysql_error());
$row_rstThumbs = mysql_fetch_assoc($rstThumbs);
$totalRows_rstThumbs = mysql_num_rows($rstThumbs);
To below this in stead of the other way round!
Code: Select all
$query_getProperties = "SELECT * FROM properties, locations, bedrooms
WHERE properties.properties_idpk = bedrooms.bedrooms_idpk
And properties.locations_idfk = locations.locations_idpk";
if ($_POST['bedrooms_idpk']) {
$query_getProperties .= ' AND properties.bedrooms_idfk >= ' .stripslashes($_POST['bedrooms_idpk']);
}
if ($_POST['locations_idpk']) {
$query_getProperties .= ' AND locations.locations_idpk = ' .$_POST['locations_idpk'];
}
$getProperties = mysql_query(******** **********) or die(mysql_error());
$row_getProperties = mysql_fetch_assoc($getProperties);
$totalRows_getProperties = mysql_num_rows($getProperties);
and then the value was passed. I obviously didn’t realise the order of the code was this important but maybe you can enlighten me if it is.
Thanks again for all you time.
B
Posted: Thu Aug 18, 2005 8:03 am
by feyd
if you did what I suspect, that's a fairly common starting mistake, I'd imagine a lot of us here have done it.

Posted: Thu Aug 18, 2005 8:56 am
by Addos
Thanks a mil.
Much apprecated and another lesson learnt!
