Solved

Php and mysql link

Posted on 2013-11-12
10
245 Views
Last Modified: 2014-06-04
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
0
Comment
Question by:Monte2256
  • 5
  • 4
10 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39642719
It's not clear where the second part is coming from in the first part.  What does $row['description'] show by itself?
0
 

Author Comment

by:Monte2256
ID: 39643039
That is coming from mysql database
0
 

Author Comment

by:Monte2256
ID: 39643048
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
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39643126
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?
0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39643315
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!
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Monte2256
ID: 40112212
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>

split link


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>";
            
            
            
?>
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40112253
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

0
 

Author Comment

by:Monte2256
ID: 40112261
Yes thank you that's a mistake, but is there a better way of doing this?
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40112270
I don't know but that should fix the problem with the code you posted.
0
 

Author Closing Comment

by:Monte2256
ID: 40112274
Thank you
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
A short article about problems I had with the new location API and permissions in Marshmallow
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now