Sometimes it will, and then it won't

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Simulacra
Forum Newbie
Posts: 7
Joined: Sun Sep 11, 2005 9:25 am

Sometimes it will, and then it won't

Post by Simulacra »

I'm trying to create a button that will bring you back to a certain page, i.e.: You where on a page that shows you thumbnails of some pics from a person, who's pic urls are held in a database, you click on a thumbnail and it show you the full thing, but it will only put a button going back sometimes.
The Code is:

Code: Select all

<?php

      echo "<center><table cellpadding='5' border='1'>";

      echo "<tr>";

    if (isset($_GET["pic"]))
      {

	echo "<td valign='center'>
	<img src='".$_GET['pic']."' border='0'></td>";
        
  $connection = mysql_connect($host,$user,$password)    #13
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)          #15
       or die ("Couldn't select database");
	   
	$thing = mysql_escape_string($_GET['pic']);
	
  $query = "SELECT person,pic FROM pics WHERE pic = '".$thing."'";   
  $result = mysql_query($query)
       or die ("Couldn't execute query."); 
$row = mysql_fetch_row($result);
if ($_GET["pic"] == $row[1])
{
  echo "<div align='center'>
        <table border='1' bgcolor='#999999'><td><a href='show.php?find=".$row[0]."'>
		<font color='white' face='Verdana, Arial, Helvetica, sans-serif' size='2'>
		Back to ".$row[0]." Section</font></a></td></table></div>";
	}	
		
      }
	  else
	  {
	  echo "No pics found";
	  }

      echo "</tr><center></table>";                            #55


		
?>
I know I have the If at the end, but that is when (as you can see) the link goes wrong and gives a link show.php?find= , it should show show.php?find=$Username, $Username being the page of the persons thumbnails
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

simulacra,

try using the $row = mysql_fetch_assoc(); echo $row['Username'];

personally if your getting back only 1 result you should be using a $row=mysql_result($rs,0,'Username');

but your results are greater than 1 then you need a loop statement

Kendall
Post Reply