How to add dynamic title to members's profiles

Discussion in 'PHP' started by jennypretty, Oct 18, 2007.

  1. #1
    Hello,

    I have a dating site http://www.usmatch.info, I like to add different dynamic titles to each profile that contain members' usernames, age, etc. so that when viewing each profile, it shows title on the browser.

    On the home page (index.php), I use the template file (template.php) to get the website header, footer.

    On my main template page, I added
    <title><!-- IF "view_profile" -->{username_value},{age_value}<!-- ENDIF --> | {title}</title>

    Where view_profile.php is the member detail page.
    username_value & age_value are field names.

    but when viewing on browser, it shows the actual useraname and age but it lists {username_value},{age_value} on the title.

    What did I do wrong?

    I attached 2 files.

    Please help me.

    Thanks,

    Jenny.
     

    Attached Files:

    jennypretty, Oct 18, 2007 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #2
    As far as I can see you didn't use any template engine, outputting just with pure PHP? So why you inserted a code with such a syntax?
    If you use no Smarty etc. you need to embed php chunks into your HTML. I.e. to output var you can insert
    <?php echo $var; ?>
    PHP:
    or
    <?=$var?> //(short, but not recommended by PHP gurus)
    PHP:
    For conditional blocks in HTML you can use constructions like this:
    <?php if ($cond) { ?>
    <b>Cond is true</b>
    <?php } else { ?>
    <b>Cond is false</b>
    <?php } ?>
    PHP:
     
    wmtips, Oct 18, 2007 IP
  3. jennypretty

    jennypretty Active Member

    Messages:
    584
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Yes. I do not use any Engine or Smarty.
    Here is what I changed but don't work.
    <?php if ($view_profile) { ?>{username_value},{age_value}<?php } else { ?>{title}<?php } ?>

    I am a newbie in PHP, can you please help me in detail?
    Thank you very much!!!
     
    jennypretty, Oct 18, 2007 IP
  4. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #4
    Wrong, you should also replace your {var} blocks, there is no {} directives.
    Something like this:
    
    <?php if ($view_profile) echo $username_value.','.$age_value; else echo $title; ?>
    
    PHP:
    Of course you need to have variables $view_profile, $username_value, $age_value, $title assigned in this point, I didn't check if you already have them declared.
     
    wmtips, Oct 19, 2007 IP
  5. jennypretty

    jennypretty Active Member

    Messages:
    584
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Hello,
    I tried exactly what you said but nothing happened. When I viewed the source, it does not have any title tag in it.
    Can you please advice?
    Thanks.
     
    jennypretty, Oct 19, 2007 IP
  6. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #6
    Assure you have variables $view_profile, $username_value, $age_value, $title assigned. Sorry I have no time to make "step-by-step manual for noobs" or analyze and write code for you. This topic contains all needed information.
     
    wmtips, Oct 19, 2007 IP
  7. jennypretty

    jennypretty Active Member

    Messages:
    584
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #7
    I got them from view_profile php page and they are sb_city, sb_state.
    Here they are from the view_profile page:

    <?
    echo "<a href='search_results.php?city=".$sbrow_off["sb_city"]."' class='small_link'
    title='All members from ".$sbrow_off["sb_city"]."'>".$sbrow_off["sb_city"]."</a>, ";

    echo "<a href='search_results.php?state=".$sbrow_off["sb_state"]."' class='small_link'
    title='All members from ".$sbrow_off["sb_state"]."'>".$sbrow_off["sb_state"]."</a>, ";

    $country=mysql_fetch_array(mysql_query("select * from sbdtng_country
    where id=".$sbrow_off["sb_country"]));
    echo "<a href='search_results.php?country=".$sbrow_off["sb_country"]."' class='small_link'
    title='All members from ".$country["country"]."'>".$country["country"]."</a>";

    Thanks!
     
    jennypretty, Oct 19, 2007 IP
  8. jennypretty

    jennypretty Active Member

    Messages:
    584
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #8
    I tried this time and it worked but not perfectly.
    here is what I tried:
    <?php if ($view_profile) echo $username.','.$gender; else echo $title_str; ?>

    The username shows up on the title tag but It added a ":" semicolon after that, and I don't know why it shows that semicolon; and the gender value does not show at all.

    If you look at this link, you will see that.

    www.usmatch.info/dating_match3506150.html

    Please help me.

    Big thanks!!!
    Jenny.
     
    jennypretty, Oct 19, 2007 IP
  9. jennypretty

    jennypretty Active Member

    Messages:
    584
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #9
    can anyone help please?
    Thanks!!!
     
    jennypretty, Oct 24, 2007 IP