SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ez one 4u... confused over: THIS->

    just a moment of your time please. I'm a novice and am changing someone else's code to suit me. my problem is this: I need to pull one extra field out of this guys DB table query - and use this extra field ($couple_id) in a query of my own. it is partially working. I am getting the $couple_id, but query is not working right as the value has been changed by wordwrap function.

    his query:
    $q = $this->queryEngine("select *, date_format(created, '%b %e, %Y ".LANG_14." %l:%i %p') as `created2` from ".DB_TABLE." where parent = '$board2' order by date asc",$this->dbo);

    then here is where he gets his stuff: my code has comments:
    while($d = $this->dbo->spiderFetchArray($q))
    {

    foreach($d as $key => $val)
    {
    $$key = htmlentities(stripslashes($val));

    if($key != 'parent' && $key != 'user' && $key != 'bid' && $key != 'created')
    {
    $$key = '<p>'.str_replace("\n", "</p><p>", $$key).'</p>';
    } // end of IF key != parent, user, bid, and created
    } // end of FOREACH

    $post = preg_replace("/<p>\s<\/p>/i", "<p>&nbsp;</p>", $post);
    $origpost = $post;
    $post = $this->replaceCode($post,"quote","div","","quote");
    $post = $this->replaceCode2($post,$tag='you',$tag2='',$style='');
    $post = $this->replaceCode2($post,$tag='img',$tag2='img',$style='');
    $post = $this->replaceCode2($post,$tag='url',$tag2='a',$style='');
    $post = $this->replaceCode2($post,$tag='b',$tag2='strong',$style='');
    $user = wordwrap($user, 16, "<br />", 1);
    $post = wordwrap($post, 70, "<br />", 1);
    // $couple_num = $this->$couple_id; // did not work!
    $couple_num = wordwrap($couple_id, 16, "<br />", 1); // does echo right but my query does not like it!
    echo "Couple id is: " . $couple_num;


    my query:
    $query = "SELECT * FROM $activity WHERE member_id = '$couple_num' LIMIT 1";
    $info_remote = mysql_query($query);
    if ($records_found > 0) { do some stuff... }
    else {$message_text = "no activity found.";}

    the code above echos the value for $couple_id - GOOD, but the query returns no records found. can you please tell me what is wrong with my attempt: $couple_num = $this->$couple_id; // did not work!

    many thanks in advance! will return in a few hours.

  2. #2
    SitePoint Enthusiast rajeev13's Avatar
    Join Date
    Nov 2012
    Location
    New Delhi,India
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by m300zx View Post
    just a moment of your time please. I'm a novice and am changing someone else's code to suit me. my problem is this: I need to pull one extra field out of this guys DB table query - and use this extra field ($couple_id) in a query of my own. it is partially working. I am getting the $couple_id, but query is not working right as the value has been changed by wordwrap function.

    his query:
    $q = $this->queryEngine("select *, date_format(created, '%b %e, %Y ".LANG_14." %l:%i %p') as `created2` from ".DB_TABLE." where parent = '$board2' order by date asc",$this->dbo);

    then here is where he gets his stuff: my code has comments:
    while($d = $this->dbo->spiderFetchArray($q))
    {

    foreach($d as $key => $val)
    {
    $$key = htmlentities(stripslashes($val));

    if($key != 'parent' && $key != 'user' && $key != 'bid' && $key != 'created')
    {
    $$key = '<p>'.str_replace("\n", "</p><p>", $$key).'</p>';
    } // end of IF key != parent, user, bid, and created
    } // end of FOREACH

    $post = preg_replace("/<p>\s<\/p>/i", "<p>*</p>", $post);
    $origpost = $post;
    $post = $this->replaceCode($post,"quote","div","","quote");
    $post = $this->replaceCode2($post,$tag='you',$tag2='',$style='');
    $post = $this->replaceCode2($post,$tag='img',$tag2='img',$style='');
    $post = $this->replaceCode2($post,$tag='url',$tag2='a',$style='');
    $post = $this->replaceCode2($post,$tag='b',$tag2='strong',$style='');
    $user = wordwrap($user, 16, "<br />", 1);
    $post = wordwrap($post, 70, "<br />", 1);
    // $couple_num = $this->$couple_id; // did not work!
    $couple_num = wordwrap($couple_id, 16, "<br />", 1); // does echo right but my query does not like it!
    echo "Couple id is: " . $couple_num;


    my query:
    $query = "SELECT * FROM $activity WHERE member_id = '$couple_num' LIMIT 1";
    $info_remote = mysql_query($query);
    if ($records_found > 0) { do some stuff... }
    else {$message_text = "no activity found.";}

    the code above echos the value for $couple_id - GOOD, but the query returns no records found. can you please tell me what is wrong with my attempt: $couple_num = $this->$couple_id; // did not work!

    many thanks in advance! will return in a few hours.

    i m new to php but want to ask a question ,why u r assigning $couple_id to another variable if it is available to this Code block.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rajeev13 View Post
    i m new to php but want to ask a question ,why u r assigning $couple_id to another variable if it is available to this Code block.
    it's a long & ugly story dude... and not relevant to my issue. which is: how the hell do I pull couple_id out of the query without wordwrapping it? why does this line: $couple_num = $this->$couple_id; not work PLEASE???

  4. #4
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by m300zx View Post
    it's a long & ugly story dude... and not relevant to my issue. which is: how the hell do I pull couple_id out of the query without wordwrapping it? why does this line: $couple_num = $this->$couple_id; not work PLEASE???
    Try $this->couple_id; (without the extra '$').

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Wouldn't the existence of
    PHP Code:
    $$key htmlentities(stripslashes($val)); 
    Mean that you could just simply use?
    PHP Code:
    $couple_num $couple_id
    Otherwise, I think this would still work too
    PHP Code:
    $couple_num $d['couple_id']; 

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Wouldn't the existence of
    PHP Code:
    $$key htmlentities(stripslashes($val)); 
    Mean that you could just simply use?
    PHP Code:
    $couple_num $couple_id
    Otherwise, I think this would still work too
    PHP Code:
    $couple_num $d['couple_id']; 
    OTHERWISE: $couple_num = $d['couple_id']; works perfectly. thanks a million cpradio!! us rookies really appreciate you guys generous help. have a great day :-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •