Jump to content

Archived

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

gabrielkolbe

struggling with Sql query - php

Recommended Posts

Hi, i would appreciate if someone can just have a look at this and tell me where, I am going wrong.....I am trying to get a prop_ID from a table called right_prop_1, then use this ID to query a 'stats' table. The combine the info from both tables in rows that gets echoed out.

Here is the code:

thanks in advance.............

[code]$query = "SELECT * FROM right_prop_1 WHERE user_id = '".$_SESSION['index']."'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) == 0) {
?>
        <tr bordercolor="#FFFFFF">
        <td class="menu_names" bgcolor= "<?=$row_color?>" colspan=5 >&nbsp;You have no visited Properties at this time</td>
        </tr>
<? } else {

$propid = $row->prop_ID;
$type = $row->type;
$suburb = $row->suburb;
$price1=$row->price;
$price = number_format($price1);



$query = "SELECT * FROM stats  WHERE propid = '".$prop_ID."' order by propid asc limit ".$page.", 30";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_object($result)) {
$visited=mysql_num_rows($result);

$row_color = ($row_count % 2) ? $color1 : $color2;
    ?>
    <tr bgstyle="color:#FFFFFF">
    <td width="20%" bgcolor= "<?=$row_color?>" class="menu_names">&nbsp;Refno:&nbsp;<span class="blacktahoma"><?=$prop_ID?></span></td>
    <td width="10%" bgcolor= "<?=$row_color?>" class="menu_names"><?=$type?></td>
    <td width="16%" bgcolor= "<?=$row_color?>" class="blacktahoma">R<?=$price?></td>
    <td width="20%" bgcolor= "<?=$row_color?>" class="menu_names"><?=$suburb?></td>
    <td width="17%" align="left" bgcolor= "<?=$row_color?>" class="menu_names">Viewed &nbsp;&nbsp;<?=$visited?></td>
    <td width="17%" bgcolor= "<?=$row_color?>" class="menu_names"><div align="right"><a href="index.php?action=detailstats&prop_ID=<?=$row->prop_ID?>">View details</a></div></td>
    </tr>
<? $row_count++; } } ?>
</table>[/code]

Share this post


Link to post
Share on other sites
As I don't have your db to run the script, what is it doing that it shouldn't?. Alternatively, what is not doing that it should?

Share this post


Link to post
Share on other sites
[code] SELECT * FROM right_prop_1 rp1
INNER JOIN stats s on s.propID = rp1.propID
WHERE rp1.user_id = '".$_SESSION['index']."'
[/code]

1 SQL Statement.. all fields joined.. just for you! [=

Share this post


Link to post
Share on other sites

×

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.