Expekt bonuses - Debt Consolidation - Sportingbet - Find jobs - Valentine's Day Gifts

PDA

View Full Version : no output


promotingspace.net
Jul 16th 2007, 9:43 pm
Hi
I'm trying to list the articles in section 105 and use this link:
http://127.0.0.1/Takfekr/htdocs/section.php?id=105
with this code:
section.php:
<?php
include 'global.php';
if (isset($_GET['id'])) {
$section_id = $_GET['id'];
$sql = "SELECT * FROM articles WHERE section = '$section_id' ORDER BY id";
$results = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($results);
while($row = mysql_fetch_array( $results )) {
$title=$row['title'];
$text=$row['text'];
$username=$row['username'];
$name=$row['name'];
?>

<div class="article_header">

<h1 dir="rtl">
<?php echo "hello!"; echo $title ;?></h1>
<div class="asd1"> </div>
<div style="float: right;" dir="rtl">

<span dir="rtl">writer:
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<? echo $name; ?></a></span>

</div>
<br>
</div>
<br>
<!-- ARTICLE CONTENT START -->

<p class="MsoNormal" dir="rtl"><?php echo $text; ?> </p>
<br><p class="MsoNormal" dir="rtl">
<?php
}
?>
<o:p></o:p></p>
<!-- ARTICLE COMMENTS STOP -->
</div>

</div>
<?php
}
else header('Location: account.php');
?>
and section 105 is not empty. it has 1 record because when I use:
$query = "SELECT Count(*) FROM articles WHERE section='$section_id'";
$result = mysql_query($query) or die(mysql_error());
echo 'count: ', mysql_result($result, 0), "<br />\n";
It sends:
count: 1
what's the problem?
thanks in advance

NoamBarz
Jul 16th 2007, 10:52 pm
Use this:


while($row = mysql_fetch_array( $results )) {

$title=$row['title'];
$text=$row['text'];
$username=$row['username'];
$name=$row['name'];

echo "<div class=\"article_header\">";
echo "<h1 dir=\"rtl\">";
echo "hello! $title </h1>";
echo "<div class=\"asd1\"> </div>";
echo "<div style=\"float: right;\" dir=\"rtl\">";
echo "<span dir=\"rtl\">writer: ";
echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo "$name</a></span></div><br></div>";
echo "<br><p class=\"MsoNormal\" dir=\"rtl\"> $text </p><br>";
echo "<p class=\"MsoNormal\" dir=\"rtl\">";

}

this should work...

promotingspace.net
Jul 16th 2007, 11:45 pm
now this is the full code:
<?php
include 'global.php';
if (isset($_GET['id'])) {
$section_id = $_GET['id'];
$sql = "SELECT * FROM articles WHERE section = '$section_id' ORDER BY id";
$results = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($results);
while($row = mysql_fetch_array( $results )) {

$title=$row['title'];
$text=$row['text'];
$username=$row['username'];
$name=$row['name'];

echo "<div class=\"article_header\">";
echo "<h1 dir=\"rtl\">";
echo "hello! $title </h1>";
echo "<div class=\"asd1\"> </div>";
echo "<div style=\"float: right;\" dir=\"rtl\">";
echo "<span dir=\"rtl\">writer: ";
echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo "$name</a></span></div><br></div>";
echo "<br><p class=\"MsoNormal\" dir=\"rtl\"> $text </p><br>";
echo "<p class=\"MsoNormal\" dir=\"rtl\">";

}
$query = "SELECT Count(*) FROM articles WHERE section='$section_id'";
$result = mysql_query($query) or die(mysql_error());
echo 'count: ', mysql_result($result, 0), "<br />\n";

?>
<o:p></o:p></p>


<!-- ARTICLE COMMENTS STOP -->
</div>



<iframe name="ifrRate" frameborder="0" height="0" width="0"></iframe>

</div>
<?php

}


else header('Location: account.php');
?>
but the only output is:
count: 1

ecentricNick
Jul 17th 2007, 1:21 am
You have *two* fetches...

$row = mysql_fetch_array($results);
while($row = mysql_fetch_array( $results )) {

So, the first fetch gets your 1st record, and the second fetch probably fails, clearing out $row?

You don't need the first one

promotingspace.net
Jul 17th 2007, 1:32 am
yes that was the problem