nickbunyun Posted June 11, 2008 Share Posted June 11, 2008 Hey guys! So far I've got a database with lots of fields... and i've got a pagination system to show me only 5 per page. it kinds puts out this. Date ZipCode Tools 2008-04-24 View || Delete 2008-04-24 30519 View || Delete 2008-04-24 30519 View || Delete 2008-04-24 30519 View || Delete 2008-04-24 30519 View || Delete « < [1] > » Pages: 3 now here's the question. What i want it to do, is when I click on VIEW, to open that ROW, and post ALL fields of the one row. heres my view.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ehc", $con); // $result = mysql_query("SELECT * FROM formone ORDER BY id ASC"); $table = 'feedback';//Table name here $limit = 5;//Limit of results here $page = $_GET['page'];//Gets the page $totalrows = mysql_num_rows(mysql_query("SELECT id FROM $table"));//Get the total rows of the table if(empty($page))//If the page is empty { $page = '1';//sets the page to 1 }; $start = ($page-1)*$limit;//set the start page $start = round($start,0);//rounds it $result = mysql_query("SELECT * FROM $table LIMIT $start, $limit");//makes the query, here you can add for example // Make the Top row to echo echo "<table>"; echo "<th> Date </th>"; echo "<th> ZipCode </th>"; echo "<th> Tools </th>"; //WHERE something='somethingelse' while ($r = mysql_fetch_array($result)) { echo "<tr><td>$r[date]</td> <td>$r[zipcode]</td> <td> <a href=?full=$r[id] target='_blank'>View</a> || Delete </td> </tr>"; }; $totalpages = $totalrows / $limit;//Gets the totalpages $totalpages = ceil($totalpages);//rounds them to the bigger number, so if the limit is 10 and there are 11 results it will show 2 paegs instead of 1 if($page == 1)//if the page is 1 { $actualpage = '[1]';//actial page 1 } else { $actualpage = "[$page]";//else actualpage is the one we get using the $_GET } if($page < $totalpages)//if the page is smaller than totalpages { $nv = $page+1;//next page $pv = $page-1;//prev page $nextpage = "<a href=?page=$nv>></a>";//next page link $prevpage = "<a href=?page=$pv><</a>";//preg page link $firstpage = "<a href='?page=1'>«</a>";//first page $finalpage = "<a href='?page=$totalpages'>»</a>";//last page } if($page == '1')//if the page is 1 { $nv = $page+1; $nextpage = "<a href=?page=$nv>> </a>"; $prevpage = "<"; $firstpage = "«"; $finalpage = "<a href='?page=$totalpages'>»</a>"; }elseif($page == $totalpages){//is the page is equal than the totalpages $pv = $page-1; $nextpage = ">"; $prevpage = "<a href=?page=$pv><</a>"; $firstpage = "<a href='?page=1'>«</a>"; $finalpage = "»"; } if($totalpages == '1' || $totalpages == '0'){//if totalpages is 1 or 0 $nextpage = ">"; $prevpage = "<"; $firstpage = "«"; $finalpage = "»"; } echo "</table>"; echo "$firstpage $prevpage $actualpage $nextpage $finalpage<br>Pages: $totalpages";//echoes the pages at the botton of the file mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/ Share on other sites More sharing options...
hansford Posted June 11, 2008 Share Posted June 11, 2008 <a href="whateverpage.php?rowvalue=1">view row 1</a> then on whateverpage.php if(isset($_GET['rowvalue'])){ $row = $_GET['rowvalue']; //connect to database and get $row } or you could use ajax which I won't go into Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-563270 Share on other sites More sharing options...
nickbunyun Posted June 11, 2008 Author Share Posted June 11, 2008 wow.. thx.. that did not help. can u be lil more specific??? <<< Noobiest Noob here. Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-563294 Share on other sites More sharing options...
hansford Posted June 11, 2008 Share Posted June 11, 2008 thats about as specific as I can get. create an anchor tag that when clicked will take you to some php page where you will use $_GET to get the value attached to the end of whateverpage.php?row=1 so $row = $_GET['row'] $row now holds the value 1, so you know to display row 1 from your DB Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-563321 Share on other sites More sharing options...
nickbunyun Posted June 12, 2008 Author Share Posted June 12, 2008 Ok what im tryin to do is this <a href=viewfull.php?full=$r[id] target='_blank'>View</a> ok what is my code going to look in the viewfull.php ?? so far i got something along these lines .. but i may be wrong. switch($_GET['full']) { case "$r[id]": // can i get the ID from the link ??? $result = mysql_query("SELECT * FROM feedback"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } $row = mysql_fetch_row($result); echo $row[0]; // 42 I really dont know how to do this.. Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-563822 Share on other sites More sharing options...
hansford Posted June 12, 2008 Share Posted June 12, 2008 in fullview.php <?php ifisset($_GET['full'])){ $row_num = $_GET['full']; //connect to database //make your query $count=1; while($row = mysql_fetch_array($result)){ if($count != $row_num){ $count++; continue; } else{ //echo out all values in $row break; } } } else{ echo "An Error has occurred in sending the value of $_GET['full']"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564005 Share on other sites More sharing options...
nickbunyun Posted June 12, 2008 Author Share Posted June 12, 2008 first.. ii guess its if isset.. right ? not ifisset one word.. and than this is wha i have <?php if isset($_GET['full']) { $row_num = $_GET['full']; //connect to database $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ehc", $con); //make your query $result = mysql_query("SELECT * FROM feedback"); $count=1; while($row = mysql_fetch_array($result)){ if($count != $row_num){ $count++; continue; } else{ //echo out all values in $row break; } } } else{ echo "An Error has occurred in sending the value of $_GET['full']"; } mysql_close($con); ?> ^^^^^^^^^ thats my viewfull.php and than i get this Parse error: syntax error, unexpected T_ISSET, expecting '(' in C:\xampp\htdocs\EHC\feedback\viewfull.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564203 Share on other sites More sharing options...
kmark Posted June 12, 2008 Share Posted June 12, 2008 Your third line shoul be: if (isset($_GET['full'])) { Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564221 Share on other sites More sharing options...
hansford Posted June 12, 2008 Share Posted June 12, 2008 he's right - sorry nickbunyun. I mis-typed and left out the ( character if(isset($_GET['full'])) Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564390 Share on other sites More sharing options...
nickbunyun Posted June 13, 2008 Author Share Posted June 13, 2008 thx.. i feel like im takin baby steps.. lol.. <?php if(isset($_GET['full'])) { $row_num = $_GET['full']; //connect to database $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ehc", $con); //make your query $result = mysql_query("SELECT * FROM feedback"); $count=1; while($row = mysql_fetch_array($result)){ if($count != $row_num){ $count++; continue; } else{ //echo out all values in $row break; } } } else{ echo "An Error has occurred in sending the value of $_GET['full']"; } mysql_close($con); ?> Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\EHC\feedback\viewfull.php on line 36 Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564739 Share on other sites More sharing options...
kmark Posted June 13, 2008 Share Posted June 13, 2008 your line 36 should read echo "An Error has occurred in sending the value of ".$_GET['full']; OR echo "An Error has occurred in sending the value of {$_GET['full']}"; Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564746 Share on other sites More sharing options...
nickbunyun Posted June 13, 2008 Author Share Posted June 13, 2008 alright i changed it but.. now i get this .. :-/ An Error has occurred in sending the value of Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\EHC\feedback\viewfull.php on line 38 line 38 is .. echo "An Error has occurred in sending the value of ".$_GET['full']; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564749 Share on other sites More sharing options...
BlueSkyIS Posted June 13, 2008 Share Posted June 13, 2008 remove that line mysql_close($con); Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564756 Share on other sites More sharing options...
nickbunyun Posted June 13, 2008 Author Share Posted June 13, 2008 now.. An Error has occurred in sending the value of Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564765 Share on other sites More sharing options...
kmark Posted June 13, 2008 Share Posted June 13, 2008 that would be because $_GET['full'] isn't set. It doesn't make sense to check if $_GET['full'] isset and then if it isn't try and use it in the error message. Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564771 Share on other sites More sharing options...
nickbunyun Posted June 13, 2008 Author Share Posted June 13, 2008 ok when click on viewfull.php?full=1 to open a pop up and show row 1. when click on viewfull.php?full=6 to open a pop up and show row 6. im following hansford example soince its the only lead i got now.. but im not understanding much, so can u tell me what and where i need to set? Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564783 Share on other sites More sharing options...
kmark Posted June 13, 2008 Share Posted June 13, 2008 Theres nothing wrong in the post above, im just saying you cant use a variable that isn't set in a error statement because it isn't set. but if it is set like the links you showed above then you should have no problem but you will have to add some code so that the row info is output. Where you have: //echo out all values in $row you need to write some code to output the values eg: print $row['firstName'].' '.$row['lastName']; where firstName and lastName are fields in your database This would print John Smith if John Smith was the first and last name in your table for the specified row. Make Sense? Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564790 Share on other sites More sharing options...
nickbunyun Posted June 13, 2008 Author Share Posted June 13, 2008 yay!! it works! you guys are awesome! if i have any other problem i know where to come! Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564798 Share on other sites More sharing options...
hansford Posted June 13, 2008 Share Posted June 13, 2008 the error message was just to tell you that $_GET is not set. you can simply echo "error"; ok, so $_GET['full'] is not getting set. Below is how you have your anchor tag. This will not do. if you're going to put php variables in there, then php must echo it out. why do you have target='_blank'? do you want to open a new window? <a href=viewfull.php?full=$r[id] target='_blank'>View</a> //will not work example: echo "<a href='viewfull.php?full=" . $r['id'] . "' target='_blank'>View</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564812 Share on other sites More sharing options...
nickbunyun Posted June 13, 2008 Author Share Posted June 13, 2008 lol.. it actually works the way it is right now o.O php if wierd. Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564818 Share on other sites More sharing options...
hansford Posted June 13, 2008 Share Posted June 13, 2008 congrats. I see that you were in-fact echoing it out. any more questions just post. Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564830 Share on other sites More sharing options...
nickbunyun Posted June 13, 2008 Author Share Posted June 13, 2008 thanks guys +1 rep to all of you.. .. if there was a rep system Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-564844 Share on other sites More sharing options...
nickbunyun Posted June 17, 2008 Author Share Posted June 17, 2008 ok so another little problem... ok so i have the code.. ... mysql_select_db("ehc", $con); //make your query $result = mysql_query("SELECT * FROM feedback"); $count=1; while($row = mysql_fetch_array($result)){ if($count != $row_num){ $count++; continue; } else{ echo "<table border='1'>"; ... Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-567464 Share on other sites More sharing options...
nickbunyun Posted June 17, 2008 Author Share Posted June 17, 2008 i have about 14 rows in the database.. but some #s are like.. 1 2 3 12 14 15 16 25 etc, because i deleted some of the unneccesary rows.. but the way it reads it now is that like this row 1,2,4,8,10,15,20 reads it as id?=1,2,3,4,5,6,7,8,9 so right now my last db row is 22, but on the viewfull.php?=15. Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-567492 Share on other sites More sharing options...
hansford Posted June 17, 2008 Share Posted June 17, 2008 We aren't interested in $_GET['full'] if its empty. The error message is for your information only and if it comes up then you know $_GET['full'] is empty ie; hasn't been set. use this instead. echo "An Error has occurred in sending the value of GET[full]"; Quote Link to comment https://forums.phpfreaks.com/topic/109749-display-more-on-click/#findComment-567524 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.