Solved

Php and mysql link

Posted on 2013-11-12
10
250 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 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
running code or pseudo code of table structure 5 25
Math Equation 23 87
A query works with MySQL 5.6, mariadb 10.1 but fail on MySQL 5.7 6 39
MySQL Memory Keeps Increasing 4 35
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

777 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