Jump to content


Photo

Help with simple php script


  • Please log in to reply
3 replies to this topic

#1 Yojance

Yojance
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 07 May 2006 - 06:35 AM

Hello, I have started learning php a week ago and I'm trying to put something together and I was wondering how can I extract every single row from this script and show it.

<?php
$db = "links";
$dbcon = mysql_connect("localhost", "user", "pass");
    mysql_select_db($db, $dbcon);
$url =             $_POST['url'];
$title =         $_POST['title'];

$addquery = "INSERT INTO links(title, url) 
                    VALUES('$title', '$url') ";
if(isset($_POST['submit'])) {
    mysql_query($addquery);
}
?>

Thanks for reading and hope someone can help me.

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 May 2006 - 08:26 AM

$sql = "select * from links";
$results = mysql_query($sql) or die (mysql_error());

while ($info = mysql_fetch_array($results)) {
   echo $info['title'] . " " . $info['url'] . "<br>";
}
will output:

title url
title url
title url
.
.
.

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 Yojance

Yojance
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 07 May 2006 - 03:58 PM

Thanks for your replay, I copy and pasted that into my editor and I played with the last line to make it look like a regular link using <a href="blahblah">title</a> .
The problem is that the title is correct, but for the url, it goes straight to the same page Im looking at the links.

Here is the code I used:
echo "<a href=\"".$info['url']."\">".$info['title']."</a><br/>";

So.. no matter how many links I have on that page, it's linking them all to the same page, called add_links.php
Any idea why this is happening?


#4 Yojance

Yojance
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 09 May 2006 - 05:17 AM

I fixed it now, a friend of mine helped me. Thank you all anyways.
Thank you Crayon for the help :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users