Solved

Php and mysql link

Posted on 2013-11-12
10
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 83

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
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 
LVL 83

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 43

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
 

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 83

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 83

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
The viewer will learn how to count occurrences of each item in an array.
Starting up a Project

628 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