How to make referral links? & How to make data from DB show as a link?

SpaceshipSpaceship
Watch

JsteRmX

Established Member
Impact
2
Hi, I have two questions...

1. I want to display data from my MySQL DB as links. I am pulling all the URLs from my DB and displaying them. How do I make them clickable links? Here is my code, which just displays them as text:
PHP:
$sql = "SELECT * FROM user_extended";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row['user_homepage']."</td>";
echo "</tr>";

2. How do I make unique referral links for all the members on my site? I want their link to look like this www.example.com/signup.php?ref=1 or something like that. and then i would like some way to track how many people each person refers. Could "ref" be replaced with the field name I used for the auto increment ID of each user? How does this work, i am very confused and have not found any good info on this when googling.

Thats it.. Thanks to anyone who can help!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
PHP:
$sql = 'SELECT * FROM user_extended';
$query = mysql_query($sql)or die($sql.'<br />'.mysql_error());
while($row = mysql_fetch_array($query)) {
echo '<tr><td>
<a href = "refer.php?ref='.$row['user_id_number'].'">'.$row['user_homepage'].'</a>
</td></tr>";

refer.php:
PHP:
$sql = 'SELECT * FROM user_extended where user_id_number = ' . $_GET['ref'] . ' limit 1';
$query = mysql_query($sql)or die($sql.'<br />'.mysql_error());
$referrals = mysql_result($query,0,'referrals') + 1;

$sql2 = 'update user_extended where set referrals = '.$referrals.' user_id_number = ' . $_GET['ref'] . ' limit 1';
mysql_query($sql2)or die($sql2.'<br />'.mysql_error());

Database fields needed: user_id_number (bigint) and referrals (bigint)
 
Last edited:
0
•••
wow thanks alot. i havent tried it yet, but it looks like exactly what i was looking for. i will report back after i try it out.

anyone know about how to make the URL pulled from the databse a clickable link?

I was able to get it to show up as a link that i can click on, but it was directing me to www.example.com/<td

this was the code for the line in question:
PHP:
echo "<a href=<td>".$row['user_homepage']."></td></a>";

this gives me a link, but again it takes me to ww.example.com/<td

any ideas?

Mikor, where would i post that first snippet of code you gave me? i guess i am a little confused. I would post it where i want them to see their referral link, right?
 
0
•••
Try this:
PHP:
echo '<td><a href="'.$row['user_homepage'].'">'.$row['user_homepage'].'</a></td>';
 
Last edited:
0
•••
:) Thanks lime! that worked great.
 
0
•••
well i wasnt able to get that referral code to work. maybe i am doing something wrong?
 
0
•••
JsteRmX said:
well i wasnt able to get that referral code to work. maybe i am doing something wrong?

you'll have to modify it to work with your database... and what dosnt work?
 
0
•••
well i keep getting a parse error.

i wanted to test the code before i added it to my core files, so i just made a test.php with my db connection info, and the first code you gave. I am getting this error:

Parse error: parse error, unexpected $ in /html/test.php on line 29

but there is no $ on line 29. line 29 is just </html> closing tag.


and then if i type the path to refer.php it says this:

SELECT * FROM user_extended where user_id_number = limit 1
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 1' at line 1


thanks.
 
0
•••
you have to goto refer.php with this url: refer.php?ref=a_number
 
0
•••
well i havent had time to really try and figure our the referral stuff yet, so i will let you know what happens when i try.

but for now... i am trying to figure out how to display data pulled from two different tables on the same line.

PHP:
$sql = "SELECT * FROM user_extended"; 
$query = mysql_query($sql); 
while($row = mysql_fetch_array($query)) { 
echo "<tr>"; 
echo '<td><p class="style1"><a href="'.$row['user_homepage'].'"><size=10>'.$row['user_homepage'].'</size></a></p></td>';   
echo "</tr>"; 
} 
$sql = "SELECT * FROM user"; 
$query = mysql_query($sql); 
while($row = mysql_fetch_array($query)) { 
echo "<tr>"; 
echo "<td><img src =\"" . $row['user_image']."\"></td>"; 
echo "</tr>";  
}

this makes the user_homepage appear above the user_image.

i want it to appear like:

www.example.com IMAGE HERE
www.example.com IMAGE HERE
www.example.com IMAGE HERE

image right after the link. I have many links and images in the database and it would be best to format it so that it is displayed on the page in a table with two columns. How do I achieve this?

Another weird problem i am having, is that only the image for the first link shows up, the one after that doesnt, though it is stored in the db just like the first. Any ideas? Thanks so much for all the help guys. =)
 
0
•••
mikor, where should i put this code?
PHP:
$sql = 'SELECT * FROM user_extended'; 
$query = mysql_query($sql)or die($sql.'<br />'.mysql_error()); 
while($row = mysql_fetch_array($query)) { 
echo '<tr><td> 
<a href = "refer.php?ref='.$row['user_id_number'].'">'.$row['user_homepage'].'</a> 
</td></tr>";

and what is 'user_homepage' doing in there?

sorry, i am really lost as to how to accomplish this. So where do i put this code? and if this work, someone will use the refer.php?ref=number and it will take them to what page? the refer.php page? But i would like it to take them to the main page, www.example.com. So could i put the refer.php somewhere else, so that they can get directed to www.example.com when someone uses the referral link?
 
0
•••
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Catchy
CatchDoms
DomainEasy — Live Options
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back