|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
As I'm new to php, I might just be missing the obvious, hey, it's been known to happen...
When I'm displaying data from a table, I am outputting just two of the fields. One is the unique auto-increment ID, the other is some descriptive text. I'm getting all of that on the screen ok, but I can't figure out how to turn the "ID" output into a link, which would be used to output a longtext field from the table (using the ID), on the same page. No problem with writing a href, but do I need another query here? Thanks in advance, the allnighter |
|
#2
|
|||
|
|||
|
Here's what I've got working, with most of the useless information stripped out :
<?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("jph001", $link); $result = mysql_query("SELECT * FROM mailarchive ORDER BY issuenumber DESC", $link); $num_rows = mysql_num_rows($result); $row = mysql_fetch_array($result, MYSQL_ASSOC); print "Choose from the " .($num_rows -1) . " articles in our archives.<P>"; $showissue = mysql_query("SELECT issuecontents FROM mailarchive WHERE issuenumber = $thisissue"); while ($row = mysql_fetch_array($result)) { if ($row["issuenumber"] != $num_rows) { // ignores empty row at end of table (for later use) $thisissue = $row["issuenumber"]; print "<A HREF=\"/mailarchive/testarchive.php?issuenumber=$thisissue\">" . "Issue : " . $row["issuenumber"] . "</A> " . $row["issuedate"] . "\t<B>" . $row["issuetitle"] . "</B>"; print "<BR>"; } } mysql_free_result($result); mysql_close($link); ?> If it's all a bit basic, we all start somewhere, right? |
|
#3
|
||||
|
||||
|
As a tip, add or die("MySQL query error: ".mysql_error()); to your mysql_query() statement...
It's good to be in the habit of using or die(); clauses to avoid potential debugging time. Also, the forum will colourize your code if you wrap it in [php] tags when you paste it into the forum. Anyways, where's the problem lying? I see your <a> link... I assume your testarchive.php page will display the extended text? |
|
#4
|
|||
|
|||
|
Quote:
It's the whole code around my <A> querystring. The page is showing the links ok, but I can't get them to refer back to the db & display the field 'showissue'. All the or die () stuff is there, I removed it only pasting the code in here. I need some code to use the $showissue variable, and this is where I'm stuck. Clicking the link does nothing as it is now. Appreciate the time you're giving to my newbie probs., thanks... |
|
#5
|
||||
|
||||
|
I don't quite follow you...
Your code, as it is right now, works properly... it displays a list of issues... you want to click an issue and see its contents... Something like this? PHP Code:
if this *is* what you're looking for, I'll explain my changes... if not, feel free to clarify... does this help? |
|
#6
|
|||
|
|||
|
Quote:
Thank you so much. That's absolutely what I was looking for. It's been a long time since I coded anything, so sorry if my line of questioning wasn't clear. I owe you one.... |
|
#7
|
||||
|
||||
|
do you understand what the code is doing?
would you like me to explain any of my coding/changes? |
|
#8
|
|||
|
|||
|
Now that I've been able to read through a short, properly written code
snippet, it's not difficult to follow. I guess it's time to get a book on the subject. Beats the coding we had to do as kids back in '82! Any ideas on a book suitable for newbies? Again I give you my thanks, Ive been able to adapt the code for various parts of the site I'm doing. Nice to replace 762 files with 2 simple db tables and 2 php-driven pages. No more having to do allnighters to get the job done. Thank you, thank you, thank you.... |
|
#9
|
||||
|
||||
|
I recommend the following books relating to PHP (links go to amazon)
PHP and MySQL Web Development This book is great for beginners. I found the examples to be simple and easy to follow. The authors set an appropriate pace and cover some excellent topics in both PHP and MySQL. Application Web Development with PHP 4.0 This book is more for the novice. The topics are slightly more advanced. If I remember correctly, there's more explanation then code. The examples are real life examples, you might find yourself borrowing some of their code for your own projects. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Problem using generated hyperlinks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|