Re: onclick event..for real estate listing page.

Discussion in 'PHP' started by noelde, Mar 31, 2007.

  1. #1
    This should be doable, right?

    I have a mysql table (‘tb_content’) that has a record for each real estate property listing

    A web page (‘properties.php’) renders data (property details) that are stored in the table tb_content for one of the listings (‘123 xyz Street’). The query that pulls the page content from the mysql table for the properties.php page is something to the effect of (please excuse the butchering…the code is conceptual)

    If (isset($_SESSION[‘recordid’])) {
    $recordid=$_SESSION[‘recordid’];
    $sql=SELECT * FROM tb_content WHERE prop_id=$recordid;
    And so on…
    } else {
    //this is the default property
    $sql=SELECT * FROM tb_content WHERE featuredproperty=’-1’;
    While…mysql_fetch_array()
    $recordid = $row[‘prop_id’];
    $_SESSION[‘recordid’]= $recordid;
    And so on.
    }
    On properties.php, there is a small section that lists a series of hrefs that represent the rest of the addresses for the other records in tb_content (‘109 Lowe Street’ ‘456 xyz Street’ ‘123 abc Street’ etc…..)

    Shouldn’t there be a way to have the user click on any one of the hrefs, have the associated prop_id (field name in the table tb_content) would replace the value in $_SESSION[‘recordid’], the page properties.php would re-render, but with the new desired property details?

    I’ve been failing miserably with everything I’ve tried.

    I could really use some help.
     
    noelde, Mar 31, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    I wonder why you're working with sessions at all? Passing the variable via $_GET seems way more appropriate in your case.
     
    nico_swd, Mar 31, 2007 IP
  3. noelde

    noelde Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    On top of my my page do I do a $_GET(['recordid'])? and then use $recordid in the query?
     
    noelde, Mar 31, 2007 IP
  4. noelde

    noelde Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    newbies must be fun to watch, I bet. Or frustrating....
     
    noelde, Mar 31, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Here an example.
    
    if (isset($_GET['recordid']))
    {
    	$sql = "SELECT * FROM tb_content WHERE prop_id = ". intval($_GET['recordid']);
    }
    else
    {
    	$sql = "SELECT * FROM tb_content WHERE featuredproperty = 1";
    }
    
    $result = mysql_query($sql) OR die( mysql_error() );
    
    while ($row = mysql_fetch_array($result))
    {
    	echo "<a href=\"test_loop_hrefs.php?recordid={$row['prop_id']}\">Click Here</a><br />\n";
    }
    
    PHP:
     
    nico_swd, Mar 31, 2007 IP