pulling from two tables in db to two tables in php question
| From: | Vinny Gullotta | Date: | Wed, 28 Jan 2004 05:17:51 +0000 |
| Subject: | pulling from two tables in db to two tables in php question | ||
| Groups: | php.lang | ||
| Request: | Send a blank email to php-lang+get-549@lists.php.net to get a copy of this message | ||
What I need to do is this, I want to take the information from $i[3] in
table links and put it where $i[4] is in the table users. Basically, I query
the first table for some info, but to make the second table look pretty, I'd
like to use the info from $i[3] in place of the info I get from $i[4]. Does
this make sense? Here is my code:
#query the db
$query = "SELECT * FROM links ORDER BY ID";
$result = mysql_query($query)
or die(mysql_error());
#display column titles
echo "<table border align=center>";
echo "<tr>";
echo
"<td><center><small><b>Admin</b></small></td>";
echo
"<td><center><small><b>ID</b></small></td>";
echo
"<td><center><small><b>LINK</b></small></td>";
echo
"<td><center><small><b>CODE</b></small></td>";
echo "</tr>";
#display results
while($i = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td><small><a href=search.php?ID=",$i[0],">edit</a> |
";
echo "<a
href=delete.php?ID=",$i[0],">delete</a></small></td>";
echo "<td><small><center>", $i[0],
"</small></td>";
echo "<td><small><center><a href=",$i[1],">", $i[3],
"</a></small></td>";
echo "<td><small><a href=\"http://www.vjg.cc/mylinks/link.php?un=%n&ln=",
$i[0], "\">", $i[2], "</a></small>";
echo "</tr>";
}
echo "</table><br>";
#query the db
$query = "SELECT * FROM users ORDER BY ID DESC";
$result = mysql_query($query)
or die(mysql_error());
#display column titles
echo "<table border align=center>";
echo "<tr>";
echo
"<td><center><small><b>Admin</b></small></td>";
echo
"<td><small><center><b>ID</b></small></td>";
echo
"<td><small><center><b>USERNAME</b></small></td>";
echo
"<td><small><center><b>LINK</b></small></td>";
echo
"<td><small><center><b>Date/Time</b></small></td>";
echo "</tr>";
#display results
while($i = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td><small><a
href=deleteuser.php?ID=",$i[0],">delete</a></small></td>";
echo "<td><small><center>", $i[0],
"</small></td>";
echo "<td><small><center>", $i[1],
"</small></td>";
echo "<td><small><center><a href=\"", $i[2], "\"
target=\"_blank\">Link ID
#", $i[4], "</a></small></td>";
echo "<td><small><center>", $i[3],
"</small></td>";
echo "</tr>";
}
echo "</table>";