Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts

    Question defining values help

    I need some help defining some values I guess you could say. I still have alot to learn with php but im trying my best. anyway im trying to define link types from my mysql database. I made the code
    PHP Code:
    $link_data = array(
    'link_type' => ($link['link_type']!='')
    ); 
    and to display it I used
    PHP Code:
    <?php print($link_data['link_type']); ?>
    Everything works just fine but what im trying to do is make the link_type display different text for each one. in my link_type table, there is 5 different links types defined by the numbers 1-5. so what im trying to do is when i use this code
    PHP Code:
    <?php print($link_data['link_type']); ?>
    instead of displaying the numbers 1-5 i want it to display text like this example.
    instead of 1 it will display link1
    instead of 2 it will display link2 and so on.

    im not even sure if im going about this the best way due to being fairly new to php but it is the best i can come up with. Can anyone help me with this? I would appreciate it. Thanks.

    Also sorry if my description is all over the place, Im pretty tired right now.
    Last edited by cosmicsea; 01-13-2010 at 12:29 PM.

  • #2
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    actually i just noticed it is only showing the value 1 for all links, not 1-5 for all links. i think this is because 1 is default in the database. im not sure what to do now. any help would be appreciated.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by cosmicsea View Post
    actually i just noticed it is only showing the value 1 for all links, not 1-5 for all links. i think this is because 1 is default in the database. im not sure what to do now. any help would be appreciated.
    post the part of the code where you extract the values from database.

    best regards

  • #4
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Ok i edited the code to look like this and now it works perfectly with the display
    PHP Code:
    $link_data = array(
    'link_type' => ($link['link_type']!='')?$link['link_type']:''
    ); 
    and now it works perfectly with the display code which is
    PHP Code:
    <?php print($link_data['link_type']); ?>
    it displays 1-5 for whatever the link type is. so now I just need to figure out a code to make 1-5 display different text besides 1,2,3,4,or5.

    example. replace 1 with link1
    replace 2 with link2 etc. is there any code i could add that would easily make those display differently?
    Last edited by cosmicsea; 01-13-2010 at 10:49 AM. Reason: typo

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by cosmicsea View Post
    Ok i edited the code to look like this and now it works perfectly with the display
    PHP Code:
    $link_data = array(
    'link_type' => ($link['link_type']!='')?$link['link_type']:''
    ); 
    and now it works perfectly with the display code which is
    PHP Code:
    <?php print($link_data['link_type']); ?>
    it displays 1-5 for whatever the link type is. so now I just need to figure out a code to make 1-5 display different text besides 1,2,3,4,or5.

    example. replace 1 with link1
    replace 2 with link2 etc. is there any code i could add that would easily make those display differently?
    PHP Code:
    print 'link'$link_data['link_type']; 
    best regards

  • #6
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    PHP Code:
    print 'link'$link_data['link_type']; 
    best regards
    I don't think that will work because my site automatically creates tables with a single table template that multiplies for each link and im looking to put the code into the table template so it will automatically generate the text for 1,2,3,4 and 5. so lets say the page consists of 100 tables and 100 links. 1 link for each table and it generates automatically. i need a single code that will automatically define what link text to post per link depending on the link numbers defined for the links in the database 1-5. so is there something else i could do?
    Last edited by cosmicsea; 01-13-2010 at 11:07 AM. Reason: typo

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by cosmicsea View Post
    Ok i edited the code to look like this and now it works perfectly with the display
    PHP Code:
    $link_data = array(
    'link_type' => ($link['link_type']!='')?$link['link_type']:''
    ); 
    and now it works perfectly with the display code which is

    it displays 1-5 for whatever the link type is. so now I just need to figure out a code to make 1-5 display different text besides 1,2,3,4,or5.

    example. replace 1 with link1
    replace 2 with link2 etc. is there any code i could add that would easily make those display differently?
    Quote Originally Posted by cosmicsea View Post
    I don't think that will work because my site automatically creates tables with a single table template that multiplies for each link and im looking to put the code into the table template so it will automatically generate the text for 1,2,3,4 and 5. so lets say the page consists of 100 tables and 100 links. 1 link for each table and it generates automatically. i need a single code that will automatically define what link text to post per link depending on the link numbers defined for the links in the database 1-5. so is there something else i could do?
    I don't know what you are doing but if:
    PHP Code:
    print  $link_data['link_type']; 
    display 1, then
    PHP Code:
    print 'link' $link_data['link_type']; 
    will display link1.

    best regards

  • #8
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    I don't know what you are doing but if:
    PHP Code:
    print  $link_data['link_type']; 
    display 1, then
    PHP Code:
    print 'link' $link_data['link_type']; 
    will display link1.

    best regards
    no
    PHP Code:
    print  $link_data['link_type']; 
    displays the number for each automatically already. it will display whether the link is type 1 or type 3 or type 5 etc i just wanted to be able to change the numbers so that they display as text instead of 1,2,3,4, or 5 automatically. my links are being pulled from 5 different websites and in the database i have the 5 websites defined as numbers 1,2,3,4, and 5. so 1 would be website 1 and 2 would be website 2 etc. im using a crawler on 5 sites and displaying links and for every link for a certain site i want to display the site name like 1 would be www.example.com and 2 would be www.example2.com etc. i need this done automatically though cause it would be impossible for me to input the data for every individual link. like i said im using a table template that recreates itself going down the page with random links. 1 link for each table so i need a single code that will automatically put in what site it is from. i hope this helps.
    Last edited by cosmicsea; 01-13-2010 at 11:33 AM. Reason: typo again

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by cosmicsea View Post
    no
    PHP Code:
    print  $link_data['link_type']; 
    displays the number for each automatically already. it will display whether the link is type 1 or type 3 or type 5 etc i just wanted to be able to change the numbers so that they display as text instead of 1,2,3,4, or 5 automatically. my links are being pulled from 5 different websites and in the database i have the 5 websites defined as numbers 1,2,3,4, and 5. so 1 would be website 1 and 2 would be website 2 etc. im using a crawler on 5 sites and displaying links and for every link for a certain site i want to display the site name like 1 would be www.example.com and 2 would be www.example2.com etc. i need this done automatically though cause it would be impossible for me to input the data for every individual link. like i said im using a table template that recreates itself going down the page with random links. 1 link for each table so i need a single code that will automatically put in what site it is from. i hope this helps.
    PHP Code:
    $urls = array(=> 'url1 here',
                         
    => 'url2 here',
                         ....
                         
    => 'url5 here');
    print 
    $urls[$link_data['link_type']]; 
    best regards

  • Users who have thanked oesxyl for this post:

    cosmicsea (01-13-2010)

  • #10
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    PHP Code:
    $urls = array(=> 'url1 here',
                         
    => 'url2 here',
                         ....
                         
    => 'url5 here');
    print 
    $urls[$link_data['link_type']]; 
    best regards
    Awesome. It seems to work flawlessly. thank you very much. I really appreciate it!

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by cosmicsea View Post
    Awesome. It seems to work flawlessly. thank you very much. I really appreciate it!
    you are welcome,

    best regards


  •  

    Posting Permissions

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