links in my code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
df75douglas
Forum Newbie
Posts: 6
Joined: Thu Nov 10, 2011 1:30 am

links in my code

Post by df75douglas »

hello ,

I am trying to get the first name in my table to link to "user_info.php"

right now the way I built my table every attribute is a link.

any ideas on how to fix this?

here is my code

Code: Select all

<html><head><title>cset3300 hw5</title></head><body>

<h3> This is the Home Page, for the search page (part 3), please use the link below.</h3>

<a href = "search.php">Search Page</a>
<?php
//connect to  database 
mysql_connect("localhost","dfuller3","dfuller37318"); 

//specify database 
mysql_select_db("dfuller3") or die("Unable to select database"); 

// Build SQL Query  
$query = "select address_book.first_name,address_book.last_name,address.street, address.city, address.state,
 address.zip_code
 from address, address_book where address.address_book_id = address_book.id  
AND address.address_type = 'home'
  order by first_name ASC"; 

$result = mysql_query($query) or die(mysql_error());



$fields_num = mysql_num_fields($result);

echo "<h1>Table:People and Places</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
 
 //printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
    
  echo "<td><a href=\"user_info.php\">$cell</a></td>";

    echo "</tr>\n";
}


mysql_free_result($result);
?>
</body></html>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: links in my code

Post by Christopher »

Just guessing at what "trying to get the first name in my table to link to user_info.php" means. Maybe this:

Code: Select all

 //printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";
    
  echo "<td><a href=\"user_info.php\">{$row['name']}</a></td>";

    echo "</tr>\n";
}
(#10850)
Post Reply