Jump to content

Displaying the results


sabo86

Recommended Posts

I am trying to display my results, I tried this way:

echo "<p>Number of records found: ".$num_results."</p>";


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

$Model.="<td>$row['Model']</td>";
$Description.="<td>$row['Description']</td>";
$Category.="<td>$row['Category']</td>";
$Image.="<td>$row['Picture']</td>";
}
for ($i=0; $i <$num_results; $i++)
  {
  <table>
<tr><td>echo "<p><strong>.($i+1).".Model</td><?=$Model</tr> 
<tr><td>echo "<p><strong>.($i+1).".Description</td><?=$Description</tr> 
<tr><td>echo "<p><strong>.($i+1).".Category</td><?=$Category</tr> 
<tr><td>echo "<p><strong>.($i+1).".Picture</td><?=$Image</tr> 
}

 

but i got this error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 76

 

What's the problem?

Link to comment
Share on other sites

for ($i=0; $i <$num_results; $i++)
  { ?>
  <table>
<tr><td><?php echo "<p><strong>".($i+1)."Model"; ?></td><?=$Model?></tr> 
<tr><td><?php echo "<p><strong>".($i+1)."Description"; ?></td><?=$Description?></tr> 
<tr><td><?php echo "<p><strong>".($i+1)."Category"; ?></td><?=$Category?></tr> 
<tr><td><?php echo "<p><strong>".($i+1)."Picture"; ?></td><?=$Image?></tr> 
<?php } ?>

Link to comment
Share on other sites

echo "<p>Number of records found: ".$num_results."</p>";

while ($row = mysql_fetch_array($result))
{
   $Model       .= '<td>'.$row['Model'].'</td>';
   $Description .= '<td>'.$row['Description'].'</td>';
   $Category    .= '<td>'.$row['Category'].'</td>';
   $Image       .= '<td>'.$row['Picture'].'</td>';
}

for ($i=0; $i <$num_results; $i++)
{
?>  <table>
<tr><td><?php echo "<p><strong>".($i+1)."Model"; ?></td><?=$Model?></tr>
<tr><td><?php echo "<p><strong>".($i+1)."Description"; ?></td><?=$Description?></tr>
<tr><td><?php echo "<p><strong>".($i+1)."Category"; ?></td><?=$Category?></tr>
<tr><td><?php echo "<p><strong>".($i+1)."Picture"; ?></td><?=$Image?></tr>
<?php } ?>

Link to comment
Share on other sites

OK I tried this one, the results are as following:

 

Notice: Undefined variable: field in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 54

 

Number of records found: 4

 

Notice: Undefined variable: Model in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 77

 

Notice: Undefined variable: Description in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 78

 

Notice: Undefined variable: Category in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 79

 

Notice: Undefined variable: Image in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 80

 

1Model

 

1Description

 

1Category

 

1Picture

 

2Model

 

2Description

 

2Category

 

2Picture

 

3Model

 

3Description

 

3Category

 

3Picture

 

4Model

 

4Description

 

4Category

 

4Picture

Link to comment
Share on other sites

ok i got

Fleifel

 

Notice: Undefined variable: field in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 54

 

Number of records found: 4

 

1Model

 

1Description

 

1Category

 

1Picture

 

2Model

 

2Description

 

2Category

 

2Picture

 

3Model

 

3Description

 

3Category

 

3Picture

 

4Model

 

4Description

 

4Category

 

4Picture

 

But I am not getting the results from the database.. just the atribute names...

Link to comment
Share on other sites

Now my code is:

    $Model       .= '<td>'.$row['Model'].'</td>';
    $Description .= '<td>'.$row['Description'].'</td>';
    $Category    .= '<td>'.$row['Category'].'</td>';
    $Image       .= '<td>'.$row['Picture'].'</td>';
}
for ($i=0; $i <$num_results; $i++)
{
?>  <table>
<tr><td><?php echo "<br><p><strong>".($i+1).". Model:"; ?></td><?=$Model?></tr>
<tr><td><?php echo "<strong> Description:"; ?></td><?=$Description?></tr>
<tr><td><?php echo "<strong> Category:"; ?></td><?=$Category?></tr>
<tr><td><?php echo "<strong> Picture:"; ?></td><?=$Image?></tr>
<?php } 

 

and results are like:

 

Number of records found: 4

 

1. Model:

Description:

Category:

Picture:

 

2. Model:

Description:

Category:

Picture:

 

3. Model:

Description:

Category:

Picture:

 

4. Model:

Description:

Category:

Picture:

 

How can I get the records in these attributes?

Link to comment
Share on other sites

The code you've posted will not display what you think it will. Try something like this:

<?php
echo "<p>Number of records found: ".$num_results."</p>";
$i = 1;
echo "<table>\n";
while ($row = mysql_fetch_assoc($result))
{
    echo '<tr><td style="font-weight:bold">' . $i . ' Model</td><td>' . $row['Model'] . '</td></tr>';
    echo '<tr><td style="font-weight:bold">' . $i . ' Description</td><td>' . $row['Description'] . '</td></tr>';
    echo '<tr><td style="font-weight:bold">' . $i . ' Category</td><td>' . $row['Category'] . '</td></tr>';
    echo '<tr><td style="font-weight:bold">' . $i . ' Picture</td><td>' . $row['Picture'] . '</td></tr>';
    $i++;
}
echo '</table>';
?>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.