Jump to content

Display more on click


nickbunyun

Recommended Posts

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);
?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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..

 

Link to comment
Share on other sites

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']";

}

?>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

:) 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
Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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'>";

...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]";

Link to comment
Share on other sites

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.