Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 01-21-2011, 11:37 AM qustion on variables
Novice Talker

Posts: 6
Trades: 0
Hi, I'm trying to make a link like this:

<?php $previous = $number - 1; $prevTitle = XXXX; echo "<a href='loader.php?pg=$previous&subsection=1&article =$prevTitle'>

the XXXX is where i'm having trouble. I've been calling out the titles via a variable, like this:
$title1
$title2
$title3

but if I put $prevTitle= $title$previous; it gives an error. How can I get it to switch the title to match the link variably?


Thanks!!
ShadowHawk is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-21-2011, 11:40 AM Re: qustion on variables
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Quote:
Originally Posted by ShadowHawk View Post
Hi, I'm trying to make a link like this:

<?php $previous = $number - 1; $prevTitle = XXXX; echo "<a href='loader.php?pg=$previous&subsection=1&article =$prevTitle'>

the XXXX is where i'm having trouble. I've been calling out the titles via a variable, like this:
$title1
$title2
$title3

but if I put $prevTitle= $title$previous; it gives an error. How can I get it to switch the title to match the link variably?


Thanks!!
Please paste all the code. Also what error message do you get..

Try putting the code in like this:
PHP Code:
<?php 
$previous 
$number 1;
$prevTitle "Sometitle";
echo 
"<a href=\"loader.php?pg=$previous&subsection=1&article=$prevTitle\">Link</a>";

?>
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 01-21-2011 at 11:41 AM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 01-21-2011, 11:56 AM Re: qustion on variables
Novice Talker

Posts: 6
Trades: 0
Ok I have a file of variables,

in short it has:

<? php
$title1= "My first Title";
$title2= "Another Title";
$title3= "Last Title";
?>

I have a page to load the content that I want. it contains a link like this:

<?php $sub = $_GET ['sub']; $number = $_GET ['pg']; include ("$number-$sub.html"); ?>


and to change links I am using like this:
<?php $previous = $number - 1; echo "<a href='loader.php?pg=$previous&sub=1&article=$title 1'>

In the html page, I use the variable to call out the title like this:
<h1>$title1</h1>
<p> contents of page</p>


'pg' controls the main page number 'sub' controls any subsections to that page, 'article' will print out the article title at the top bar as well as on the top of the page.

So far I am doing it manually, but it would be nice if the numbers are updated automatically.
ShadowHawk is offline
Reply With Quote
View Public Profile
 
Old 01-21-2011, 01:08 PM Re: qustion on variables
Novice Talker

Posts: 6
Trades: 0
for example i think i only need a way to replace the number portion of the variable,

like $title{$previous}

but I don't know how to just change the number.

for example this:
$[title$previous] if $previous = 3

returns $[title3]

so i need it to return $title3
which should hopefully print the correct title. (the text that was assigned to $title3)

searching around I am now trying like this:

ok, so this is how far I got:

<?php $previous =3; $dollar= '$'; $g= 'title'; $preID ="$dollar$g$previous"; ?>
<?php echo $preID ;?>

but this shows $title3, it does not give me the "Title 3" from the $title3 variable.

Last edited by ShadowHawk; 01-21-2011 at 01:53 PM.. Reason: update
ShadowHawk is offline
Reply With Quote
View Public Profile
 
Old 01-21-2011, 03:21 PM Re: qustion on variables
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Just put the titles in a simple array. Then you index by numbers - nice and easy.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 01-21-2011, 04:27 PM Re: qustion on variables
Novice Talker

Posts: 6
Trades: 0
Thanks, That worked great!
ShadowHawk is offline
Reply With Quote
View Public Profile
 
Old 01-27-2011, 10:18 PM Re: qustion on variables
Novice Talker

Posts: 8
Trades: 0
Also worth mentioning that when you do echo stuff in an array - if you want PHP to interpolate the string with array values that you can wrap them in curly braces like this: echo "Hello {$person['name']}\n"; Which can take less typing than: echo "Hello ". $person['name'] ."\n";
jenny4pres is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to qustion on variables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64363 seconds with 12 queries