PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 30th, 2005, 08:27 PM
allnighter allnighter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Ireland
Posts: 10 allnighter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 59 m 59 sec
Reputation Power: 0
Question Problem using generated hyperlinks

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

Reply With Quote
  #2  
Old January 31st, 2005, 11:52 AM
allnighter allnighter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Ireland
Posts: 10 allnighter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 59 m 59 sec
Reputation Power: 0
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?

Reply With Quote
  #3  
Old January 31st, 2005, 12:12 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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?

Reply With Quote
  #4  
Old January 31st, 2005, 12:56 PM
allnighter allnighter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Ireland
Posts: 10 allnighter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 59 m 59 sec
Reputation Power: 0
Arrow Using link doesn't change page contents.

Quote:
Originally Posted by MadCowDzz
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?


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...

Reply With Quote
  #5  
Old February 1st, 2005, 08:47 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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:
<?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($resultMYSQL_ASSOC);

print 
"Choose from the " .($num_rows -1) . " articles in our archives.<P>";

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=\"".$_SERVER['PHP_SELF']."?issuenumber=$thisissue\">" "Issue : " $row["issuenumber"] . "</A> " $row["issuedate"] . "\t<B>" $row["issuetitle"] . "</B>";
        print 
"<BR>";
    }
}

if(isset(
$_GET['issuenumber']) {

    
$showissue mysql_query("SELECT issuecontents FROM mailarchive WHERE issuenumber=".$_GET['issuenumber']);
    
$row mysql_fetch_array($showissue)
    print 
"This is the issue contents: <BR>".$row['issuecontents'];
}
?>


if this *is* what you're looking for, I'll explain my changes...
if not, feel free to clarify...

does this help?

Reply With Quote
  #6  
Old February 2nd, 2005, 12:51 AM
allnighter allnighter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Ireland
Posts: 10 allnighter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 59 m 59 sec
Reputation Power: 0
Thumbs up Bullseye!

Quote:
Originally Posted by MadCowDzz
does this help?


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....

Reply With Quote
  #7  
Old February 2nd, 2005, 09:06 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
do you understand what the code is doing?
would you like me to explain any of my coding/changes?

Reply With Quote
  #8  
Old February 3rd, 2005, 05:14 AM
allnighter allnighter is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Ireland
Posts: 10 allnighter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 59 m 59 sec
Reputation Power: 0
Smile

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....

Reply With Quote
  #9  
Old February 3rd, 2005, 09:34 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Problem using generated hyperlinks


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT