Jump to content

[SOLVED] $_Get('currentpage') I think ...?


Recommended Posts

Hiya

 

Trying to build a script that will list titles and subtitles, and when you click on the title, you see title, subtitle and ARTICLE ... and its not working very well ...

 

I think im getting close though ... I have very limited knowledge of PHP so im doing alot of trial and error lol

 

This is what is happening when I load the page (Note the error at the bottom)

 

www.bradleystokejudoclub.co.uk/test.php

 

And heres the code (Line 15 is $currentpage = $_GET('currentpage'); )

 

Hope you can help =)

 

<?php
// database connection info
$conn = mysql_connect("80.94.196.33","USER_INFO") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR);

$result = mysql_query ("SELECT title, subtitle, article FROM articles ORDER BY ID DESC");
while(list($title, $subtitle, $article) = mysql_fetch_row($result))
{
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$title'>$title</a><BR />";
echo $subtitle;
echo "<BR />";
echo "<BR />";

} 
$currentpage = $_GET('currentpage');

if ($currentpage = $title)
{
echo $title;
echo "<BR />";
echo $subtitle;
echo "<BR />";
echo nl2br($article);
echo "<BR />";
}
else
{
echo "ERROR";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/
Share on other sites

Don't know, you really don't say what you are actually doing.  What is current page supposed to represent?

 

I kind of get what that is saying, thanks.

 

Does that mean I cant do it this way?

 

Can you suggest another way?

 

Thanks

LOL sorry..

 

I'll try to explain

 

Might be easier to see for yourself though

 

www.bradleystokejudoclub.co.uk/test.php

 

On that page I have listed title and subtitle from my database....

 

I want to be able to click on title, and it take me to a new "page" where it shows title, subtitle, and article ...

 

Does that make any sense??

 

Thanks mate - I really appreciate your help :)

 

Gem

???  my head hurts ...

 

so, when you say have it go to a new page ... do you literally mean a new page, or ..test.php?id=1  ??

 

that would be perfect, but I dont know how to do it.

 

a clue perhaps?

 

I really appreciate you help so much, I'm enjoying learning php and what it can do!! =)

 

Gem x

 

 

 

 

I personally would go to a new page, but still use your id=1 with it, so you pass which row you are displaying.  Then that page, all you have to do is worry about displaying just that data.

 

Try something like this.

 

<?
// database connection info
if ((isset ($_GET['currentpage']))
{
$currentpage = $_GET('currentpage');
$conn = mysql_connect("80.94.196.33","USER_INFO") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR);

$result = mysql_query ('SELECT title, subtitle, article FROM articles WHERE title = "' . $title . '"');
while(list($title, $subtitle, $article) = mysql_fetch_row($result))
{
	echo $title;
	echo "<BR />";
	echo $subtitle;
	echo "<BR />";
	echo nl2br($article);
	echo "<BR />";
}
}

$conn = mysql_connect("80.94.196.33","USER_INFO") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR);

$result = mysql_query ("SELECT title, subtitle, article FROM articles ORDER BY ID DESC");
while(list($title, $subtitle, $article) = mysql_fetch_row($result))
{
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$title'>$title</a><BR />";
   echo $subtitle;
   echo "<BR />";
   echo "<BR />";
   
}
else
{
   echo "ERROR";
}

?>

Hiya

 

Thanks for your help.  I uploaded your code, but I got this error:

 

PHP Parse error: syntax error, unexpected '{' in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\test.php on line 4

 

If I remove the {} then I get "Unexpected T_VAR" which is this one: $currentpage

 

What to do?

 

X

Thanks Rev - This is what i've got so far

 

Test.php (This works)

<?php

$conn = mysql_connect("80.94.196.33","gem","landseer") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR);

$result = mysql_query ("SELECT id, title, subtitle, article FROM articles ORDER BY ID DESC");
while(list($id, $title, $subtitle, $article) = mysql_fetch_row($result))
{
    echo " <a href='test1.php?currentpage=$id'>$title</a><BR />";
   echo $subtitle;
   echo "<BR />";
   echo "<BR />";
   
}

?>

 

Test1.php (this doesnt work)

<?php
// database connection info
if (isset ($_GET['currentpage']))
$currentpage = $_GET('currentpage');
$conn = mysql_connect("80.94.196.33","gem","landseer") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR);
$result = mysql_query ('SELECT title, subtitle, article FROM articles WHERE title = "' . $title . '"');
while(list($title, $subtitle, $article) = mysql_fetch_row($result))
{
echo $title;
echo "<BR />";
echo $subtitle;
echo "<BR />";
echo nl2br($article);
echo "<BR />";
}
?>

 

Error: PHP Fatal error: Call to undefined function: array() in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\test1.php on line 4

 

I'm getting close ... I can feel it in my bones =)

LOL - took me like a minute to see what the difference was there!

 

Heres what I got now... I change the query to to select where id equals $id but all i get is a blank screen ...

 

<?php
// database connection info
if (isset ($_GET['currentpage']))
$currentpage = $_GET['currentpage'];
$conn = mysql_connect("80.94.196.33","gem","landseer") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR);
$result = mysql_query ('SELECT title, subtitle, article FROM articles WHERE id = "' . $id . '"');
while(list($id, $title, $subtitle, $article) = mysql_fetch_row($result))
{
echo $title;
echo "<BR />";
echo $subtitle;
echo "<BR />";
echo nl2br($article);
echo "<BR />";
}
?>

well i figured that because in test.php i was linking using the $id ... I should probably use that in the query on test1.php ??

 

I am really stuck ...  ???

 

Yesterday I loved PHP, today I'm hating it!

 

Looks like you should be using '$currentpage'.

where to though mate??

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
// database connection info
if (isset ($_GET['currentpage']))
$currentpage = $_GET['currentpage'];
$conn = mysql_connect("80.94.196.33","gem","landseer") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('bssql',$conn) or trigger_error("SQL", E_USER_ERROR);
$result = mysql_query ('SELECT title, subtitle, article FROM articles WHERE id = "' . $id . '"');
while(list($id, $title, $subtitle, $article) = mysql_fetch_row($result))
{
echo $title;
echo "<BR />";
echo $subtitle;
echo "<BR />";
echo nl2br($article);
echo "<BR />";
}
?>

 

All i want to is get the $id from the url of the page and then use that to tell the page which article it is I want echo'd ... all seemed so easy in my head  :(

 

Heres the pages, that might help

www.bradleystokejudoclub.co.uk/test.php

 

and then click on one of the links and that is the page above

 

:-\

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.