I hope I explain this well enough. I can access my Mysql database and get a list of record_id fields as in below in a list:
...
$sql = "SELECT record_id, name ... etc.
FROM $table_name
";
$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");
$member_list = "<ul>";
while ($row = mysql_fetch_array($result)) {
$record_id = $row['org_id'];
... etc.
$member_list .= "<li><a href=\"members.php\">$record_id</a>";
}
$member_list .= "</ul>";
etc.
Perhaps I didn't copy this right but suffice it to say I can list the records_id fields in all the records. Can I get this list so that the id fields that appear are clickable to reveal the content of each record and its fields? In other words, so one would be able to click on one name on the list and get the fields listed for that record? I can list all the information in one record with php and mysql but with my code I seem to get only the last record in the database. Let me know if this here makes sense or not and you want to help. I can send my code.
Al
mysql-php question re: clickable listed fields
Moderator: General Moderators
What you would need to do is change the link to this:
<a href=\"members.php?record_id=$record_id\">$record_id</a>
Now add another part to your code that tests to see if $record_id exists, and if so, then print out the required fields etc.
If $record_id does not exist, then print out the list of record_ids.
ie.
if ( $record_id )
{
$sql = ("SELECT * from $table_name WHERE record_id='$record_id'");
//mysql_query etc.
//print out results
}
else
{
$sql = SELECT record_id, name ... etc.
//mysql_query etc.
//print out the record_id list as before
}
<a href=\"members.php?record_id=$record_id\">$record_id</a>
Now add another part to your code that tests to see if $record_id exists, and if so, then print out the required fields etc.
If $record_id does not exist, then print out the list of record_ids.
ie.
if ( $record_id )
{
$sql = ("SELECT * from $table_name WHERE record_id='$record_id'");
//mysql_query etc.
//print out results
}
else
{
$sql = SELECT record_id, name ... etc.
//mysql_query etc.
//print out the record_id list as before
}
"Data" I almost got it but ...
Much appreciate your help, but I haven't quite got it working, and you'll see why, I'm sure, in following post when you see what I've got. There is a line out of place or some such thing. I seem always to be printing out the last record even though I see each record name listed by their name as I drag the mouse over the links following your suggestions. Actually, following almost all your suggestions.
Let me know. Again, I appreciate your help.
Al (act@iname.com)
Let me know. Again, I appreciate your help.
Al (act@iname.com)
Last edited by os2al on Sun Jun 30, 2002 8:41 am, edited 1 time in total.
Almost got there. Any suggestions to finish it?
Can you tell me what's wrong with this someone? I can only get the last record in the database to list the info, when I wanted to be able to click on each name on the list and get database information. Thanks in advance, again.
<?
$db_name = "database";
$table_name = "table";
$connection = @mysql_connect("localhost", "", "") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "SELECT id, Application, Name
FROM $table_name
";
$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");
$member_list = "<ul>";
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$Application = $row['Application'];
$Name = $row['Name'];
$member_list .= "<li><a href=\"members.php?$Name=$Name\">$Name</a>";
}
$member_list .= "</ul>";
?>
<HTML>
<HEAD>
<TITLE>Members</TITLE>
</HEAD>
<BODY>
<? echo "$member_list"; ?>
<h1>Member Information</h1>
<h2><? echo "$Name"; ?></h2>
<P><strong>Record Number:</strong> <? echo "$id"; ?><br>
<P><strong>Application:</strong> <? echo "$Application"; ?><br>
?>
</p>
<br>
<p><a href="main.html">Return to Main Page</a></p>
</BODY>
</HTML>
<?
$db_name = "database";
$table_name = "table";
$connection = @mysql_connect("localhost", "", "") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "SELECT id, Application, Name
FROM $table_name
";
$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");
$member_list = "<ul>";
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$Application = $row['Application'];
$Name = $row['Name'];
$member_list .= "<li><a href=\"members.php?$Name=$Name\">$Name</a>";
}
$member_list .= "</ul>";
?>
<HTML>
<HEAD>
<TITLE>Members</TITLE>
</HEAD>
<BODY>
<? echo "$member_list"; ?>
<h1>Member Information</h1>
<h2><? echo "$Name"; ?></h2>
<P><strong>Record Number:</strong> <? echo "$id"; ?><br>
<P><strong>Application:</strong> <? echo "$Application"; ?><br>
?>
</p>
<br>
<p><a href="main.html">Return to Main Page</a></p>
</BODY>
</HTML>
Code: Select all
$member_list .= "<li><a href="members.php?$Name=$Name">$Name</a>";Code: Select all
$member_list .= "<li><a href="members.php?Name=$Name">$Name</a>";