PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
NiGHTFiRE
Forum Contributor
Posts: 156 Joined: Sun May 14, 2006 10:36 am
Location: Sweden
Post
by NiGHTFiRE » Sat Jul 22, 2006 1:26 pm
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'].' </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.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sat Jul 22, 2006 2:47 pm
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?
NiGHTFiRE
Forum Contributor
Posts: 156 Joined: Sun May 14, 2006 10:36 am
Location: Sweden
Post
by NiGHTFiRE » Sat Jul 22, 2006 3:01 pm
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Sat Jul 22, 2006 3:06 pm
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'].' </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>';
}
}
?>
NiGHTFiRE
Forum Contributor
Posts: 156 Joined: Sun May 14, 2006 10:36 am
Location: Sweden
Post
by NiGHTFiRE » Sat Jul 22, 2006 3:11 pm
I still get the same result though.
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Sat Jul 22, 2006 3:20 pm
This WILL work (even thought its 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++)
{
$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'].' </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.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sat Jul 22, 2006 3:21 pm
You need to clear $row. The var is somehow being added to itself rather than writing over it.
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Sat Jul 22, 2006 3:22 pm
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
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sat Jul 22, 2006 3:33 pm
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'] . ' </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>';
}
?>
NiGHTFiRE
Forum Contributor
Posts: 156 Joined: Sun May 14, 2006 10:36 am
Location: Sweden
Post
by NiGHTFiRE » Sat Jul 22, 2006 4:41 pm
tecktalkcm0391 wrote: This WILL work (even thought its 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++)
{
$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'].' </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
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sat Jul 22, 2006 11:41 pm
Did you try the other code I posted. I want to know if it works.
NiGHTFiRE
Forum Contributor
Posts: 156 Joined: Sun May 14, 2006 10:36 am
Location: Sweden
Post
by NiGHTFiRE » Sun Jul 23, 2006 4:58 am
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.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sun Jul 23, 2006 11:19 am
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.