Link to home
Start Free TrialLog in
Avatar of Monte2256
Monte2256

asked on

Php and mysql link

I'm pulling a link out of my mysql database and trying to add an id to it.  Here is the code to pull the data out of the database:

<?php 
$sql = mysql_query("SELECT * FROM ybgstores WHERE cat_id=$cat_id ORDER BY storename");

echo" <table width='100%' border='0'>
  <tr>
    <th width='25%'><h5>Store</h5></th>
	<th width='50%'><h5><div align='center'>Description</div></h5></th>
    <th width='25%'><h5><div align='center'>Donation</div></h5></th>

 </tr>";

while ($row = mysql_fetch_array($sql)){
		echo "<tr>";
		echo "<td width='25%'>".$row['logo_link']."</td>";
		echo "<td width='50%'><div align='left'>".$row['description']."</div></td>";
		echo "<td width='10%'><div align='center'>".$row['donat_percent']."</div></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td colspan='3'><hr size='1' /></td>";
		echo "</tr>";
}
		echo "</table>";
	
?>

Open in new window


Which gives my this:

<a href="http://www.tkqlhce.com/click-7227717-10716258[b]?sid= echo $sid;[/b]" target="_blank">
<img src="http://www.ftjcfx.com/image-7227717-10716258" width="75" height="75" alt="AllPosters.com   " border="0"/></a>

Open in new window


Now i want to add the sid?  - ?sid= echo $sid; but it only renders it as text it dosen't process the php code and the sid variable.

What am I missing and yes I'm new at this.  Thank in advance
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

It's not clear where the second part is coming from in the first part.  What does $row['description'] show by itself?
Avatar of Monte2256
Monte2256

ASKER

That is coming from mysql database
Description is in the database here is the website that I'm working on. http://pw5n.com/ybg/products.php?sid=Feeding%20America

If you look att he link behind the image you will see what I'm talking about.

Thank you
Bill
The problem is that there are a number of ways to add things to the text.  I am having trouble figuring out Exactly what is coming from the database.  Once I know that, I can tell how to add the 'sid' part.  Does it need to go in the middle of the text or at the end?
The link behind the image on your site is this:

http://www.tkqlhce.com/click-7227717-10716258?sid=Feeding America

There is no PHP code echoing out - it appears to be working as you expect it to, unless I'm missing something!
Hi David

This works but is there a better way

It has to go in the middle of the link, my client enters and breaks the link into parts to putting the sid=  in as seen in the picture below.  The on the page the link is reassembled and the sid code is echoed from the session.

first part of link:
<a href="http://www.tkqlhce.com/click-7227717-11304284?sid=

Second part of link:
" target="_blank">
<img src="http://www.tqlkg.com/image-7227717-11304284" width="89" height="90" alt="1SaleADay.com - Great Deals, Just 24 Hours" border="0"/></a>

User generated image


The session data "feeding-america" has to go in the middle of the link right after the sid=

my code to reassemble the link looks like this and adds the session id data in the middle:
<?php
$sql = mysql_query("SELECT * FROM ybgstores WHERE cat_id=$cat_id ORDER BY storename");

echo" <table width='100%' border='0'>
  <tr>
    <th width='25%'><h5>Store</h5></th>
      <th width='50%'><h5><div align='center'>Description</div></h5></th>
    <th width='25%'><h5><div align='center'>Donation</div></h5></th>

 </tr>";

while ($row = mysql_fetch_array($sql)){
            echo "<tr>";
            echo "<td width='25%'>".$row['logo_link']."&sid=$_SESSION[sid] target='_blank'".$row['logo_link2']."</td>";
            echo "<td width='50%'><div align='left'>".$row['description']."</div></td>";
            echo "<td width='10%'><div align='center'>".$row['donat_percent']."</div></td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td colspan='3'><hr size='1' /></td>";
            echo "</tr>";
}
            echo "</table>";
            
            
            
?>
You're putting target='_blank' in there twice.  Should probably be...

echo "<td width='25%'>".$row['logo_link']."&sid=".$_SESSION[sid].$row['logo_link2']."</td>";

Open in new window

Yes thank you that's a mistake, but is there a better way of doing this?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you