954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Passing db data to end of a url in PHP

I'm trying to grab a value from a mySQL database and put that value on the end of a url path

e.g. http://url.com/$valuefromdb

Is there any tutorials to how to do this or can anybody recommend how to tackle this?

Kind Regards


JayJ

JayJ
Newbie Poster
17 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

I've tried various things now to attempt to get this to work - all to no avail.

My current is

// Define variables
$filename = mysql_query("SELECT log_filename FROM uploads_log");
$issueno = mysql_query("SELECT log_issue FROM uploads_log");
$issuemonth = mysql_query("SELECT log_month FROM uploads_log");

print "<a href=www.url/uploads/$filename><?php echo Issue $issueno.", ".$issuemonth; ?></a>";
JayJ
Newbie Poster
17 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 
<?php

$xconn =mysql_pconnect("localhost","username","userpassword") or die("unable to connect to dbengine".mysql_error());// assuming a connection to mysql db
$qry = "select field from table" ; //your sql statement


$exec_qry = mysql_query($qry) or die ("query failed".mysql_query());

$pulling =  mysql_fetch_array( $exec_qry,MYSQL_ASSOC);

foreach($pulling as $valuefromdb);
printf('%s','<a href="targetlink.ext". "?parameter= ". $valuefromdb . " '  ) ;

mysql_close($xconn);

?>

I hope this helps, Goodluck.

hakimkal
Newbie Poster
20 posts since Dec 2007
Reputation Points: 10
Solved Threads: 5
 

Thanks.

I've tried that and got the following errors:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in table2.php on line 7

Warning: Invalid argument supplied for foreach() in table2.php on line 9

JayJ
Newbie Poster
17 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

Hi...
Try this....

<?php

// Define variables
$result1 = mysql_query("SELECT log_filename FROM uploads_log");
$filename = mysql_fetch_array($result1);
$result2 = mysql_query("SELECT log_issue FROM uploads_log");
$issueno = mysql_fetch_array($result2);
$result3 = mysql_query("SELECT log_month FROM uploads_log");
$issuemonth = mysql_fetch_array($result3);

print "<a href='www.url/uploads/".$filename."'>Issue ".$issueno.", ".$issuemonth."</a>"; 

?>
sikka_varun
Junior Poster in Training
94 posts since Dec 2008
Reputation Points: 11
Solved Threads: 12
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You