Gem Posted April 5, 2009 Share Posted April 5, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/ Share on other sites More sharing options...
revraz Posted April 5, 2009 Share Posted April 5, 2009 $_GET uses [ ] around the array, not ( ) Also, you need to pass something in order to $_GET it. Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801789 Share on other sites More sharing options...
Gem Posted April 5, 2009 Author Share Posted April 5, 2009 Hi Revraz ... Thank you What do you mean by pass something to $_GET it?? Im kind of making it up as I go, so dont really know what I'm doing ... ??? Cheers Gem Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801795 Share on other sites More sharing options...
Gem Posted April 5, 2009 Author Share Posted April 5, 2009 ^ Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801803 Share on other sites More sharing options...
unrelenting Posted April 5, 2009 Share Posted April 5, 2009 Hi Revraz ... Thank you What do you mean by pass something to $_GET it?? Im kind of making it up as I go, so dont really know what I'm doing ... ??? Cheers Gem http://www.tizag.com/phpT/postget.php Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801804 Share on other sites More sharing options...
Gem Posted April 5, 2009 Author Share Posted April 5, 2009 I kind of get what that is saying, thanks. Does that mean I cant do it this way? Can you suggest another way? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801807 Share on other sites More sharing options...
Gem Posted April 5, 2009 Author Share Posted April 5, 2009 ^ Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801821 Share on other sites More sharing options...
revraz Posted April 5, 2009 Share Posted April 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801824 Share on other sites More sharing options...
Gem Posted April 5, 2009 Author Share Posted April 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801827 Share on other sites More sharing options...
revraz Posted April 5, 2009 Share Posted April 5, 2009 Instead of using the title to build the URL, use the ID of the Row that holds the data. Then have it go to a new page on how you want that data to be displayed. Then you need to Select that row of data to display it. Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801849 Share on other sites More sharing options...
Gem Posted April 5, 2009 Author Share Posted April 5, 2009 ??? 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 Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801861 Share on other sites More sharing options...
revraz Posted April 6, 2009 Share Posted April 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801915 Share on other sites More sharing options...
unrelenting Posted April 6, 2009 Share Posted April 6, 2009 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-801964 Share on other sites More sharing options...
Gem Posted April 6, 2009 Author Share Posted April 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802278 Share on other sites More sharing options...
Gem Posted April 6, 2009 Author Share Posted April 6, 2009 Sorry to bump, but im stuck without this ... x Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802300 Share on other sites More sharing options...
revraz Posted April 6, 2009 Share Posted April 6, 2009 That is because you have 3 ((( and only 2 )) here if ((isset ($_GET['currentpage'])) Get rid of the first ( if (isset ($_GET['currentpage'])) Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802342 Share on other sites More sharing options...
Gem Posted April 6, 2009 Author Share Posted April 6, 2009 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 =) Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802378 Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 Like revraz already mentioned you need to change: $currentpage = $_GET('currentpage'); to: $currentpage = $_GET['currentpage']; Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802406 Share on other sites More sharing options...
Gem Posted April 6, 2009 Author Share Posted April 6, 2009 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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802414 Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 Put this right after your opening php tag <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802428 Share on other sites More sharing options...
Gem Posted April 6, 2009 Author Share Posted April 6, 2009 Thank you!! Error: Notice: Undefined variable: id in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\test1.php on line 9 PHP Notice: Undefined variable: id in d:\webspace\bradleystokejudoclub.co.uk\wwwroot\test1.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802431 Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 Well where does $id come from? Before your clause was "WHERE title = '$title'" now you're using id, which is it? Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802435 Share on other sites More sharing options...
Gem Posted April 6, 2009 Author Share Posted April 6, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802437 Share on other sites More sharing options...
Maq Posted April 6, 2009 Share Posted April 6, 2009 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'. Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802438 Share on other sites More sharing options...
Gem Posted April 6, 2009 Author Share Posted April 6, 2009 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 :-\ Quote Link to comment https://forums.phpfreaks.com/topic/152674-solved-_getcurrentpage-i-think/#findComment-802443 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.