mysql-php question re: clickable listed fields

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
os2al
Forum Newbie
Posts: 14
Joined: Tue Jun 25, 2002 3:26 pm

mysql-php question re: clickable listed fields

Post by os2al »

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
Data
Forum Newbie
Posts: 15
Joined: Tue Jun 25, 2002 4:14 am
Location: Aberdeen, Scotland

Post by Data »

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
}
os2al
Forum Newbie
Posts: 14
Joined: Tue Jun 25, 2002 3:26 pm

"Data" I almost got it but ...

Post by os2al »

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)
Last edited by os2al on Sun Jun 30, 2002 8:41 am, edited 1 time in total.
os2al
Forum Newbie
Posts: 14
Joined: Tue Jun 25, 2002 3:26 pm

Almost got there. Any suggestions to finish it?

Post by os2al »

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>
Pekka
Forum Newbie
Posts: 5
Joined: Sun Jun 16, 2002 11:48 am

Post by Pekka »

Code: Select all

$member_list .= "<li><a href="members.php?$Name=$Name">$Name</a>";
should be

Code: Select all

$member_list .= "<li><a href="members.php?Name=$Name">$Name</a>";
i.e. no dollar signs on posted variable names.
Post Reply