Passing Variable within URL coming from SQL DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
haresh.chugani
Forum Newbie
Posts: 2
Joined: Sat May 09, 2009 5:22 am

Passing Variable within URL coming from SQL DB

Post by haresh.chugani »

Request help to pass variable in URL coming from database.... it behaves differently.
Sample below. Your help will be highly appreciated. Tx.

Code: Select all

 
<?
//Database Connection
$dbcnx = @mysql_connect('localhost', 'Haresh', 'REMOVED');
mysql_select_db('iwddb',$dbcnx);
$memberidresult = @mysql_query('SELECT * FROM members');
//db hase only 2 fields, memberid & name
 
while ($memberarray = mysql_fetch_array($memberidresult)) 
{
    $memberid = $memberarray['memberid'];
    echo '<p>The member id is ' . $memberid . '</p>';
 
    $namelink = $memberarray['name'];
    echo '<p>
    //actual value of namelink in database = 
    <a href="http://www.xyz.com/x/?x=c&z=s&v=1801659&k=' . $memberid . '" target="_blank">Name Link</a>
    // end of actual value of name link in database
    </p>';
}
//Till here it is fine, we are able to pass $memberid's actual VALUE in the url
 
 
// ERROR STARTS HERE when we insert the above actual link in the database as above & call it from there.
echo '<p>The name link via DB ' . $namelink . '</p>';
// ERROR: When $namelink is called via DB, $memberid is not getting passed and is called as (' . $memberid . ') instead of its value
// pls help. Thanks.
 
?>
 
Last edited by Benjamin on Sat May 09, 2009 9:59 am, edited 1 time in total.
Reason: Added code tags, removed password.
bozy12v
Forum Newbie
Posts: 2
Joined: Sat May 09, 2009 2:36 pm
Location: Romania

Re: Passing Variable within URL coming from SQL DB

Post by bozy12v »

I don't understand what you want
The error si because the last "echo" is outside the while loop ....
bozy12v
Forum Newbie
Posts: 2
Joined: Sat May 09, 2009 2:36 pm
Location: Romania

Re: Passing Variable within URL coming from SQL DB

Post by bozy12v »

Code: Select all

<?
//Database Connection
$dbcnx = @mysql_connect('localhost', 'Haresh', 'REMOVED');
mysql_select_db('iwddb',$dbcnx);
$memberidresult = @mysql_query('SELECT * FROM members');
//db hase only 2 fields, memberid & name
 
while ($memberarray = mysql_fetch_array($memberidresult)) 
{
    $memberid = $memberarray['memberid'];
    echo '<p>The member id is ' . $memberid . '</p>';
 
    $namelink = $memberarray['name'];
    echo '<p>
    //actual value of namelink in database = 
    <a href="http://www.xyz.com/x/?x=c&z=s&v=1801659&k=' . $memberid . '" target="_blank">Name Link</a>
    // end of actual value of name link in database
    </p>';
   echo '<p>The name link via DB ' . $namelink . '</p>';
 
}
 
 
?>
Last edited by Benjamin on Sun May 10, 2009 12:30 pm, edited 1 time in total.
Reason: Changed code type from text to php.
haresh.chugani
Forum Newbie
Posts: 2
Joined: Sat May 09, 2009 5:22 am

Re: Passing Variable within URL coming from SQL DB

Post by haresh.chugani »

Hi, Thanks for trying to help. however, i think you did not get the problem right.
Let me put it this way: In the above code:

1. the variable $memberid value in database = 1002
2. variable $namelink in the database has the value = "<a href="http://www.xyz.com/x/?x=c&z=s&v=1801659&k=' . $memberid . '" target="_blank">Name Link</a>"

3. Now, when we run this code, the text "Name Link" refers to the link = "http://www.xyz.com/x/?x=c&z=s&v=1801659&k=' . $memberid . '" target="_blank".

NOTE: THE EXPECTED RESPONSE is the value of $memberid to be populated within the link:
i.e: "http://www.xyz.com/x/?x=c&z=s&v=1801659&k=1002" target="_blank"
Post Reply