Page 1 of 1

Have code here for displaying data but ... need help ...

Posted: Sun Sep 08, 2002 9:34 pm
by os2al
This bit of code displays member names in a <li> list </ul>, and when you click on a member name in the list, it shows you the data (name, address, city, state, zip) from a Mysql database at the bottom of the same list page; in other words, on the same page. Click on any name, you get the data info at the bottom of the same page, etc. I need it to display the data on another page or window instead of at the bottom of the <li> list page. Can anyone help me correct this code so it will do that?
Much appreciate any help. Thanks,

Al
- - -

<?php
function list_member()
{
$db_name = "database";
$table_name = "Table";

$connect = @mysql_connect("localhost", "database", "password");
if( !$connect )
{
echo "Couldn't connect to database";
exit;
}

$db = @mysql_select_db($db_name, $connect);
if( !$db )
{
echo "Couldn't select database";
exit;
}

$sql = "SELECT id, Name FROM $table_name";
$result = @mysql_query($sql,$connect);
while ($row = mysql_fetch_assoc($result))
{
$id = $row['id'];
$Name = $row['Name'];
echo "<li><a href=\"$PHP_SELF?action=showmember&id=$id\">$Name</a>";
}
echo "</ul>";

mysql_close( $connect );
}
function member_details ( $id )
{
$db_name = "database";
$table_name = "table";

$connect = @mysql_connect("localhost", "database", "password");
if( !$connect )
{
echo "Couldn't connect to database";
exit;
}

$db = @mysql_select_db($db_name, $connect);
if( !$db )
{
echo "Couldn't select database";
exit;
}

$sql = "SELECT * FROM $table_name WHERE id='$id'";
$result = @mysql_query($sql,$connect);
while ($row = mysql_fetch_assoc($result))
{
$Name = $row['Name'];
$Address = $row['Address'];
$City = $row['City'];
$State = $row['State'];
$Zip = $row['Zip'];
}
echo"

<h3>$Name</h3>

<strong>Address: </strong>$Address <br>
<strong>City: </strong>$City<br>
<strong>State: </strong>$State<br>
<strong>Zip: </strong>$Zip<br>

mysql_free_result($result);
mysql_close ($connect);
}
?>
<html>
<head>
<title>Members List</title>

</head>

<?php
list_member();
switch( $action )
{
case "showmember":
member_details( $id );
break;
default:
echo "Some instructions here";
break;
}
?>
<h4><strong><br> Choose another member<br></strong></a></h4>
<br>
</body>
</html> :(

Posted: Sun Sep 08, 2002 9:45 pm
by volka
in function list_member() change

Code: Select all

echo "&lt;li&gt;&lt;a href="$PHP_SELF?action=showmember&amp;id=$id"&gt;$Name&lt;/a&gt;";
to

Code: Select all

echo "&lt;li&gt;&lt;a href="$PHP_SELF?action=showmember&amp;id=$id" target="memberDetail"&gt;$Name&lt;/a&gt;";
and change

Code: Select all

&lt;?php
list_member(); 
switch( $action ) 
{ 
case "showmember": 
member_details( $id ); 
break; 
default: 
echo "Some instructions here"; 
break; 
}
?&gt;
to

Code: Select all

&lt;?php 
if (!isset($action))
	list_member(); 
else
{
	switch( $action ) 
	{ 
		case "showmember": 
			member_details( $id ); 
			break; 
		default: 
			echo "Some instructions here"; 
			break; 
	} 
}
?&gt;
and read Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+ ;)

Many thanks, Volka ...

Posted: Mon Sep 09, 2002 7:42 pm
by os2al
:D Followed your instructions and they worked perfectly, so I am very grateful for your help. You truly are a master and could teach Yoda a few tricks.

I'm ashamed to ask for anything else, but it would be that the data opens in a way that would allow me to use the browser's back button to go back and forth between the list and the record info. As it stands now (and they are perfectly good, believe me) when one clicks on the list name, you go to another window to see the record data after the first record appears and must keep switching windows. I hoped it would just be another page that I could move back and forth around, using the back button; click on a name, see the data, and go back again. But I couldn't explain it well enough.

I much appreciate your help. You've been good to me.

Al

Posted: Tue Sep 10, 2002 1:02 am
by Takuma
So do you want the user detail to open in a new window or the same window?
Your English is too good for me :lol:

Sorry about the English ...

Posted: Tue Sep 10, 2002 8:13 am
by os2al
:? As I tried to explain but didn't well enough, so that the data appears not on the same page as the list but in a way that let's me move back and forth to the list using the brower's Back button -- on a new web page is perhaps I'm trying to say. Just as, say, when you login to a site, you could go back to the login screen, even though you're on a different webpage after the login.
Sorry about this. Thanks for bothering with my confusion. How exactly to explain it other than that is unclear to me (and obviously to anyone else).

Al

Re: Sorry about the English ...

Posted: Tue Sep 10, 2002 11:16 am
by Takuma
os2al wrote::? As I tried to explain but didn't well enough, so that the data appears not on the same page as the list but in a way that let's me move back and forth to the list using the brower's Back button
Ah, do you mean by this?

Code: Select all

&lt;?php
echo "&lt;li&gt;&lt;a href="$PHP_SELF?action=showmember&amp;id=$id" target="_blank"&gt;$Name&lt;/a&gt;";
?&gt;

Well, it's the same ...

Posted: Fri Sep 13, 2002 9:10 am
by os2al
8O Sorry to say, despite your heroic efforts, that the code does the same thing, from what I can see. Much appreciate your effort, though.

Al

Posted: Fri Sep 13, 2002 4:30 pm
by Takuma
So the data retrieval is working but not the window?

Works as before the change

Posted: Sun Sep 15, 2002 10:19 pm
by os2al
:o Well, it works just as it did before. The window opens and the data shows, the only "problem" (if this is a problem) is that it's a different window but one that doesn't allow me to use the browser's back button to go back to the list. To get to the list again, I have to switch windows, click on another name, and then switch back to see the data in the other window. I hope this makes sense.

Al

Posted: Mon Sep 16, 2002 2:30 am
by Takuma
Would this work?

Code: Select all

&lt;?php
echo "&lt;li&gt;&lt;a href="$PHP_SELF?action=showmember&amp;id=$id"&gt;$Name&lt;/a&gt;";
?&gt;