Jump to content


struggling with Sql query - php

  • Please log in to reply
2 replies to this topic

#1 gabrielkolbe

  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 14 March 2006 - 05:37 PM

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.............

$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>
<? } else {

$propid = $row->prop_ID;
$type = $row->type;
$suburb = $row->suburb;
$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)) {

$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>
<? $row_count++; } } ?>

The Devil never lies..he just almost tell the truth

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 14 March 2006 - 08:04 PM

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?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 keeB

  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 14 March 2006 - 08:09 PM

SELECT * FROM right_prop_1 rp1
INNER JOIN stats s on s.propID = rp1.propID
WHERE rp1.user_id = '".$_SESSION['index']."'

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

Come visit my site to see my latest projects

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users