How - Each Record to have a clickable url link

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
soundsdodgy
Forum Newbie
Posts: 2
Joined: Fri Jun 17, 2005 9:53 am
Location: London

How - Each Record to have a clickable url link

Post by soundsdodgy »

Extremely Raw code at the mo'.... but can you shed some light on this...

Have a Form that enters Data into a Database (One element being Title
another being a URL among others)
http://www.topweb.co.uk/temp/statsenter_form.txt <<<<HTML Form Code
http://www.topweb.co.uk/temp/statsenter_script.txt <<<<PHP Script Code
Obviously You'll need to change usual details to get it to work on your system.

Once Submitted the Data is indeed entered - It then proceeds to display the
whole contents (ugly display at moment, but will be tidied up) of the
database - However I want the Title to be a clickable link to wherever the
entered URL references.

The following may make what I need to do a little clearer...

Within the php script you'll see a commented out line that I tried - this
however Gives ALL the records 'Title' elements the same value which is the
last entered URL link, as it's in a while loop - obviously what I want is each record to have each Title link to its Unique Url link...

So every time different details are entered into the Form, then database contents displayed, each Title is a link to that url...

Have searched everywhere for a solution, but no joy...

My php skills are limited so please respond as if your talking to an alien...

Thanks in advance

Soundsdodgy... Submitted Fri 17th June 4pm (London, England)
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

Well we need to see your sql script too, maybe there's something wrong with that since you always get the same data as title.. :)
soundsdodgy
Forum Newbie
Posts: 2
Joined: Fri Jun 17, 2005 9:53 am
Location: London

Found The answer - For All Others

Post by soundsdodgy »

Dreamline - Appologies, didnt realise link to see php script didnt work correctly... Have Found Answer now - See Below..

What I had to output the contents was as below:

$sql = "SELECT * FROM stats";
$res = mysql_query( $sql, $dbconnect);

echo "<table align='center'>\n";
echo "<tr><td><b>Title</b></td>
<td><b>URL Link</b></td>
<td><b>Broad Subject</b></td>
<td><b>Narrow Subject</b></td>
<td><b>Description</b></td>
<td><b>Coverage</b></td>
</tr>\n";
while( $row = mysql_fetch_array( $res)) {
echo "<tr>\n";
echo "<td>".$row[ "title"]."</td>";
echo "<td><a href =\"urllink\">".$row[ "title"]."</a></td>";
echo "<td>".$row[ "broad_subject"]."</td>";
echo "<td>".$row[ "narrow_subject"]."</td>";
echo "<td>".$row[ "description"]."</td>";
echo "<td>".$row[ "coverage"]."</td>";
echo "</tr>\n";
}
echo "</table>\n";

Which was taking the latest value of urllink from the Form, whereas what I needed was to take the value of urllink from the Database as below:

$sql = "SELECT * FROM stats";
$res = mysql_query( $sql, $dbconnect);

echo "<table align='center'>\n";
echo "<tr><td><b>Title</b></td>
// <td><b>URL Link</b></td> Not Now Needed
<td><b>Broad Subject</b></td>
<td><b>Narrow Subject</b></td>
<td><b>Description</b></td>
<td><b>Coverage</b></td>
</tr>\n";
while( $row = mysql_fetch_array( $res)) {
echo "<tr>\n";
echo "<td><a href=\"".$row["urllink"]."\">".$row["title"]."</a></td>";
echo "<td>".$row[ "broad_subject"]."</td>";
echo "<td>".$row[ "narrow_subject"]."</td>";
echo "<td>".$row[ "description"]."</td>";
echo "<td>".$row[ "coverage"]."</td>";
echo "</tr>\n";
}
echo "</table>\n";

Thanx all - Hope this helps someone else...
Post Reply