Jump to content
xisto Community

Calling A False Variable... like count . val

Recommended Posts

Okay I'm very new to PHP still, although you may recognize me from the threa before, just go finished finals so now back to PHP!

On one page I accept an input which will tell the next page how many form lines to generate, that part I have worked out, or so I think. Because the number of forum fields could vary I need to have a number of forum variables, so I used this code:

echo   "<td><input name=\"wname" . $appendval . "\" type=\"text\" id=\"wname" . $appendval . "\" value=\"Catagorie Name\"></td>";

where $appendval is a variable what goes up one at a time, so at the end of this block of code it would say $appendval++
This appears to work quite well, however when it comes to he next page and I want to call that variable which would be the result of wname and the number that happened to be assigned to appendval at the time I run into troubles, is there anyway I can call a variable that is the result of two variables combined?
I'm quite certian it can be done, I just havn't a clue how.

Share this post

Link to post
Share on other sites

Let me try to get this straight,


you are trying to have an input field where the input (assuming a category name) will have effect on the next page.


where, on the next page, it displays the amount of form lines based on what categorie name it is?


or is it more like (simplified) it should ADD a next line when a new category is inputted (sounds more likely..)


Assuming it is option 2 (i figured it out while writing this posts, just too tired to delete the former lines..) you are making it harder then i think it should be


I created a news script and projects script yesterday and this is the method i used..



echo "<td><input name=\"wname\" type=\"text\" id=\"cname\" value=\"Category Name\"></td>";


$id=$_POST['cname'];$name=$_POST['wname'];$qry="INSERT INTO your_table (id,name) VALUES('$id','$name')";$result=mysql_query($qry) or die("error..");


$qry="SELECT name,id from your_table";$result=mysql_query($qry);if(mysql_num_rows($result)==0){//print something if there are no entries..}while($cats=mysql_fetch_array($result, MYSQL_ASSOC)){print "<tr><td>$cats[name]</td><td>$cats[id]</td></tr>";}

I am of course not sure if this works the same with forum categories, but the concept is the same, it gets the array of all name/id inputs of your category table and prints a row(<TR><TD></TD></TR>) for every entry


I am tired but if you understood it, while(){} is a loop that fetches all data and prints something for every entry (you could even display $cats[name] and then a <br>, making it go to the next line..)


Hope this helps just a tiny bit :rolleyes:

Share this post

Link to post
Share on other sites

I'm no where near SQL accessing, no what I'm wanting is to make three pages, one html that asks for two numbers.

Then on the next page a php script, which I have alreay created that will build a HTML table inside a form, that will accept input from the user, based on the info from the previous page. So for example if I put 4 as the value on the previous page there would be 4 text entrie fields on the next page, now because the text areas in a single form must have diffrent names I have assigned a starter name, which in my above code is called wname, and then to make each field diffrent I would then add, using the " . " the value of $appendval a number that goes up every time the while, loops.

Now my problem comes in when I want to display the variable on the next page, which in my case happens to be in a dropdown box, but that's not important. If I call $wname there is nothing assigned to it because on the previous page it would be $wname1, $wname2, $wname3 ect. How do I call these variables bearing in mind that I have no predetermined way of know how many variables there are.

I would assume it would look something like this:

echo "And your're number is," ${wname . $appendval}"

That probably looks nothing like any PHP you've seen (which would be why it doesn't work!), but the important thing is that before the variable is called I need to define it as wname plus a number, hence the { }.

Any thoughts?

Share this post

Link to post
Share on other sites

if i got that right<input name=\"wname\" id=\"cname\">$wname=intval($_POST['wname'];while(($wname=$wname++) && ($cname=$cname++)){echo "You\'re number $wname";}Not sure if it works tho..

Share this post

Link to post
Share on other sites

If I understand PHP at all I think that

while($wname = $wname++)
will never work as 3 can never equal 3+1!

That isn't however what I wanted, I really apprecieate you're trying to help, um how cvan I put this?


Okay you know how when you call a variable you simply use it in code for example
echo "You're name is" $name
should (I stree Should) simply write You're name is and then whatever the value assigned to $name was. That easy enough. And we also know that to accept input from a form we use a variable name which in this case would be "name".

But what if to get the variable name on the previous page I had to assign it by merging two vars together something like :
$part1 = "na";$part2 = "me";//something about input, I don't know the HTML input code but the var would be:name="$var1 . $var2";

This ofcorse is a very silly example, but when precessed it would read:
so my question is after pressing submit whatever information was in the form called "name" would be stored in the variable $name, Correct. So on the next page how do I retreve the information from $name without knowing it is called $name because it was derived from $var1 . $var2 (na . me) Again it wouldn't be hard if I knew what the two vars were at any given time, but what if $var2 were a random number that was passed on to the next page then the form information could be stored in $na194939, or $na295654, or $na111222, and so on. As I'm reading I think it could be done with the
But I don't know how.

Notice from BuffaloHELP:
Edited per request.

Edited by BuffaloHELP (see edit history)

Share this post

Link to post
Share on other sites

I just though I'd let everyone know that I solved the problem, Thankyou HmmZ for your help, I don't know if you really ever understood my question but here's the code I've ended up using:

   while ( $weighthist <= $weightnum ){	$dropval = ${wname . $weighthist};	$perval = ${wper . $weighthist};	echo '<option value="' . $perval . '"> ' . $dropval . '</option>'; 	$weighthist++;      }

Share this post

Link to post
Share on other sites

Heh, guess I didn't understand your question :lol:ahwell, i'm still in the long but adventureous exploring stage of PHPGlad you solved your problem though :rolleyes:

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.