Greetings people.

I've just recently discovered PHP, and have just created my first dynamic PHP-document, which fills a table with data from my SQL db. It works quite well, but what I'd like is to have hyperlinks in one of the three columns (header), pointing towards whatever adress posted from the original form (thus I need a fourth text field).

I've looked around both Google almighty and these forums, but I couldn't find an easy enough way for me to go. :(

If any of you know some basic solution, I'd greatly appreciate it (I'm quite slow, mind you...)

I've created the proper table in my db, and the three categories (header, category and date) match up. All fields in the table are of the VARCHAR data type. I've tried playing around with various data types, but to no avail.

The source from my files below:

input.html:

<html>

<form action="formprocessing.php" method="post">

Header: <input type="text" name="header"><br>
Category: <input type="text" name = "category"><br>
Date: <input type="text" name = "date"><br>
<input type="submit" value="Post">
</form> 

</html>

formprocessing.php

<?

$header=$_POST['header'];
$category=$_POST['category'];
$date=$_POST['date'];

mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("database2") or die(mysql_error());
mysql_query("INSERT INTO `mytable` VALUES ('$header', '$category', '$date')");


?>

And finally, the entry-page:

list.php

<?php 
$database="database2"; 
mysql_connect ("localhost", "user", "password"); 

@mysql_select_db($database) or die( "Unable to select database"); 

$result = mysql_query( "SELECT * FROM mytable" ) 
or die("SELECT Error: ".mysql_error()); 

$num_rows = mysql_num_rows($result); 

print "<table width=804 border=1><tr><td width=35%><b>Header</b></td><td><b>Category</b></td><td><b>Date</b></td></tr></table><br>\n";

print "<table width=804 border=1>\n"; 
while ($get_info = mysql_fetch_row($result)){ 

print "<tr>\n"; 

foreach ($get_info as $field) 

print "\t<td width=35%>$field</td>\n"; 

print "</tr>\n"; 
} 
print "</table>\n"; 


?>

Again, any help would be greatly appreciated.

use this please for listing page

<?php 
$database="database2"; 
mysql_connect ("localhost", "user", "password"); 
@mysql_select_db($database) or die( "Unable to select database"); 
$result = mysql_query( "SELECT * FROM mytable" ) 
or die("SELECT Error: ".mysql_error()); 

$num_rows = mysql_num_rows($result); 

echo "<table width=804 border=1><tr><td width=35%><b>Header</b></td><td><b>Category</b></td><td><b>Date</b></td></tr></table><br>\n";

echo "<table width=804 border=1>\n"; 
while ($get_info = mysql_fetch_row($result)){ 

echo  "<tr>\n"; 

echo  '\t<td width=35%><a href="www.yahoo.com" title="my link" >'.$get_info['header'].'</a></td>\n';  // link on header. same you can do with other fields
echo  "\t<td width=35%>".$get_info['category']."</td>\n"; 
echo  "\t<td width=35%>".$get_info['date']."</td>\n"; 

echo  "</tr>\n"; 
} 
echo  "</table>\n"; 


?>

Thank you! I'll try it out right away. I feel quite stupid whenever the solution turns out to require but the tiniest modification...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.