...

View Full Version : Resolved defining values help



cosmicsea
01-13-2010, 08:42 AM
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
$link_data = array(
'link_type' => ($link['link_type']!='')
);

and to display it I used

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

cosmicsea
01-13-2010, 08:47 AM
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.

oesxyl
01-13-2010, 09:04 AM
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

cosmicsea
01-13-2010, 09:47 AM
Ok i edited the code to look like this and now it works perfectly with the display

$link_data = array(
'link_type' => ($link['link_type']!='')?$link['link_type']:''
);


and now it works perfectly with the display code which is

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

oesxyl
01-13-2010, 09:53 AM
Ok i edited the code to look like this and now it works perfectly with the display

$link_data = array(
'link_type' => ($link['link_type']!='')?$link['link_type']:''
);


and now it works perfectly with the display code which is

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



print 'link'. $link_data['link_type'];


best regards

cosmicsea
01-13-2010, 10:06 AM
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?

oesxyl
01-13-2010, 10:17 AM
Ok i edited the code to look like this and now it works perfectly with the display

$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?


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:

print $link_data['link_type'];
display 1, then

print 'link' . $link_data['link_type'];

will display link1.

best regards

cosmicsea
01-13-2010, 10:30 AM
I don't know what you are doing but if:

print $link_data['link_type'];
display 1, then

print 'link' . $link_data['link_type'];

will display link1.

best regards

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

oesxyl
01-13-2010, 10:38 AM
no
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.


$urls = array(1 => 'url1 here',
2 => 'url2 here',
....
5 => 'url5 here');
print $urls[$link_data['link_type']];


best regards

cosmicsea
01-13-2010, 11:01 AM
$urls = array(1 => 'url1 here',
2 => 'url2 here',
....
5 => 'url5 here');
print $urls[$link_data['link_type']];


best regards

Awesome. It seems to work flawlessly. thank you very much. I really appreciate it!:thumbsup:

oesxyl
01-13-2010, 11:11 AM
Awesome. It seems to work flawlessly. thank you very much. I really appreciate it!:thumbsup:
you are welcome, :)

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum