Log in

View Full Version : Resolved Lets work again! Forum question



auriaks
11-09-2009, 01:30 AM
Hi again,
i have file index.php with link <a href='forum.php';>Electronics<a/>
when i push this link i want to get info about electronics, but how i can say to mysql, that i need only electronics variable, and that will be by only pushing this link??

ASK if more details needed... Thx :)

Nile
11-09-2009, 02:20 AM
I don't understand your question. Can you try to explain it a bit better? Here are a few questions:

- Do you already have a page about the electronics?
- Is it a special category inside your forums?
- What forums are you using (or is this a a fill out forum, such as a contact forum?)
- Can you provide a link to your page?

Thank you!

bluewalrus
11-09-2009, 03:46 AM
Your link shouldnt have a semi colon.
<a href='forum.php'>Electronics<a/>
Not: <a href='forum.php';>Electronics<a/>

boogyman
11-09-2009, 05:02 AM
Your link shouldnt have a semi colon.
<a href='forum.php'>Electronics<a/>
Not: <a href='forum.php';>Electronics<a/>

That is part of the answer, however that will just link them to the forum.php file.


@auriaks

In addition to the modification above, you would need to pass a variable to that file that will indicate PHP to add on a filter when performing the MySQL look-up.

auriaks
11-09-2009, 03:11 PM
I dont have this page, because i want to use one forum.php page to show ALL the titles and messages which are choosed by pushing link in index.php. Link {which is in index.php} says what variable to ASK IN forum.php

like my link is ELECTRONIC, i push on it, and in forum.php, script takes your pushed link and regonises it as electronic variable which is needed. Messy ye? :D

I know that is possible to do something like:
www.tester.xz.lt/forum.php?electronics.do,blablablacode
and something like that saves electronics name and uses it in forum.php as show key.

bluewalrus
11-09-2009, 03:40 PM
Okay, so you can do this.


Change your links to be this format
<a href='forum.php?&amp;cat=electronics'>Electronics<a/>


At the start of your page put this in

$url = $_SERVER['REQUEST_URI'];
//from the address get the categorey
//Not sure how $url will be if it will have the and symbol or the &amp;
echo $url;
// so by result of this echo if it is &amp; change the & below to that
$page = explode ("forum.php?&cat=", $url);
$cat = $page[1];


Then use the variable $cat in your sql statment to get the results you want displayed.
You might want to initialize $cat as something or use an if statment around your sql so it isn't triggered when $ is empty or not set.

fg123
11-10-2009, 01:13 AM
Like Nile said. Pass info with $_GET.

Nile
11-10-2009, 01:15 AM
Fg:
I don't recall?

Bluewalrus:
Use $_GET, like fg123 said. ;)

Fg:
I reversed your post.

bluewalrus
11-10-2009, 01:24 AM
How do you use $_GET without knowing the name of the variable passing the value in? I've only used it with a post but thought it would be the same except for different method from the form. $_POST['name'];

Nile
11-10-2009, 01:38 AM
Ok, take your code:


$url = $_SERVER['REQUEST_URI'];
//from the address get the categorey
//Not sure how $url will be if it will have the and symbol or the &amp;
echo $url;
// so by result of this echo if it is &amp; change the & below to that
$page = explode ("forum.php?&cat=", $url);
$cat = $page[1];

And add return $cat at the bottom.
If the url was form.php?&cat=bob, out return value would be "bob." BUT if you were to go to forum.php?&cat=bob&page=4 it would return "bob&page=4". Using $_GET['cat'] would be more effecient, and only return 'bob' no matter what. (And you do not need the & after the question mark, fyi. ;))

bluewalrus
11-10-2009, 02:40 AM
OO so the get takes from the question mark to the equals mark, like this? I know I could run this but I just want to see if this is the correct usage or if I'm missing a part. Thanks.

http://www.somesite.com/index.php?variablecontrol=variable_set_to
$set_variable = $_GET['variablecontrol'];
echo $set_variable;
// displays "variable_set_to"

Nile
11-10-2009, 03:09 AM
Correct, and when making a forum, you can also set the method to "get" instead of just "post".