[thelist] php questions: using multiple mysql tables in a script and anchors/links

Heather Ruggio hjrbaby at yahoo.com
Mon May 7 19:11:48 CDT 2001


I am new to the PHP world, and I have encountered some
problems in the scripts from a training book that
neither that book nor a MySQL book that I have can
answer.  Here they are:

Question 1. How do you access information from
multiple tables with the same script?  The practice
scripts in the book are for a news source where
authors can enter articles and viewers can access
them.  The first looks like this (the parts that need
changing):

*****
$sql = "INSERT INTO news 
VALUES(NULL,'$heading','$body','$date','$auth','$auth_email')";
mysql_query($sql);
*****
<form action="data_in.php" method="post">
Name: <br><input type="text" name="auth"><p>
Email: <br><input type="text" name="auth_email"><p>
Heading: <br><input type="text" name="heading"><p>
News: <br><textarea cols=40 rows=20 name="body"
wrap="virtual"></textarea><p>
<input type="submit" name="submit" value="Submit
News!">
</form>
*****

And the second like this:

*****
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
	print("<tr><td bgcolor=\"#003399\"><b>");
	printf("<font
color=\"white\">%s</font></b></td></tr>\n",
	$row["heading"]);
	printf("<td>By: <a hjref=\"mailto:%s\">%s</a>\n",
	$row2["author_email"], $row2["author_name"]);
	printf("<br>Posted: %s<hr>\n",
	$row["date"]);
	printf("%s</td></tr>\n",
	$row["body"]);
	}
*****

The book gives a half-assed 5-line description of what
to change in the second script to access both tables
(one for the authors and one for the news articles,
with the author id in common), but it doesn't work.  I
have tried many variations on both scripts, but I just
can't figure out how to do this.

Question 2. Is there any way to link to another page
on a PHP site when both pages are in the same script? 
There is another practice script in this book that is
basically an online magazine, but the whole thing is
in one script, so when you are in a page, there is no
way to get back to the front page.  And there is
another page to enter articles, but there is no way to
get there from the front page: you have to type the
URL and then ?action=post to get there.  I tried
setting up href links to that specific part, but they
don't work.

I would appreciate advice on these problems.

Thank you in advance,
Heather Ruggio

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/




More information about the thelist mailing list