MySQL Forums
Forum List  »  PHP

Dynamically linking to mysql results record - using while mysql_result loop
Posted by: Gerald Taber
Date: November 29, 2012 12:47AM

I am Using a while ($i < $num) { ... ?> $i++ LOOP to retrieve and display a single table's NAME data and then link that name result to an individual .php page; containing each Row/Record's entire dataset.

Currently trying to link to anchored url / php file containing all the results formatted within an HTML Table so that the ANCHOR=ROW#.

I would prefer to generate or link to a single .PHP file for each row's result query based on the ROW or Key ID field. There is probably a MySQL / php function & much more effecient way to do this, but here is newbie post after being a member since 2008.

I have Two .php files, both can pull and view the data individually, but I am stuck on the logic to link each NAME's result to the Record's full query result in a second .php file. Thank you in advance for assisting me in the most efficient and simple way to link from each result in the LINKS page to the ROW's formatted data in the VIEW page.

File (1) LINK PAGE: scholar_get_view_links.php

<html xmlns="http://www.w3.org/1999/xhtml">;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Available Scholarships NAME View</title>
</head>
<body>
<?php
include("my_database_connection_File.php");
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM scholarship ORDER BY name ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table bgcolor="#CCCCCC" width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif"><ul>Scholarship Name</ul></font></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"scholarship_id");
$f1=mysql_result($result,$i,"name");
$f2=mysql_result($result,$i,"updated");
$f3=mysql_result($result,$i,"awarded");
$f4=mysql_result($result,$i,"due_date");
$f5=mysql_result($result,$i,"intro");
$f6=mysql_result($result,$i,"requirement");
$f7=mysql_result($result,$i,"decision");
$f8=mysql_result($result,$i,"contact");
$f9=mysql_result($result,$i,"gpa");
$f10=mysql_result($result,$i,"ethnic_req");
$f11=mysql_result($result,$i,"school_req");
$f12=mysql_result($result,$i,"special_req");
$f13=mysql_result($result,$i,"need");
$f14=mysql_result($result,$i,"renewable");
$f15=mysql_result($result,$i,"audit");
$f16=mysql_result($result,$i,"updated");
?>
<tr>
<td valign="top"><font face="Arial, Helvetica, sans-serif"><a href="scholar_get_view_page.php?num"><?php echo $f1; ?></a></font></td>
</tr>
<?php
$i++;
}
?> 
</table>
</body>
</html>

File (2) VIEW PAGE: scholar_get_view_page.php

<html xmlns="http://www.w3.org/1999/xhtml">;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Single Scholarship View </title>
</head>
<body>
<?php
include("my_database_connection_File.php");
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM scholarship ORDER BY name ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table bgcolor="#D2FFFF" width="100%" border="0" cellspacing="2" cellpadding="2">
<?php
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"scholarship_id");
$f1=mysql_result($result,$i,"name");
$f2=mysql_result($result,$i,"amount");
$f3=mysql_result($result,$i,"awarded");
$f4=mysql_result($result,$i,"due_date");
$f5=mysql_result($result,$i,"intro");
$f6=mysql_result($result,$i,"requirement");
$f7=mysql_result($result,$i,"decision");
$f8=mysql_result($result,$i,"contact");
$f9=mysql_result($result,$i,"gpa");
$f10=mysql_result($result,$i,"ethnic_req");
$f11=mysql_result($result,$i,"school_req");
$f12=mysql_result($result,$i,"special_req");
$f13=mysql_result($result,$i,"need");
$f14=mysql_result($result,$i,"renewable");
$f15=mysql_result($result,$i,"audit");
$f16=mysql_result($result,$i,"updated");
?>
<tr>
<td valign="top"><font face="Arial, Helvetica, sans-serif"><b><?php echo $f1; ?></b>
<br />
<br />
<b>Amount:</b> <?php echo $f2; ?>
<br />
<br />
<b>Awarded:</b> <?php echo $f3; ?>
<br />
<br />
<b>Due By:</b> <?php echo $f4; ?>
<br /><br />
<?php echo $f5; ?>
<br />
<br />
<b>Requirements:</b> <br /><br /><?php echo $f6; ?>
<br />
<br />
<b>Decisions:</b> <?php echo $f7; ?>
<br />
<br />
<b>Contact:</b>  <br /><?php echo $f8; ?>
<br />
<b>Ethnic Requirment:</b><?php echo $f10; ?>,&nbsp;<b>School Requirment:</b><?php echo $f11; ?>,&nbsp;<b>Special Requirement:</b><?php echo $f12; ?>,&nbsp;<b>Financial Need:</b><?php echo $f13; ?>,&nbsp;<b>Renewable:</b><?php echo $f14; ?>
<br />
<br />
<b>Last Updated:</b><?php echo $f16; ?>
</font>
<br />
<!-- THIS IS THE SEPORATION BREAK FOR EACH RECORD -->
<hr size="10" />
</td>
<?php
$i++;
}
?> 
</table>
</body>
</html>

Can I either PASS the variable data from the LINKS page to the VIEW page or basically use all the results to display the record nicely in the html table that I have in the VIEW page, via an anchor?

Also, the '<a href="scholar_get_view_page.php?num">' code from the LINKS page was my feeble attempt to use session data of either the $i or $num variable to locate or link to and from the ROW that the loop is currently displaying or linking too, of course this doesn't work or do anything, and could simply be '<a href="scholar_get_view_page.php">' and get the same results. But with this I hope you get the idea that i am just trying to link / view all the data for each row in a nicely formatted page starting from the live results of a single table my mysql database.

Also if I used the 'scholar_get_view_page.php' as is, and had a name anchor to link from the LINKS file, it could indeed be almost usable as is, it would be a bit crude and probably very inefficient , but I will take any suggestions for linking to the specific Records data, based on its name and or row number, Key Field ID or anything that makes sense to display the entire record in this HTML Table in File 2.



Edited 1 time(s). Last edit at 11/29/2012 04:41AM by Gerald Taber.

Options: ReplyQuote


Subject
Written By
Posted
Dynamically linking to mysql results record - using while mysql_result loop
November 29, 2012 12:47AM
November 29, 2012 10:19AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.