Page 1 of 1

Showing pictures using links in database

Posted: Sat Jul 22, 2006 1:26 pm
by NiGHTFiRE
Hey,
I've got a MySQL table with a column where diffrent pictures names are in.
This is my code:

Code: Select all

<?php

  include("db.php");
  include("functions.php");

  $sql = "SELECT COUNT(id) FROM auction where status='ny'";
  $result = mysql_query($sql);
  echo mysql_error();
  //$limit = 3; // Antal "nya" nyheter

  $row = @mysql_fetch_array($result); 
  $numrows = mysql_result($result, 0); // antal i databasen 

  if (mysql_result ($result , 0) <= 0)
  {
      print '<br>Finns inga auktioner ännu!<br>';
  }

  else
  {
      $result = mysql_query("SELECT * FROM auction where status='ny' ORDER BY id DESC LIMIT 3");

      for ($x = 0; $x < mysql_num_rows($result); $x++)
      {
          $row = mysql_fetch_array($result);

          print '<table align="center" width="270" border="0"><tr><td class="svart_ram">';

          print '<table border="0" width="220"><tr><td>'.$row['datum_borja'].'<br><b>'.$row['auktionnamn'].'&nbsp;</b></td>';
          //print '<td>Av: '.$row['skrivar_id'].'</td>';
          print '</tr></table><hr noshade="noshade">';
		  $sms = "För att lägga ett bud på denna auktion smsa ". $row['item'];
		  $sms .= " till 72550";
		  echo $sms;
		  echo "<br>";
		  $var .= "<img title=\"Produktnamn\"";
$var .= "src=\"img/products/". $row['bild']."\"";
$var .= " border=\"0\" />";
echo $var;
echo "<br>";
          $text = $row['info'];
		  echo $text;
		  echo "<br>";
          //print text_replace($text);

          print '</tr></td></table><br>';

      }
  }

?>
The problem is that at the first box it shows 1 picture. At the second box it shows two pictures. The picture in box one and the picture that should be displayed in box 2. And in box three there's 3 pictures being displayed. The picture in box one and the picture in box two. And the picture that should be displayed in box 3.
How would I solve that the correct picture shows at the correct box?
Thanks.

Posted: Sat Jul 22, 2006 2:47 pm
by John Cartwright
I read your problem about 5 times and could not understand what you meant.. do you have a live example I can look at or could you please explain as clear as possible the problem?

Posted: Sat Jul 22, 2006 3:01 pm
by NiGHTFiRE
http://wmegn.mine.nu/emil/auctions.php

Sorry that i've explained porly

Posted: Sat Jul 22, 2006 3:06 pm
by tecktalkcm0391
Try this: (untested)

Code: Select all

<?php 

  include("db.php"); 
  include("functions.php"); 

  $sql = "SELECT COUNT(id) FROM auction where status='ny'"; 
  $result = mysql_query($sql); 
  echo mysql_error(); 
  //$limit = 3; // Antal "nya" nyheter 

  $row = @mysql_fetch_array($result); 
  $numrows = mysql_result($result, 0); // antal i databasen 

  if (mysql_result ($result , 0) <= 0) 
  { 
      print '<br>Finns inga auktioner ännu!<br>'; 
  } 

  else 
  { 
      $result = mysql_query("SELECT * FROM auction where status='ny' ORDER BY id DESC LIMIT 3"); 

      for ($x = 0; $x < mysql_num_rows($result); $x++) 
      { 
          $row = mysql_fetch_assoc($result); // mysql_fetch_assoc instead of mysql_fetch_array

          print '<table align="center" width="270" border="0"><tr><td class="svart_ram">'; 

          print '<table border="0" width="220"><tr><td>'.$row['datum_borja'].'<br><b>'.$row['auktionnamn'].'&nbsp;</b></td>'; 
          //print '<td>Av: '.$row['skrivar_id'].'</td>'; 
          print '</tr></table><hr noshade="noshade">'; 
                  $sms = "För att lägga ett bud på denna auktion smsa ". $row['item']; 
                  $sms .= " till 72550"; 
                  echo $sms; 
                  echo "<br>"; 
                  $var .= "<img title=\"Produktnamn\""; 
$var .= "src=\"img/products/". $row['bild']."\""; 
$var .= " border=\"0\" />"; 
echo $var; 
echo "<br>"; 
          $text = $row['info']; 
                  echo $text; 
                  echo "<br>"; 
          //print text_replace($text); 

          print '</tr></td></table><br>'; 

      } 
  } 

?>

Posted: Sat Jul 22, 2006 3:11 pm
by NiGHTFiRE
I still get the same result though.

Posted: Sat Jul 22, 2006 3:20 pm
by tecktalkcm0391
This WILL work (even thought its untested... :lol: )

Code: Select all

<?php 

  include("db.php"); 
  include("functions.php"); 

  $sql = "SELECT COUNT(id) FROM auction where status='ny'"; 
  $result = mysql_query($sql); 
  echo mysql_error(); 
  //$limit = 3; // Antal "nya" nyheter 

  $row = @mysql_fetch_array($result); 
  $numrows = mysql_result($result, 0); // antal i databasen 

  if (mysql_result ($result , 0) <= 0) 
  { 
      print '<br>Finns inga auktioner ännu!<br>'; 
  } 

  else 
  { 
      $result = mysql_query("SELECT * FROM auction where status='ny' ORDER BY id DESC LIMIT 3"); 

      for ($x = 0; $x < mysql_num_rows($result); $x++) 
      { 
          $var = '';
          $row = mysql_fetch_assoc($result); // mysql_fetch_assoc instead of mysql_fetch_array 

          print '<table align="center" width="270" border="0"><tr><td class="svart_ram">'; 

          print '<table border="0" width="220"><tr><td>'.$row['datum_borja'].'<br><b>'.$row['auktionnamn'].'&nbsp;</b></td>'; 
          //print '<td>Av: '.$row['skrivar_id'].'</td>'; 
          print '</tr></table><hr noshade="noshade">'; 
                  $sms = "För att lägga ett bud på denna auktion smsa ". $row['item']; 
                  $sms .= " till 72550"; 
                  echo $sms; 
                  echo "<br>"; 
                  $var .= "<img title=\"Produktnamn\""; 
$var .= "src=\"img/products/". $row['bild']."\""; 
$var .= " border=\"0\" />"; 
echo $var; 
echo "<br>"; 
          $text = $row['info']; 
                  echo $text; 
                  echo "<br>"; 
          //print text_replace($text); 

          print '</tr></td></table><br>'; 

      } 
  } 

?>
You never cleared out the $var you just kept adding more and more HTML to it.

Posted: Sat Jul 22, 2006 3:21 pm
by RobertGonzalez
You need to clear $row. The var is somehow being added to itself rather than writing over it.

Posted: Sat Jul 22, 2006 3:22 pm
by tecktalkcm0391
Everah wrote:You need to clear $row. The var is somehow being added to itself rather than writing over it.
It think its $var more than $row

Posted: Sat Jul 22, 2006 3:33 pm
by RobertGonzalez
Try this...

Code: Select all

<?php 
include 'db.php';
include'functions.php';

if (!$result = mysql_query('SELECT * FROM auction where status=\'ny\' ORDER BY id DESC LIMIT 3'))
{
	die('Could not grab the data: ' . mysql_error());
}

if (mysql_num_rows($result))
{
	echo '<table align="center" width="270" border="0"><tr><td class="svart_ram">';
	while ($row = mysql_fetch_array($result))
	{
		echo '<table border="0" width="220"><tr><td>' . $row['datum_borja'] . '<br><b>' . $row['auktionnamn'] . '&nbsp;</b></td>';
		echo '</tr></table><hr noshade="noshade">'; 
		echo 'För att lägga ett bud på denna auktion smsa ' . $row['item'] . ' till 72550';
		echo '<br>';
		echo '<img title="Produktnamn" src="img/products/'. $row['bild']. '" border="0" />';
		echo '<br>';
		echo $row['info'];
		echo '<br>'; 
	}
	echo '</tr></td></table><br>';
}
else
{
	echo '<br>Finns inga auktioner ännu!<br>';
}
?>

Posted: Sat Jul 22, 2006 4:41 pm
by NiGHTFiRE
tecktalkcm0391 wrote:This WILL work (even thought its untested... :lol: )

Code: Select all

<?php 

  include("db.php"); 
  include("functions.php"); 

  $sql = "SELECT COUNT(id) FROM auction where status='ny'"; 
  $result = mysql_query($sql); 
  echo mysql_error(); 
  //$limit = 3; // Antal "nya" nyheter 

  $row = @mysql_fetch_array($result); 
  $numrows = mysql_result($result, 0); // antal i databasen 

  if (mysql_result ($result , 0) <= 0) 
  { 
      print '<br>Finns inga auktioner ännu!<br>'; 
  } 

  else 
  { 
      $result = mysql_query("SELECT * FROM auction where status='ny' ORDER BY id DESC LIMIT 3"); 

      for ($x = 0; $x < mysql_num_rows($result); $x++) 
      { 
          $var = '';
          $row = mysql_fetch_assoc($result); // mysql_fetch_assoc instead of mysql_fetch_array 

          print '<table align="center" width="270" border="0"><tr><td class="svart_ram">'; 

          print '<table border="0" width="220"><tr><td>'.$row['datum_borja'].'<br><b>'.$row['auktionnamn'].'&nbsp;</b></td>'; 
          //print '<td>Av: '.$row['skrivar_id'].'</td>'; 
          print '</tr></table><hr noshade="noshade">'; 
                  $sms = "För att lägga ett bud på denna auktion smsa ". $row['item']; 
                  $sms .= " till 72550"; 
                  echo $sms; 
                  echo "<br>"; 
                  $var .= "<img title="Produktnamn""; 
$var .= "src="img/products/". $row['bild']."""; 
$var .= " border="0" />"; 
echo $var; 
echo "<br>"; 
          $text = $row['info']; 
                  echo $text; 
                  echo "<br>"; 
          //print text_replace($text); 

          print '</tr></td></table><br>'; 

      } 
  } 

?>
You never cleared out the $var you just kept adding more and more HTML to it.
Thanks, works good now :)

Posted: Sat Jul 22, 2006 11:41 pm
by RobertGonzalez
Did you try the other code I posted. I want to know if it works.

Posted: Sun Jul 23, 2006 4:58 am
by NiGHTFiRE
No I haven't tryed yours.
And if I do I gotta change some stuff so the right id of the auction and everything works.

Posted: Sun Jul 23, 2006 11:19 am
by RobertGonzalez
You shouldn'y have to change it any more than you would have to change what you posted. I used all of your parameters and queries.

No biggie. If you decide to try it and it flies, let me know. Thanks.